From 2380097d453bbed4912fd004f20a05eca41df5e0 Mon Sep 17 00:00:00 2001 From: shirtjs <2660574+shirt-dev@users.noreply.github.com> Date: Tue, 7 Sep 2021 21:54:41 -0400 Subject: [PATCH] v2.0.3 Cleaned up code, fixed CSS issues caused by Netflix update --- .eslintrc.json | 29 +++++++++++++ README.md | 2 +- background.js | 9 ++--- cadmium-playercore-shim.js | 22 +++------- content_script.js | 83 +++++++++++++++++++------------------- manifest.json | 6 ++- netflix.css | 14 +++++++ 7 files changed, 100 insertions(+), 65 deletions(-) create mode 100644 .eslintrc.json create mode 100644 netflix.css diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..9a91a3a --- /dev/null +++ b/.eslintrc.json @@ -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" + ] + } +} diff --git a/README.md b/README.md index 366b1b5..168fb81 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/background.js b/background.js index db65091..2b8ea29 100644 --- a/background.js +++ b/background.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ // https://stackoverflow.com/a/45985333 function getBrowser() { if (typeof chrome !== "undefined") { @@ -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)); diff --git a/cadmium-playercore-shim.js b/cadmium-playercore-shim.js index 3eabbb4..23c887e 100644 --- a/cadmium-playercore-shim.js +++ b/cadmium-playercore-shim.js @@ -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) { @@ -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", @@ -82,11 +72,11 @@ 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();" ); @@ -94,7 +84,7 @@ 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 diff --git a/content_script.js b/content_script.js index cea255a..dbdd5b9 100644 --- a/content_script.js +++ b/content_script.js @@ -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 @@ -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(); - } -}); \ No newline at end of file + 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(); + } +}); diff --git a/manifest.json b/manifest.json index 00c725d..4a8db55 100644 --- a/manifest.json +++ b/manifest.json @@ -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" @@ -24,6 +24,7 @@ "*://www.netflix.com/*" ], "all_frames": true, + "css": ["netflix.css"], "js": ["content_script.js"], "run_at": "document_start" }], @@ -36,7 +37,8 @@ }, "web_accessible_resources": [ "cadmium-playercore-shim.js", - "netflix_max_bitrate.js" + "netflix_max_bitrate.js", + "netflix.css" ], "permissions": [ "storage", diff --git a/netflix.css b/netflix.css new file mode 100644 index 0000000..13117f4 --- /dev/null +++ b/netflix.css @@ -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; +}