1
0
mirror of https://github.com/pixeltris/TwitchAdSolutions.git synced 2024-11-23 19:03:03 +01:00

Fix Worker conflict detection #294

This commit is contained in:
pixeltris 2024-11-03 17:55:59 +00:00
parent 13f80faf3d
commit 722f5b9624
4 changed files with 66 additions and 14 deletions

View File

@ -26,6 +26,19 @@ twitch-videoad.js text/javascript
var OriginalVideoPlayerQuality = null;
var IsPlayerAutoQuality = null;
const oldWorker = window.Worker;
function isWorkerDoubleHooked(ourWorker, identifier) {
var ourWorkerString = ourWorker ? ourWorker.toString() : null;
var proto = window.Worker;
while (proto)
{
var workerString = proto.toString();
if (workerString.includes(identifier) && workerString !== ourWorkerString) {
return true;
}
proto = Object.getPrototypeOf(proto);
}
return false;
}
function hookWindowWorker() {
var newWorker = window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl, options) {
@ -33,7 +46,7 @@ twitch-videoad.js text/javascript
try {
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
} catch {}
if (newWorker.toString() !== window.Worker.toString()) {
if (isWorkerDoubleHooked(newWorker, 'twitch')) {
console.log('Multiple twitch adblockers installed. Skipping Worker hook (vaft)');
isTwitchWorker = false;
}
@ -862,8 +875,8 @@ twitch-videoad.js text/javascript
}
}catch{}
}
if (window.Worker.toString().includes('twitch')) {
console.log('Twitch Worker is already hooked');
if (isWorkerDoubleHooked(null, 'twitch')) {
console.log('Twitch Worker is already hooked. Skipping (vaft)');
} else {
window.reloadTwitchPlayer = reloadTwitchPlayer;
declareOptions(window);

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (vaft)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 13.0.0
// @version 14.0.0
// @description Multiple solutions for blocking Twitch ads (vaft)
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js
@ -38,6 +38,19 @@
var OriginalVideoPlayerQuality = null;
var IsPlayerAutoQuality = null;
const oldWorker = window.Worker;
function isWorkerDoubleHooked(ourWorker, identifier) {
var ourWorkerString = ourWorker ? ourWorker.toString() : null;
var proto = window.Worker;
while (proto)
{
var workerString = proto.toString();
if (workerString.includes(identifier) && workerString !== ourWorkerString) {
return true;
}
proto = Object.getPrototypeOf(proto);
}
return false;
}
function hookWindowWorker() {
var newWorker = window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl, options) {
@ -45,7 +58,7 @@
try {
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
} catch {}
if (newWorker.toString() !== window.Worker.toString()) {
if (isWorkerDoubleHooked(newWorker, 'twitch')) {
console.log('Multiple twitch adblockers installed. Skipping Worker hook (vaft)');
isTwitchWorker = false;
}
@ -874,8 +887,8 @@
}
}catch{}
}
if (window.Worker.toString().includes('twitch')) {
console.log('Twitch Worker is already hooked');
if (isWorkerDoubleHooked(null, 'twitch')) {
console.log('Twitch Worker is already hooked. Skipping (vaft)');
} else {
window.reloadTwitchPlayer = reloadTwitchPlayer;
declareOptions(window);

View File

@ -25,6 +25,19 @@ twitch-videoad.js text/javascript
}
var twitchWorkers = [];
const oldWorker = window.Worker;
function isWorkerDoubleHooked(ourWorker, identifier) {
var ourWorkerString = ourWorker ? ourWorker.toString() : null;
var proto = window.Worker;
while (proto)
{
var workerString = proto.toString();
if (workerString.includes(identifier) && workerString !== ourWorkerString) {
return true;
}
proto = Object.getPrototypeOf(proto);
}
return false;
}
function hookWindowWorker() {
var newWorker = window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl, options) {
@ -32,7 +45,7 @@ twitch-videoad.js text/javascript
try {
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
} catch {}
if (newWorker.toString() !== window.Worker.toString()) {
if (isWorkerDoubleHooked(newWorker, 'twitch')) {
console.log('Multiple twitch adblockers installed. Skipping Worker hook (video-swap-new)');
isTwitchWorker = false;
}
@ -653,8 +666,8 @@ twitch-videoad.js text/javascript
return realGetItem.apply(this, arguments);
};
}
if (window.Worker.toString().includes('twitch')) {
console.log('Twitch Worker is already hooked');
if (isWorkerDoubleHooked(null, 'twitch')) {
console.log('Twitch Worker is already hooked. Skipping (video-swap-new)');
} else {
window.reloadTwitchPlayer = reloadTwitchPlayer;
declareOptions(window);

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (video-swap-new)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.31
// @version 1.32
// @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)
@ -37,6 +37,19 @@
}
var twitchWorkers = [];
const oldWorker = window.Worker;
function isWorkerDoubleHooked(ourWorker, identifier) {
var ourWorkerString = ourWorker ? ourWorker.toString() : null;
var proto = window.Worker;
while (proto)
{
var workerString = proto.toString();
if (workerString.includes(identifier) && workerString !== ourWorkerString) {
return true;
}
proto = Object.getPrototypeOf(proto);
}
return false;
}
function hookWindowWorker() {
var newWorker = window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl, options) {
@ -44,7 +57,7 @@
try {
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
} catch {}
if (newWorker.toString() !== window.Worker.toString()) {
if (isWorkerDoubleHooked(newWorker, 'twitch')) {
console.log('Multiple twitch adblockers installed. Skipping Worker hook (video-swap-new)');
isTwitchWorker = false;
}
@ -665,8 +678,8 @@
return realGetItem.apply(this, arguments);
};
}
if (window.Worker.toString().includes('twitch')) {
console.log('Twitch Worker is already hooked');
if (isWorkerDoubleHooked(null, 'twitch')) {
console.log('Twitch Worker is already hooked. Skipping (video-swap-new)');
} else {
window.reloadTwitchPlayer = reloadTwitchPlayer;
declareOptions(window);