mirror of
https://github.com/shirt-dev/netflix-international.git
synced 2025-05-03 08:30:33 +00:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
/* eslint-disable no-undef */
|
|
// https://stackoverflow.com/a/45985333
|
|
function getBrowser() {
|
|
if (typeof chrome !== "undefined") {
|
|
if (typeof browser !== "undefined") {
|
|
return "Firefox";
|
|
} else {
|
|
return "Chrome";
|
|
}
|
|
} else {
|
|
return "Edge";
|
|
}
|
|
}
|
|
|
|
chrome.webRequest.onBeforeRequest.addListener(
|
|
function (details) {
|
|
/* Allow our shim to load an untouched copy */
|
|
if (details.url.endsWith("?no_filter")) {
|
|
return {};
|
|
}
|
|
|
|
if (getBrowser() == "Chrome") {
|
|
return { redirectUrl: chrome.runtime.getURL("cadmium-playercore-shim.js") };
|
|
}
|
|
|
|
/* Work around funky CORS behaviour on Firefox */
|
|
else if (getBrowser() == "Firefox") {
|
|
let filter = browser.webRequest.filterResponseData(details.requestId);
|
|
let encoder = new TextEncoder();
|
|
filter.onstop = () => {
|
|
fetch(browser.runtime.getURL("cadmium-playercore-shim.js")).
|
|
then(response => response.text()).
|
|
then(text => {
|
|
filter.write(encoder.encode(text));
|
|
filter.close();
|
|
});
|
|
};
|
|
return {};
|
|
}
|
|
|
|
else {
|
|
console.error("Unsupported web browser.");
|
|
return {};
|
|
}
|
|
}, {
|
|
urls: [
|
|
"*://assets.nflxext.com/*/ffe/player/html/*",
|
|
"*://www.assets.nflxext.com/*/ffe/player/html/*"
|
|
]
|
|
}, ["blocking"]
|
|
);
|