diff --git a/README.md b/README.md index c0f1fdb..9580a34 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This repo aims to provide multiple solutions for blocking Twitch ads. +**Don't combine Twitch specific ad blockers.** + ## Recommendations Proxies are the most reliable way of avoiding ads ([buffering / downtime info](full-list.md#proxy-issues)). @@ -22,10 +24,9 @@ Alternatively: **There are better / easier to use methods in the above** `Recommendations`. -*Don't combine these scripts with other Twitch specific ad blockers.* - - bypass ([ublock](https://github.com/pixeltris/TwitchAdSolutions/raw/master/bypass/bypass-ublock-origin.js) / [userscript](https://github.com/pixeltris/TwitchAdSolutions/raw/master/bypass/bypass.user.js)) - No ads. + - *Enabled by default on uBlock Origin 1.38.4*. - notify-strip ([ublock](https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip-ublock-origin.js) / [userscript](https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js)) - Ad segments are replaced by low resolution stream segments. - Notifies Twitch that ads were "watched" (reduces preroll ad frequency). diff --git a/base/base.user.js b/base/base.user.js index 0f5cb74..97a009c 100644 --- a/base/base.user.js +++ b/base/base.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions -// @version 1.11 +// @version 1.12 // @description Multiple solutions for blocking Twitch ads // @author pixeltris // @match *://*.twitch.tv/* @@ -492,14 +492,7 @@ var realFetch = window.fetch; window.fetch = function(url, init, ...args) { if (typeof url === 'string') { - if (url.includes('/access_token') || url.includes('gql')) { - if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { - if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { - const newBody = JSON.parse(init.body); - newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; - init.body = JSON.stringify(newBody); - } - } + if (url.includes('gql')) { var deviceId = init.headers['X-Device-Id']; if (typeof deviceId !== 'string') { deviceId = init.headers['Device-ID']; @@ -513,12 +506,19 @@ value: gql_device_id }); } - if (OPT_ROLLING_DEVICE_ID) { - if (typeof init.headers['X-Device-Id'] === 'string') { - init.headers['X-Device-Id'] = gql_device_id_rolling; + if (typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { + if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { + const newBody = JSON.parse(init.body); + newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; + init.body = JSON.stringify(newBody); } - if (typeof init.headers['Device-ID'] === 'string') { - init.headers['Device-ID'] = gql_device_id_rolling; + if (OPT_ROLLING_DEVICE_ID) { + if (typeof init.headers['X-Device-Id'] === 'string') { + init.headers['X-Device-Id'] = gql_device_id_rolling; + } + if (typeof init.headers['Device-ID'] === 'string') { + init.headers['Device-ID'] = gql_device_id_rolling; + } } } } diff --git a/bypass/bypass-ublock-origin.js b/bypass/bypass-ublock-origin.js index 3d3bebf..b3b48ad 100644 --- a/bypass/bypass-ublock-origin.js +++ b/bypass/bypass-ublock-origin.js @@ -4,14 +4,12 @@ twitch-videoad.js application/javascript function hookFetch() { var realFetch = window.fetch; window.fetch = function(url, init, ...args) { - if (typeof url === 'string') { - if (url.includes('gql')) { - if (typeof init.headers['X-Device-Id'] === 'string') { - init.headers['X-Device-Id'] = 'twitch-web-wall-mason'; - } - if (typeof init.headers['Device-ID'] === 'string') { - init.headers['Device-ID'] = 'twitch-web-wall-mason'; - } + if (typeof url === 'string' && url.includes('gql') && typeof init.body == 'string' && init.body.includes('PlaybackAccessToken')) { + if (typeof init.headers['X-Device-Id'] === 'string') { + init.headers['X-Device-Id'] = 'twitch-web-wall-mason'; + } + if (typeof init.headers['Device-ID'] === 'string') { + init.headers['Device-ID'] = 'twitch-web-wall-mason'; } } return realFetch.apply(this, arguments); diff --git a/bypass/bypass.user.js b/bypass/bypass.user.js index 955053b..067f686 100644 --- a/bypass/bypass.user.js +++ b/bypass/bypass.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TwitchAdSolutions (bypass) // @namespace https://github.com/pixeltris/TwitchAdSolutions -// @version 1.0 +// @version 1.1 // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/bypass/bypass.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/bypass/bypass.user.js // @description Multiple solutions for blocking Twitch ads (bypass) @@ -15,14 +15,12 @@ function hookFetch() { var realFetch = window.fetch; window.fetch = function(url, init, ...args) { - if (typeof url === 'string') { - if (url.includes('gql')) { - if (typeof init.headers['X-Device-Id'] === 'string') { - init.headers['X-Device-Id'] = 'twitch-web-wall-mason'; - } - if (typeof init.headers['Device-ID'] === 'string') { - init.headers['Device-ID'] = 'twitch-web-wall-mason'; - } + if (typeof url === 'string' && url.includes('gql') && typeof init.body == 'string' && init.body.includes('PlaybackAccessToken')) { + if (typeof init.headers['X-Device-Id'] === 'string') { + init.headers['X-Device-Id'] = 'twitch-web-wall-mason'; + } + if (typeof init.headers['Device-ID'] === 'string') { + init.headers['Device-ID'] = 'twitch-web-wall-mason'; } } return realFetch.apply(this, arguments); diff --git a/notify-reload/notify-reload-ublock-origin.js b/notify-reload/notify-reload-ublock-origin.js index a487ee5..a47fb98 100644 --- a/notify-reload/notify-reload-ublock-origin.js +++ b/notify-reload/notify-reload-ublock-origin.js @@ -483,14 +483,7 @@ twitch-videoad.js application/javascript var realFetch = window.fetch; window.fetch = function(url, init, ...args) { if (typeof url === 'string') { - if (url.includes('/access_token') || url.includes('gql')) { - if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { - if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { - const newBody = JSON.parse(init.body); - newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; - init.body = JSON.stringify(newBody); - } - } + if (url.includes('gql')) { var deviceId = init.headers['X-Device-Id']; if (typeof deviceId !== 'string') { deviceId = init.headers['Device-ID']; @@ -504,12 +497,19 @@ twitch-videoad.js application/javascript value: gql_device_id }); } - if (OPT_ROLLING_DEVICE_ID) { - if (typeof init.headers['X-Device-Id'] === 'string') { - init.headers['X-Device-Id'] = gql_device_id_rolling; + if (typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { + if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { + const newBody = JSON.parse(init.body); + newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; + init.body = JSON.stringify(newBody); } - if (typeof init.headers['Device-ID'] === 'string') { - init.headers['Device-ID'] = gql_device_id_rolling; + if (OPT_ROLLING_DEVICE_ID) { + if (typeof init.headers['X-Device-Id'] === 'string') { + init.headers['X-Device-Id'] = gql_device_id_rolling; + } + if (typeof init.headers['Device-ID'] === 'string') { + init.headers['Device-ID'] = gql_device_id_rolling; + } } } } diff --git a/notify-reload/notify-reload.user.js b/notify-reload/notify-reload.user.js index 705fea1..e4c69e7 100644 --- a/notify-reload/notify-reload.user.js +++ b/notify-reload/notify-reload.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TwitchAdSolutions (notify-reload) // @namespace https://github.com/pixeltris/TwitchAdSolutions -// @version 1.11 +// @version 1.12 // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js // @description Multiple solutions for blocking Twitch ads (notify-reload) @@ -494,14 +494,7 @@ var realFetch = window.fetch; window.fetch = function(url, init, ...args) { if (typeof url === 'string') { - if (url.includes('/access_token') || url.includes('gql')) { - if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { - if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { - const newBody = JSON.parse(init.body); - newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; - init.body = JSON.stringify(newBody); - } - } + if (url.includes('gql')) { var deviceId = init.headers['X-Device-Id']; if (typeof deviceId !== 'string') { deviceId = init.headers['Device-ID']; @@ -515,12 +508,19 @@ value: gql_device_id }); } - if (OPT_ROLLING_DEVICE_ID) { - if (typeof init.headers['X-Device-Id'] === 'string') { - init.headers['X-Device-Id'] = gql_device_id_rolling; + if (typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { + if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { + const newBody = JSON.parse(init.body); + newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; + init.body = JSON.stringify(newBody); } - if (typeof init.headers['Device-ID'] === 'string') { - init.headers['Device-ID'] = gql_device_id_rolling; + if (OPT_ROLLING_DEVICE_ID) { + if (typeof init.headers['X-Device-Id'] === 'string') { + init.headers['X-Device-Id'] = gql_device_id_rolling; + } + if (typeof init.headers['Device-ID'] === 'string') { + init.headers['Device-ID'] = gql_device_id_rolling; + } } } } diff --git a/notify-strip/notify-strip-ublock-origin.js b/notify-strip/notify-strip-ublock-origin.js index 20dabd2..d2f4c48 100644 --- a/notify-strip/notify-strip-ublock-origin.js +++ b/notify-strip/notify-strip-ublock-origin.js @@ -483,14 +483,7 @@ twitch-videoad.js application/javascript var realFetch = window.fetch; window.fetch = function(url, init, ...args) { if (typeof url === 'string') { - if (url.includes('/access_token') || url.includes('gql')) { - if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { - if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { - const newBody = JSON.parse(init.body); - newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; - init.body = JSON.stringify(newBody); - } - } + if (url.includes('gql')) { var deviceId = init.headers['X-Device-Id']; if (typeof deviceId !== 'string') { deviceId = init.headers['Device-ID']; @@ -504,12 +497,19 @@ twitch-videoad.js application/javascript value: gql_device_id }); } - if (OPT_ROLLING_DEVICE_ID) { - if (typeof init.headers['X-Device-Id'] === 'string') { - init.headers['X-Device-Id'] = gql_device_id_rolling; + if (typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { + if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { + const newBody = JSON.parse(init.body); + newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; + init.body = JSON.stringify(newBody); } - if (typeof init.headers['Device-ID'] === 'string') { - init.headers['Device-ID'] = gql_device_id_rolling; + if (OPT_ROLLING_DEVICE_ID) { + if (typeof init.headers['X-Device-Id'] === 'string') { + init.headers['X-Device-Id'] = gql_device_id_rolling; + } + if (typeof init.headers['Device-ID'] === 'string') { + init.headers['Device-ID'] = gql_device_id_rolling; + } } } } diff --git a/notify-strip/notify-strip.user.js b/notify-strip/notify-strip.user.js index 25fe545..5a98cdc 100644 --- a/notify-strip/notify-strip.user.js +++ b/notify-strip/notify-strip.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TwitchAdSolutions (notify-strip) // @namespace https://github.com/pixeltris/TwitchAdSolutions -// @version 1.11 +// @version 1.12 // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js // @description Multiple solutions for blocking Twitch ads (notify-strip) @@ -494,14 +494,7 @@ var realFetch = window.fetch; window.fetch = function(url, init, ...args) { if (typeof url === 'string') { - if (url.includes('/access_token') || url.includes('gql')) { - if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { - if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { - const newBody = JSON.parse(init.body); - newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; - init.body = JSON.stringify(newBody); - } - } + if (url.includes('gql')) { var deviceId = init.headers['X-Device-Id']; if (typeof deviceId !== 'string') { deviceId = init.headers['Device-ID']; @@ -515,12 +508,19 @@ value: gql_device_id }); } - if (OPT_ROLLING_DEVICE_ID) { - if (typeof init.headers['X-Device-Id'] === 'string') { - init.headers['X-Device-Id'] = gql_device_id_rolling; + if (typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) { + if (OPT_ACCESS_TOKEN_PLAYER_TYPE) { + const newBody = JSON.parse(init.body); + newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE; + init.body = JSON.stringify(newBody); } - if (typeof init.headers['Device-ID'] === 'string') { - init.headers['Device-ID'] = gql_device_id_rolling; + if (OPT_ROLLING_DEVICE_ID) { + if (typeof init.headers['X-Device-Id'] === 'string') { + init.headers['X-Device-Id'] = gql_device_id_rolling; + } + if (typeof init.headers['Device-ID'] === 'string') { + init.headers['Device-ID'] = gql_device_id_rolling; + } } } }