1
0
mirror of https://github.com/pixeltris/TwitchAdSolutions.git synced 2024-11-22 10:22:51 +01:00

Add Worker check from AdGuard Extra #276

This commit is contained in:
pixeltris 2024-08-20 19:13:31 +01:00
parent 39666c7bb1
commit 144bc99a61
4 changed files with 652 additions and 560 deletions

View File

@ -1,48 +1,6 @@
twitch-videoad.js text/javascript
(function() {
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
//This stops Twitch from pausing the player when in another tab and an ad shows.
try {
Object.defineProperty(document, 'visibilityState', {
get() {
return 'visible';
}
});
Object.defineProperty(document, 'hidden', {
get() {
return false;
}
});
const block = e => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
};
const process = e => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
//This corrects the background tab buffer bug when switching to the background tab for the first time after an extended period.
doTwitchPlayerTask(false, false, true, false, false);
};
document.addEventListener('visibilitychange', block, true);
document.addEventListener('webkitvisibilitychange', block, true);
document.addEventListener('mozvisibilitychange', block, true);
document.addEventListener('hasFocus', block, true);
if (/Firefox/.test(navigator.userAgent)) {
Object.defineProperty(document, 'mozHidden', {
get() {
return false;
}
});
} else {
Object.defineProperty(document, 'webkitHidden', {
get() {
return false;
}
});
}
} catch (err) {}
function declareOptions(scope) {
scope.AdSignifier = 'stitched';
scope.ClientID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
@ -63,12 +21,12 @@ twitch-videoad.js text/javascript
scope.ClientIntegrityHeader = null;
scope.AuthorizationHeader = null;
}
declareOptions(window);
var twitchWorkers = [];
var adBlockDiv = null;
var OriginalVideoPlayerQuality = null;
var IsPlayerAutoQuality = null;
const oldWorker = window.Worker;
function hookWindowWorker() {
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl, options) {
var isTwitchWorker = false;
@ -243,6 +201,7 @@ twitch-videoad.js text/javascript
}
}
};
}
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
@ -853,5 +812,73 @@ twitch-videoad.js text/javascript
return realFetch.apply(this, arguments);
};
}
function isWorkerIntact() {
// Taken from Adguard Extra
const iframe = window.document.createElement('iframe');
window.document.body.append(iframe);
const cleanWindow = iframe.contentWindow;
if (cleanWindow.Worker.toString() === window.Worker.toString()) {
iframe.remove();
return true;
}
iframe.remove();
return false;
}
function onContentLoaded() {
if (!isWorkerIntact()) {
console.log('Twitch Worker is already hooked');
return;
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
declareOptions(window);
hookWindowWorker();
hookFetch();
// This stops Twitch from pausing the player when in another tab and an ad shows.
// Taken from https://github.com/saucettv/VideoAdBlockForTwitch/blob/cefce9d2b565769c77e3666ac8234c3acfe20d83/chrome/content.js#L30
try {
Object.defineProperty(document, 'visibilityState', {
get() {
return 'visible';
}
});
}catch{}
try {
Object.defineProperty(document, 'hidden', {
get() {
return false;
}
});
}catch{}
var block = e => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
};
document.addEventListener('visibilitychange', block, true);
document.addEventListener('webkitvisibilitychange', block, true);
document.addEventListener('mozvisibilitychange', block, true);
document.addEventListener('hasFocus', block, true);
try {
if (/Firefox/.test(navigator.userAgent)) {
Object.defineProperty(document, 'mozHidden', {
get() {
return false;
}
});
} else {
Object.defineProperty(document, 'webkitHidden', {
get() {
return false;
}
});
}
}catch{}
}
if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") {
onContentLoaded();
} else {
window.addEventListener("DOMContentLoaded", function() {
onContentLoaded();
});
}
})();

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (vaft)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 10.0.0
// @version 11.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
@ -13,48 +13,6 @@
// ==/UserScript==
(function() {
'use strict';
//This stops Twitch from pausing the player when in another tab and an ad shows.
try {
Object.defineProperty(document, 'visibilityState', {
get() {
return 'visible';
}
});
Object.defineProperty(document, 'hidden', {
get() {
return false;
}
});
const block = e => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
};
const process = e => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
//This corrects the background tab buffer bug when switching to the background tab for the first time after an extended period.
doTwitchPlayerTask(false, false, true, false, false);
};
document.addEventListener('visibilitychange', block, true);
document.addEventListener('webkitvisibilitychange', block, true);
document.addEventListener('mozvisibilitychange', block, true);
document.addEventListener('hasFocus', block, true);
if (/Firefox/.test(navigator.userAgent)) {
Object.defineProperty(document, 'mozHidden', {
get() {
return false;
}
});
} else {
Object.defineProperty(document, 'webkitHidden', {
get() {
return false;
}
});
}
} catch (err) {}
function declareOptions(scope) {
scope.AdSignifier = 'stitched';
scope.ClientID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
@ -75,12 +33,12 @@
scope.ClientIntegrityHeader = null;
scope.AuthorizationHeader = null;
}
declareOptions(window);
var twitchWorkers = [];
var adBlockDiv = null;
var OriginalVideoPlayerQuality = null;
var IsPlayerAutoQuality = null;
const oldWorker = window.Worker;
function hookWindowWorker() {
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl, options) {
var isTwitchWorker = false;
@ -255,6 +213,7 @@
}
}
};
}
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
@ -865,5 +824,73 @@
return realFetch.apply(this, arguments);
};
}
function isWorkerIntact() {
// Taken from Adguard Extra
const iframe = window.document.createElement('iframe');
window.document.body.append(iframe);
const cleanWindow = iframe.contentWindow;
if (cleanWindow.Worker.toString() === window.Worker.toString()) {
iframe.remove();
return true;
}
iframe.remove();
return false;
}
function onContentLoaded() {
if (!isWorkerIntact()) {
console.log('Twitch Worker is already hooked');
return;
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
declareOptions(window);
hookWindowWorker();
hookFetch();
// This stops Twitch from pausing the player when in another tab and an ad shows.
// Taken from https://github.com/saucettv/VideoAdBlockForTwitch/blob/cefce9d2b565769c77e3666ac8234c3acfe20d83/chrome/content.js#L30
try {
Object.defineProperty(document, 'visibilityState', {
get() {
return 'visible';
}
});
}catch{}
try {
Object.defineProperty(document, 'hidden', {
get() {
return false;
}
});
}catch{}
var block = e => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
};
document.addEventListener('visibilitychange', block, true);
document.addEventListener('webkitvisibilitychange', block, true);
document.addEventListener('mozvisibilitychange', block, true);
document.addEventListener('hasFocus', block, true);
try {
if (/Firefox/.test(navigator.userAgent)) {
Object.defineProperty(document, 'mozHidden', {
get() {
return false;
}
});
} else {
Object.defineProperty(document, 'webkitHidden', {
get() {
return false;
}
});
}
}catch{}
}
if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") {
onContentLoaded();
} else {
window.addEventListener("DOMContentLoaded", function() {
onContentLoaded();
});
}
})();

