Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbr committed Aug 21, 2024
1 parent 5cd5372 commit 57c6f96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 48 deletions.
36 changes: 12 additions & 24 deletions resources/vaft-ublock-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
});
}
}
})();
36 changes: 12 additions & 24 deletions resources/video-swap-new-ublock-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
});
}
}
})();

0 comments on commit 57c6f96

Please sign in to comment.