From 0d3a1932e998c0cb3f4c5ff1d9a3fe62e12a3cf4 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 8 Oct 2021 07:12:58 -0400 Subject: [PATCH] Update twitch-videoad scriptlet Related issue: - https://github.com/uBlockOrigin/uAssets/issues/5184#issuecomment-938379331 Solution contributed by : - https://github.com/pixeltris/TwitchAdSolutions/commit/6be4c5313035c8e9354ce9fd19424c4bb3063fe0 --- assets/resources/scriptlets.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 5604ae4a0..903b26499 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -1559,19 +1559,31 @@ })(); -// https://github.com/uBlockOrigin/uAssets/issues/5184 /// twitch-videoad.js +// https://github.com/uBlockOrigin/uAssets/issues/5184 +// https://github.com/pixeltris/TwitchAdSolutions/commit/6be4c5313035 (function() { if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; } - var realFetch = window.fetch; - window.fetch = function(input) { - if ( arguments.length >= 2 && typeof input === 'string' && input.includes('/access_token') ) { - var url = new URL(arguments[0]); - url.searchParams.delete('platform'); - arguments[0] = url.href; + window.fetch = new Proxy(window.fetch, { + apply: function(target, thisArg, args) { + const [ url, init ] = args; + if ( + typeof url === 'string' && + url.includes('gql') && + init instanceof Object && + init.headers instanceof Object + ) { + const { headers } = init; + if ( typeof headers['X-Device-Id'] === 'string' ) { + headers['X-Device-Id'] = 'twitch-web-wall-mason'; + } + if ( typeof headers['Device-ID'] === 'string' ) { + headers['Device-ID'] = 'twitch-web-wall-mason'; + } + } + return Reflect.apply(target, thisArg, args); } - return realFetch.apply(this, arguments); - }; + }); })();