Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
"web_accessible_resources": [
{
"resources": [
"src/amazon-ivs-worker.min.js",
"src/app.js",
"src/chrome/app.js"
"src/chrome/app.js",
"src/download.js"
],
"matches": [
"https://*.twitch.tv/*"
]
}
],
"background": {
"service_worker": "src/background.js"
},
"content_scripts": [
{
"matches": [
Expand All @@ -34,5 +39,11 @@
"https://*.twitch.tv/*",
"https://static.twitchcdn.net/assets/*"
],
"permissions": []
"permissions": [
"activeTab",
"tabs",
"webRequest",
"webNavigation",
"declarativeNetRequest"
]
}
15 changes: 7 additions & 8 deletions src/amazon-ivs-worker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 23 additions & 16 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
// From vaft script (https://github.com/pixeltris/TwitchAdSolutions/blob/master/vaft/vaft.user.js#L299)
function getWasmWorkerJs(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
req.overrideMimeType("text/javascript");
req.send();
return req.responseText;
}
var isVariantA = false;
const originalAppendChild = document.head.appendChild;

document.head.appendChild = function (element) {
if (element.tagName === "SCRIPT") {
if (element.src.includes("player-core-variant-a")) {
isVariantA = true;
}
}

return originalAppendChild.call(this, element);
};

const oldWorker = window.Worker;

window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl) {
var workerString = getWasmWorkerJs(`${twitchBlobUrl.replaceAll("'", "%27")}`);
super(twitchBlobUrl);

this.addEventListener("message", (event) => {
const data = event.data;

if ((data.id == 1 || isVariantA) && data.type == 1) {
const newData = event.data;

const blobUrl = URL.createObjectURL(new Blob([`
importScripts(
'${patch_url}',
);
${workerString}
`]));
newData.arg = [data.arg];

super(blobUrl);
this.postMessage(newData);
}
});
}
}
82 changes: 82 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

chrome.webNavigation.onBeforeNavigate.addListener(function () {

}, {
url: [{ hostContains: "twitch" }]
});

var isChrome = chrome.declarativeNetRequest != undefined;
var cdnLink = '';

if (isChrome) {

chrome.runtime.onStartup.addListener(() => {
chrome.runtime.reload();
});
}


const app = () => {
if (isChrome) {

chrome.declarativeNetRequest.updateDynamicRules({
addRules: [{
'id': 1001,
'priority': 1,
'action': {
'type': 'redirect',
'redirect': { url: cdnLink }
},
'condition': { urlFilter: 'https://static.twitchcdn.net/assets/amazon-ivs-wasmworker.min-*.js' }
}],
removeRuleIds: [1001]
});

chrome.declarativeNetRequest.updateDynamicRules({
addRules: [{
'id': 1002,
'priority': 1,
'action': {
'type': 'redirect',
'redirect': { url: cdnLink }
},
'condition': { urlFilter: 'https://assets.twitch.tv/assets/amazon-ivs-wasmworker.min-*.js' }
}],
removeRuleIds: [1002]
});
} else {

browser.webRequest.onBeforeRequest.addListener(() => {
return { redirectUrl: cdnLink };
}, {
urls: [
"https://static.twitchcdn.net/assets/amazon-ivs-wasmworker.min-*.js",
"https://assets.twitch.tv/assets/amazon-ivs-wasmworker.min-*.js"
],
types: ["main_frame", "script"]
}, ["blocking"]);
}

};

(async () => {

try {
const response = await fetch("https://api.github.com/repos/besuper/TwitchNoSub/commits");
const content = await response.json();

var latestCommit = content[0].sha;

console.log("Lastest commit sha: " + latestCommit);

cdnLink = `https://cdn.jsdelivr.net/gh/besuper/TwitchNoSub@${latestCommit}/src/amazon-ivs-worker.min.js`;
} catch (e) {
console.log(e);

cdnLink = `https://cdn.jsdelivr.net/gh/besuper/TwitchNoSub/src/amazon-ivs-worker.min.js`;
}

console.log("CDN link : " + cdnLink);

app();
})();
Loading