Fix worker hook #236

- Inject into every worker
- Remove unused proxy code from vaft
- Add additional source stream request to vaft
- Make log inside hookWorkerFetch consistent between vaft/video-swap-new
This commit is contained in:
pixeltris
2024-04-12 12:46:45 +01:00
parent 726254a5cb
commit 044d1fb3bb
4 changed files with 84 additions and 204 deletions
+14 -22
View File
@@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (video-swap-new)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.23
// @version 1.24
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js
// @description Multiple solutions for blocking Twitch ads (video-swap-new)
@@ -46,14 +46,10 @@
scope.AuthorizationHeader = null;
}
declareOptions(window);
var twitchMainWorker = null;
var twitchWorkers = [];
const oldWorker = window.Worker;
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl) {
if (twitchMainWorker) {
super(twitchBlobUrl);
return;
}
var jsURL = getWasmWorkerUrl(twitchBlobUrl);
if (typeof jsURL !== 'string') {
super(twitchBlobUrl);
@@ -83,7 +79,7 @@
importScripts('${jsURL}');
`
super(URL.createObjectURL(new Blob([newBlobStr])));
twitchMainWorker = this;
twitchWorkers.push(this);
this.onmessage = function(e) {
// NOTE: Removed adDiv caching as '.video-player' can change between streams?
if (e.data.key == 'UboShowAdBanner') {
@@ -455,6 +451,11 @@
return 0;
}
}
function postTwitchWorkerMessage(key, value) {
twitchWorkers.forEach((worker) => {
worker.postMessage({key: key, value: value});
});
}
function hookFetch() {
var realFetch = window.fetch;
window.fetch = function(url, init, ...args) {
@@ -467,11 +468,8 @@
if (typeof deviceId === 'string') {
gql_device_id = deviceId;
}
if (gql_device_id && twitchMainWorker) {
twitchMainWorker.postMessage({
key: 'UboUpdateDeviceId',
value: gql_device_id
});
if (gql_device_id) {
postTwitchWorkerMessage('UboUpdateDeviceId', gql_device_id);
}
if (typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) {
if (OPT_ACCESS_TOKEN_PLAYER_TYPE) {
@@ -495,20 +493,14 @@
}
if (typeof init.headers['Client-Integrity'] === 'string') {
ClientIntegrityHeader = init.headers['Client-Integrity'];
if (ClientIntegrityHeader && twitchMainWorker) {
twitchMainWorker.postMessage({
key: 'UpdateClientIntegrityHeader',
value: init.headers['Client-Integrity']
});
if (ClientIntegrityHeader) {
postTwitchWorkerMessage('UpdateClientIntegrityHeader', init.headers['Client-Integrity']);
}
}
if (typeof init.headers['Authorization'] === 'string') {
AuthorizationHeader = init.headers['Authorization'];
if (AuthorizationHeader && twitchMainWorker) {
twitchMainWorker.postMessage({
key: 'UpdateAuthorizationHeader',
value: init.headers['Authorization']
});
if (AuthorizationHeader) {
postTwitchWorkerMessage('UpdateAuthorizationHeader', init.headers['Authorization']);
}
}
}