Skip to content

Commit

Permalink
Use github to fetch amazon worker
Browse files Browse the repository at this point in the history
  • Loading branch information
besuper committed Jan 11, 2023
1 parent 36e5b3f commit f62f0e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion firefox-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"webRequest",
"webRequestBlocking",
"https://*.twitch.tv/*",
"https://static.twitchcdn.net/assets/*"
"https://static.twitchcdn.net/assets/*",
"https://raw.githubusercontent.com/*"
],
"browser_specific_settings": {
"gecko": {
Expand Down
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"service_worker": "src/background.js"
},
"host_permissions": [
"https://raw.githubusercontent.com/*",
"https://www.twitch.tv/*",
"https://static.twitchcdn.net/assets/*"
],
Expand Down
41 changes: 34 additions & 7 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,58 @@ if (isChrome) {
// declarativeNetRequest only available on chrome
chrome.declarativeNetRequest.updateDynamicRules({
addRules: [{
'id': 1002,
'priority': 1,
'action': {
'type': "modifyHeaders",
'responseHeaders': [
{
'operation': "set",
'header': 'content-type',
'value': 'application/javascript',
}
]
},
'condition': {
'requestDomains': ['raw.githubusercontent.com']
}
},
{
'id': 1001,
'priority': 1,
'action': {
'type': 'redirect',
'redirect': {
url: chrome.runtime.getURL("src/amazon-ivs-worker.min.js")
url: "https://raw.githubusercontent.com/besuper/TwitchNoSub/master/src/amazon-ivs-worker.min.js"
}
},
'condition': {
'urlFilter': 'https://static.twitchcdn.net/assets/amazon-ivs-wasmworker.min-*.js',
}
}],
removeRuleIds: [1001]
removeRuleIds: [1001, 1002]
})
} else {
// Support firefox here
browser.webRequest.onBeforeRequest.addListener(function (details) {
return { redirectUrl: browser.runtime.getURL("src/amazon-ivs-worker.min.js") };
browser.webRequest.onBeforeRequest.addListener((details) => {
return { redirectUrl: "https://raw.githubusercontent.com/besuper/TwitchNoSub/master/src/amazon-ivs-worker.min.js" };
},
{
urls: [
"https://static.twitchcdn.net/assets/amazon-ivs-wasmworker.min-*.js"
],
urls: ["https://static.twitchcdn.net/assets/amazon-ivs-wasmworker.min-*.js"],
types: ["main_frame", "script"]
},
["blocking"]
);

browser.webRequest.onHeadersReceived.addListener((details) => {
details.responseHeaders.push({
name: 'content-type',
value: 'application/javascript'
});

return { responseHeaders: details.responseHeaders };
},
{ urls: ["https://raw.githubusercontent.com/besuper/TwitchNoSub/master/src/amazon-ivs-worker.min.js"] },
["blocking", "responseHeaders"]
);
}

0 comments on commit f62f0e1

Please sign in to comment.