diff --git a/README.md b/README.md index 4f317ef..c0f1fdb 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Alternatively: *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. - 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/bypass/bypass-ublock-origin.js b/bypass/bypass-ublock-origin.js new file mode 100644 index 0000000..3d3bebf --- /dev/null +++ b/bypass/bypass-ublock-origin.js @@ -0,0 +1,21 @@ +twitch-videoad.js application/javascript +(function() { + if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; } + 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'; + } + } + } + return realFetch.apply(this, arguments); + } + } + hookFetch(); +})(); \ No newline at end of file diff --git a/bypass/bypass.user.js b/bypass/bypass.user.js new file mode 100644 index 0000000..955053b --- /dev/null +++ b/bypass/bypass.user.js @@ -0,0 +1,32 @@ +// ==UserScript== +// @name TwitchAdSolutions (bypass) +// @namespace https://github.com/pixeltris/TwitchAdSolutions +// @version 1.0 +// @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) +// @author pixeltris +// @match *://*.twitch.tv/* +// @run-at document-start +// @grant none +// ==/UserScript== +(function() { + 'use strict'; + 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'; + } + } + } + return realFetch.apply(this, arguments); + } + } + hookFetch(); +})();