Skip to content

Commit

Permalink
Update twitch-videoad scriptlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Oct 8, 2021
1 parent c4b7ee8 commit 0d3a193
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
});
})();


Expand Down

0 comments on commit 0d3a193

Please sign in to comment.