Update twitch-videoad scriptlet

Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/5184#issuecomment-938379331

Solution contributed by <https://github.com/pixeltris>:
- 6be4c53130
This commit is contained in:
Raymond Hill 2021-10-08 07:12:58 -04:00
parent c4b7ee80ea
commit 0d3a1932e9
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 21 additions and 9 deletions

View File

@ -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';
}
return realFetch.apply(this, arguments);
};
if ( typeof headers['Device-ID'] === 'string' ) {
headers['Device-ID'] = 'twitch-web-wall-mason';
}
}
return Reflect.apply(target, thisArg, args);
}
});
})();