View File

@ -23,9 +23,9 @@ twitch-videoad.js text/javascript
scope.ClientIntegrityHeader = null;
scope.AuthorizationHeader = null;
}
declareOptions(window);
var twitchWorkers = [];
const oldWorker = window.Worker;
function hookWindowWorker() {
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl, options) {
var isTwitchWorker = false;
@ -108,6 +108,7 @@ twitch-videoad.js text/javascript
}
}
}
}
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
@ -580,9 +581,27 @@ twitch-videoad.js text/javascript
localStorage.setItem(lsKeyVolume, currentVolumeLS);
}, 3000);
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
hookFetch();
function isWorkerIntact() {
// Taken from Adguard Extra
const iframe = window.document.createElement('iframe');
window.document.body.append(iframe);
const cleanWindow = iframe.contentWindow;
if (cleanWindow.Worker.toString() === window.Worker.toString()) {
iframe.remove();
return true;
}
iframe.remove();
return false;
}
function onContentLoaded() {
if (!isWorkerIntact()) {
console.log('Twitch Worker is already hooked');
return;
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
declareOptions(window);
hookWindowWorker();
hookFetch();
// This stops Twitch from pausing the player when in another tab and an ad shows.
// Taken from https://github.com/saucettv/VideoAdBlockForTwitch/blob/cefce9d2b565769c77e3666ac8234c3acfe20d83/chrome/content.js#L30
try {

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (video-swap-new)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.28
// @version 1.29
// @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)
@ -35,9 +35,9 @@
scope.ClientIntegrityHeader = null;
scope.AuthorizationHeader = null;
}
declareOptions(window);
var twitchWorkers = [];
const oldWorker = window.Worker;
function hookWindowWorker() {
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl, options) {
var isTwitchWorker = false;
@ -120,6 +120,7 @@
}
}
}
}
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
@ -592,9 +593,27 @@
localStorage.setItem(lsKeyVolume, currentVolumeLS);
}, 3000);
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
hookFetch();
function isWorkerIntact() {
// Taken from Adguard Extra
const iframe = window.document.createElement('iframe');
window.document.body.append(iframe);
const cleanWindow = iframe.contentWindow;
if (cleanWindow.Worker.toString() === window.Worker.toString()) {
iframe.remove();
return true;
}
iframe.remove();
return false;
}
function onContentLoaded() {
if (!isWorkerIntact()) {
console.log('Twitch Worker is already hooked');
return;
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
declareOptions(window);
hookWindowWorker();
hookFetch();
// This stops Twitch from pausing the player when in another tab and an ad shows.
// Taken from https://github.com/saucettv/VideoAdBlockForTwitch/blob/cefce9d2b565769c77e3666ac8234c3acfe20d83/chrome/content.js#L30
try {