Skip to content

Commit

Permalink
Sanity checks on worker url
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltris committed Jun 28, 2024
1 parent e73c6fb commit 39666c7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
15 changes: 12 additions & 3 deletions vaft/vaft-ublock-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ twitch-videoad.js text/javascript
var IsPlayerAutoQuality = null;
const oldWorker = window.Worker;
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl) {
constructor(twitchBlobUrl, options) {
var isTwitchWorker = false;
try {
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
} catch {}
if (!isTwitchWorker) {
super(twitchBlobUrl, options);
return;
}
var newBlobStr = `
${getStreamUrlForResolution.toString()}
${getStreamForResolution.toString()}
Expand All @@ -84,7 +92,7 @@ twitch-videoad.js text/javascript
${tryNotifyTwitch.toString()}
${parseAttributes.toString()}
${getWasmWorkerUrl.toString()}
var workerUrl = getWasmWorkerUrl('${twitchBlobUrl}');
var workerUrl = getWasmWorkerUrl('${twitchBlobUrl.replaceAll("'", "%27")}');
if (workerUrl && workerUrl.includes('assets.twitch.tv/assets/amazon-ivs-wasmworker')) {
declareOptions(self);
self.addEventListener('message', function(e) {
Expand All @@ -108,7 +116,7 @@ twitch-videoad.js text/javascript
importScripts(workerUrl);
}
`;
super(URL.createObjectURL(new Blob([newBlobStr])));
super(URL.createObjectURL(new Blob([newBlobStr])), options);
twitchWorkers.push(this);
this.onmessage = function(e) {
if (e.data.key == 'ShowAdBlockBanner') {
Expand Down Expand Up @@ -238,6 +246,7 @@ twitch-videoad.js text/javascript
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
req.overrideMimeType("text/javascript");
req.send();
return req.responseText.split("'")[1];
}
Expand Down
17 changes: 13 additions & 4 deletions vaft/vaft.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (vaft)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 9.0.0
// @version 10.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
Expand Down Expand Up @@ -82,7 +82,15 @@
var IsPlayerAutoQuality = null;
const oldWorker = window.Worker;
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl) {
constructor(twitchBlobUrl, options) {
var isTwitchWorker = false;
try {
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
} catch {}
if (!isTwitchWorker) {
super(twitchBlobUrl, options);
return;
}
var newBlobStr = `
${getStreamUrlForResolution.toString()}
${getStreamForResolution.toString()}
Expand All @@ -96,7 +104,7 @@
${tryNotifyTwitch.toString()}
${parseAttributes.toString()}
${getWasmWorkerUrl.toString()}
var workerUrl = getWasmWorkerUrl('${twitchBlobUrl}');
var workerUrl = getWasmWorkerUrl('${twitchBlobUrl.replaceAll("'", "%27")}');
if (workerUrl && workerUrl.includes('assets.twitch.tv/assets/amazon-ivs-wasmworker')) {
declareOptions(self);
self.addEventListener('message', function(e) {
Expand All @@ -120,7 +128,7 @@
importScripts(workerUrl);
}
`;
super(URL.createObjectURL(new Blob([newBlobStr])));
super(URL.createObjectURL(new Blob([newBlobStr])), options);
twitchWorkers.push(this);
this.onmessage = function(e) {
if (e.data.key == 'ShowAdBlockBanner') {
Expand Down Expand Up @@ -250,6 +258,7 @@
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
req.overrideMimeType("text/javascript");
req.send();
return req.responseText.split("'")[1];
}
Expand Down
15 changes: 12 additions & 3 deletions video-swap-new/video-swap-new-ublock-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ twitch-videoad.js text/javascript
var twitchWorkers = [];
const oldWorker = window.Worker;
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl) {
constructor(twitchBlobUrl, options) {
var isTwitchWorker = false;
try {
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
} catch {}
if (!isTwitchWorker) {
super(twitchBlobUrl, options);
return;
}
var newBlobStr = `
${processM3U8.toString()}
${hookWorkerFetch.toString()}
Expand All @@ -39,7 +47,7 @@ twitch-videoad.js text/javascript
${parseAttributes.toString()}
${onFoundAd.toString()}
${getWasmWorkerUrl.toString()}
var workerUrl = getWasmWorkerUrl('${twitchBlobUrl}');
var workerUrl = getWasmWorkerUrl('${twitchBlobUrl.replaceAll("'", "%27")}');
if (workerUrl && workerUrl.includes('assets.twitch.tv/assets/amazon-ivs-wasmworker')) {
declareOptions(self);
self.addEventListener('message', function(e) {
Expand All @@ -55,7 +63,7 @@ twitch-videoad.js text/javascript
importScripts(workerUrl);
}
`
super(URL.createObjectURL(new Blob([newBlobStr])));
super(URL.createObjectURL(new Blob([newBlobStr])), options);
twitchWorkers.push(this);
this.onmessage = function(e) {
// NOTE: Removed adDiv caching as '.video-player' can change between streams?
Expand Down Expand Up @@ -103,6 +111,7 @@ twitch-videoad.js text/javascript
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
req.overrideMimeType("text/javascript");
req.send();
return req.responseText.split("'")[1];
}
Expand Down
17 changes: 13 additions & 4 deletions video-swap-new/video-swap-new.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (video-swap-new)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.27
// @version 1.28
// @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)
Expand Down Expand Up @@ -39,7 +39,15 @@
var twitchWorkers = [];
const oldWorker = window.Worker;
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl) {
constructor(twitchBlobUrl, options) {
var isTwitchWorker = false;
try {
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
} catch {}
if (!isTwitchWorker) {
super(twitchBlobUrl, options);
return;
}
var newBlobStr = `
${processM3U8.toString()}
${hookWorkerFetch.toString()}
Expand All @@ -51,7 +59,7 @@
${parseAttributes.toString()}
${onFoundAd.toString()}
${getWasmWorkerUrl.toString()}
var workerUrl = getWasmWorkerUrl('${twitchBlobUrl}');
var workerUrl = getWasmWorkerUrl('${twitchBlobUrl.replaceAll("'", "%27")}');
if (workerUrl && workerUrl.includes('assets.twitch.tv/assets/amazon-ivs-wasmworker')) {
declareOptions(self);
self.addEventListener('message', function(e) {
Expand All @@ -67,7 +75,7 @@
importScripts(workerUrl);
}
`
super(URL.createObjectURL(new Blob([newBlobStr])));
super(URL.createObjectURL(new Blob([newBlobStr])), options);
twitchWorkers.push(this);
this.onmessage = function(e) {
// NOTE: Removed adDiv caching as '.video-player' can change between streams?
Expand Down Expand Up @@ -115,6 +123,7 @@
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
req.overrideMimeType("text/javascript");
req.send();
return req.responseText.split("'")[1];
}
Expand Down

0 comments on commit 39666c7

Please sign in to comment.