From 57c6f966712a0bf53beff899b3adb6a98f5dc677 Mon Sep 17 00:00:00 2001 From: ryanbr Date: Wed, 21 Aug 2024 04:32:41 +0000 Subject: [PATCH] Re-sync with https://github.com/pixeltris/TwitchAdSolutions/commit/0863c6 --- resources/vaft-ublock-origin.js | 36 ++++++++--------------- resources/video-swap-new-ublock-origin.js | 36 ++++++++--------------- 2 files changed, 24 insertions(+), 48 deletions(-) diff --git a/resources/vaft-ublock-origin.js b/resources/vaft-ublock-origin.js index d007d23..11b9fdc 100644 --- a/resources/vaft-ublock-origin.js +++ b/resources/vaft-ublock-origin.js @@ -811,27 +811,7 @@ 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 { @@ -873,11 +853,19 @@ } }catch{} } - if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") { - onContentLoaded(); + if (window.Worker.toString().includes('twitch')) { + console.log('Twitch Worker is already hooked'); } else { - window.addEventListener("DOMContentLoaded", function() { + window.reloadTwitchPlayer = reloadTwitchPlayer; + declareOptions(window); + hookWindowWorker(); + hookFetch(); + if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") { onContentLoaded(); - }); + } else { + window.addEventListener("DOMContentLoaded", function() { + onContentLoaded(); + }); + } } })(); diff --git a/resources/video-swap-new-ublock-origin.js b/resources/video-swap-new-ublock-origin.js index c8868b0..25b5771 100644 --- a/resources/video-swap-new-ublock-origin.js +++ b/resources/video-swap-new-ublock-origin.js @@ -580,27 +580,7 @@ localStorage.setItem(lsKeyVolume, currentVolumeLS); }, 3000); } - 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 { @@ -668,11 +648,19 @@ return realGetItem.apply(this, arguments); }; } - if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") { - onContentLoaded(); + if (window.Worker.toString().includes('twitch')) { + console.log('Twitch Worker is already hooked'); } else { - window.addEventListener("DOMContentLoaded", function() { + window.reloadTwitchPlayer = reloadTwitchPlayer; + declareOptions(window); + hookWindowWorker(); + hookFetch(); + if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") { onContentLoaded(); - }); + } else { + window.addEventListener("DOMContentLoaded", function() { + onContentLoaded(); + }); + } } })();