Skip to content

Commit

Permalink
v2.0.3
Browse files Browse the repository at this point in the history
Cleaned up code, fixed CSS issues caused by Netflix update
  • Loading branch information
shirt-dev committed Sep 8, 2021
1 parent 4383594 commit 2380097
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 65 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# netflix-international
Extension to play Netflix with all dubs & subs, 1080p, and 5.1.

- Firefox: https://addons.mozilla.org/en-US/firefox/addon/netflix-international/
- Firefox: Removed by Mozilla
- Chrome: https://chrome.google.com/webstore/detail/netflix-international/pbbaoiomplacehgkfnlejmibhmbebaal

Contact me on discord: shirt#1337
Expand Down
9 changes: 4 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
// https://stackoverflow.com/a/45985333
function getBrowser() {
if (typeof chrome !== "undefined") {
Expand All @@ -19,17 +20,15 @@ chrome.webRequest.onBeforeRequest.addListener(
}

if (getBrowser() == "Chrome") {
return {
redirectUrl: chrome.extension.getURL("cadmium-playercore-shim.js")
};
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 = event => {
fetch(browser.extension.getURL("cadmium-playercore-shim.js")).
filter.onstop = () => {
fetch(browser.runtime.getURL("cadmium-playercore-shim.js")).
then(response => response.text()).
then(text => {
filter.write(encoder.encode(text));
Expand Down
22 changes: 6 additions & 16 deletions cadmium-playercore-shim.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
/* eslint-disable no-undef */
// This script runs as a drop-in replacement of the original cadmium-playercore. This is not a content script.
console.log("Netflix International script active!");

// promisify chrome storage API for easier chaining
function chromeStorageGet(opts) {
if (getBrowser() == "Firefox") {
return chrome.storage.sync.get(opts);
}
else {
return new Promise(resolve => {
chrome.storage.sync.get(opts, resolve);
});
}
}

function do_patch(desc, needle, replacement) {
var match = cadmium_src.match(needle);
if (!match) {
Expand All @@ -35,8 +24,9 @@ request.send();

var cadmium_src = request.responseText;

// eslint-disable-next-line no-unused-vars
function get_profile_list() {
custom_profiles = [
var custom_profiles = [
"playready-h264mpl30-dash",
"playready-h264mpl31-dash",
"playready-h264mpl40-dash",
Expand Down Expand Up @@ -82,19 +72,19 @@ do_patch(
"Custom profiles 2",
/(name:"default",profiles:).}/,
"$1 get_profile_list()}"
)
);

do_patch(
"Re-enable Ctrl+Shift+Alt+S menu",
/this\...\....\s*\&\&\s*this\.toggle\(\);/,
/this\...\....\s*&&\s*this\.toggle\(\);/,
"this.toggle();"
);

if (globalOptions.showAllTracks) {
do_patch("Show all audio tracks",
/"showAllSubDubTracks",!1/,
"\"showAllSubDubTracks\",!0"
)
);
}

// run our patched copy of playercore in a non-privileged context on the page
Expand Down
83 changes: 42 additions & 41 deletions content_script.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-undef */

script_urls = [];
var script_urls = [];

urls = [
'netflix_max_bitrate.js'
var urls = [
"netflix_max_bitrate.js"
];

// https://stackoverflow.com/a/45985333
Expand All @@ -20,50 +21,50 @@ function getBrowser() {

// promisify chrome storage API for easier chaining
function chromeStorageGet(opts) {
if (getBrowser() == "Firefox") {
return chrome.storage.sync.get(opts);
}
else {
return new Promise(resolve => {
chrome.storage.sync.get(opts, resolve);
});
}
if (getBrowser() == "Firefox") {
return chrome.storage.sync.get(opts);
}
else {
return new Promise(resolve => {
chrome.storage.sync.get(opts, resolve);
});
}
}

function attachScript(resp) {
let xhr = resp.target;
let mainScript = document.createElement('script');
mainScript.type = 'application/javascript';
if (xhr.status == 200) {
mainScript.text = xhr.responseText;
document.documentElement.appendChild(mainScript);
}
let xhr = resp.target;
let mainScript = document.createElement("script");
mainScript.type = "application/javascript";
if (xhr.status == 200) {
mainScript.text = xhr.responseText;
document.documentElement.appendChild(mainScript);
}
}

chromeStorageGet({
use6Channels: true,
showAllTracks: true,
setMaxBitrate: false,
disableVP9: false,
use6Channels: true,
showAllTracks: true,
setMaxBitrate: false,
disableVP9: false,
}).then(items => {
// very messy workaround for accessing chrome storage outside of background / content scripts
let mainScript = document.createElement('script');
mainScript.type = 'application/javascript';
mainScript.text = `var globalOptions = JSON.parse('${JSON.stringify(items)}');`;
document.documentElement.appendChild(mainScript);
// very messy workaround for accessing chrome storage outside of background / content scripts
let mainScript = document.createElement("script");
mainScript.type = "application/javascript";
mainScript.text = `var globalOptions = JSON.parse('${JSON.stringify(items)}');`;
document.documentElement.appendChild(mainScript);
}).then(() => {
// attach and include additional scripts after we have loaded the main configuration
for (let i = 0; i < script_urls.length; i++) {
let script = document.createElement('script');
script.src = script_urls[i];
document.documentElement.appendChild(script);
}
// attach and include additional scripts after we have loaded the main configuration
for (let i = 0; i < script_urls.length; i++) {
let script = document.createElement("script");
script.src = script_urls[i];
document.documentElement.appendChild(script);
}

for (let i = 0; i < urls.length; i++) {
let mainScriptUrl = chrome.extension.getURL(urls[i]);
let xhr = new XMLHttpRequest();
xhr.open('GET', mainScriptUrl, true);
xhr.onload = attachScript;
xhr.send();
}
});
for (let i = 0; i < urls.length; i++) {
let mainScriptUrl = chrome.extension.getURL(urls[i]);
let xhr = new XMLHttpRequest();
xhr.open("GET", mainScriptUrl, true);
xhr.onload = attachScript;
xhr.send();
}
});
6 changes: 4 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Netflix International",
"description": "Displays all available Netflix audio tracks.",
"version": "2.0.2",
"version": "2.0.3",
"author": "shirt",
"browser_action": {
"default_icon": "img/icon128.png"
Expand All @@ -24,6 +24,7 @@
"*://www.netflix.com/*"
],
"all_frames": true,
"css": ["netflix.css"],
"js": ["content_script.js"],
"run_at": "document_start"
}],
Expand All @@ -36,7 +37,8 @@
},
"web_accessible_resources": [
"cadmium-playercore-shim.js",
"netflix_max_bitrate.js"
"netflix_max_bitrate.js",
"netflix.css"
],
"permissions": [
"storage",
Expand Down
14 changes: 14 additions & 0 deletions netflix.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Fixes audio and subtitle picker scrolling */

.watch-video--selector-audio-subtitle {
display: flex;
}

div[data-uia="selector-audio-subtitle"] > div {
display: flex;
flex-direction: column;
}

div[data-uia="selector-audio-subtitle"] > div > ul {
overflow-y: scroll;
}

0 comments on commit 2380097

Please sign in to comment.