diff --git a/background.js b/background.js new file mode 100644 index 0000000..d86bfad --- /dev/null +++ b/background.js @@ -0,0 +1,47 @@ +/* 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) { + 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/*" + ], + types: ["script"] + }, ["blocking"] +); diff --git a/cadmium-playercore-shim.js b/cadmium-playercore-shim.js index 2cfef06..9dbf41b 100644 --- a/cadmium-playercore-shim.js +++ b/cadmium-playercore-shim.js @@ -41,7 +41,7 @@ function do_patch(desc, needle, replacement) { the response before the body of this script finishes executing */ var request = new XMLHttpRequest(); var cadmium_url = document.getElementById("player-core-js").src; -request.open("GET", cadmium_url, false); // synchronous +request.open("GET", cadmium_url + "?no_filter", false); // synchronous request.send(); var cadmium_src = request.responseText; @@ -100,11 +100,27 @@ function get_profile_list(original_profiles) { profiles = profiles.filter(val => !val.includes("av1-")); } - if (globalOptions.use6Channels) { - profiles = profiles.concat([ - "heaac-5.1-dash", - ]); - } + if (globalOptions.useDDPlus && MediaSource.isTypeSupported('audio/mp4; codecs="ec-3"')) { + // Dolby Digital + profiles = profiles.concat([ + "ddplus-2.0-dash", + ]); + + if (globalOptions.use6Channels) { + profiles = profiles.concat([ + "ddplus-5.1-dash", + "ddplus-5.1hq-dash", + "ddplus-atmos-dash", + ]); + } + } else { + // No Dolby Digital + if (globalOptions.use6Channels) { + profiles = profiles.concat([ + "heaac-5.1-dash", + ]); + } + } profiles = [...new Set(profiles)].sort(); return profiles; @@ -129,7 +145,7 @@ do_patch( ); do_patch( - "Re-enable Ctrl+Shift+Alt+B menu", + "Re-enable Ctrl+Shift+Alt+S menu", /this\...\....\s*&&\s*this\.toggle\(\);/, "this.toggle();" ); @@ -153,5 +169,19 @@ do_patch( "preferredTextLocale: globalOptions.preferredTextLocale" ); +if(globalOptions.useDDPlus && MediaSource.isTypeSupported('audio/mp4; codecs="ec-3"')) { + do_patch( + "Select highest audio bitrate 1", + /(indexOf\(.\))(\?[^?]+)(\?[0-9]:)/, + "$1)$3" + ); + + do_patch( + "Select highest audio bitrate 2", + /(var\sx;if\(this\.[^\)]+)/, + "$1 && !globalOptions.useDDPlus" + ); +} + // run our patched copy of playercore in a non-privileged context on the page window.Function(cadmium_src)(); diff --git a/img/icon128.png b/img/icon128.png index 32c7b64..ba0355e 100644 Binary files a/img/icon128.png and b/img/icon128.png differ diff --git a/img/icon48.png b/img/icon48.png index 6705cdb..d987966 100644 Binary files a/img/icon48.png and b/img/icon48.png differ diff --git a/manifest.json b/manifest.json index ff4ef89..3bf5b6b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { - "manifest_version": 3, + "manifest_version": 2, "name": "Netflix International", "description": "Displays all available Netflix audio and subtitle tracks.", - "version": "2.0.23", + "version": "2.0.19", "author": "shirt", - "action": { + "browser_action": { "default_icon": "img/icon128.png", "default_popup": "pages/options.html" }, @@ -19,6 +19,8 @@ }, "content_scripts": [{ "matches": [ + "*://assets.nflxext.com/*/ffe/player/html/*", + "*://www.assets.nflxext.com/*/ffe/player/html/*", "*://netflix.com/*", "*://www.netflix.com/*" ], @@ -27,35 +29,24 @@ "js": ["content_script.js"], "run_at": "document_start" }], + "background": { + "scripts": ["background.js"] + }, "options_ui": { "page": "pages/options.html", "open_in_tab": true }, - "web_accessible_resources": [{ - "resources": [ - "cadmium-playercore-shim.js", - "netflix_max_bitrate.js", - "netflix.css" - ], - "matches": [ - "*://assets.nflxext.com/*", - "*://netflix.com/*", - "*://www.netflix.com/*" - ] - }], - "declarative_net_request" : { - "rule_resources" : [{ - "id": "1", - "enabled": true, - "path": "rules.json" - }] - }, + "web_accessible_resources": [ + "cadmium-playercore-shim.js", + "netflix_max_bitrate.js", + "netflix.css" + ], "permissions": [ "storage", - "declarativeNetRequestWithHostAccess" - ], - "host_permissions": [ - "*://assets.nflxext.com/*", + "webRequest", + "webRequestBlocking", + "*://assets.nflxext.com/*/ffe/player/html/*", + "*://www.assets.nflxext.com/*/ffe/player/html/*", "*://netflix.com/*", "*://www.netflix.com/*" ] diff --git a/netflix_max_bitrate.js b/netflix_max_bitrate.js index 654c4b7..9ad496b 100644 --- a/netflix_max_bitrate.js +++ b/netflix_max_bitrate.js @@ -6,7 +6,7 @@ let getElementByXPath = function (xpath) { }; let fn = function () { - const VIDEO_SELECT = getElementByXPath("//div[text()='Video Bitrate']") || getElementByXPath("//div[text()='Video Bitrate / VMAF']"); + const VIDEO_SELECT = getElementByXPath("//div[text()='Video Bitrate']"); const AUDIO_SELECT = getElementByXPath("//div[text()='Audio Bitrate']"); const BUTTON = getElementByXPath("//button[text()='Override']"); @@ -26,7 +26,7 @@ let fn = function () { } window.dispatchEvent(new KeyboardEvent('keydown', { - keyCode: 66, + keyCode: 83, ctrlKey: true, altKey: true, shiftKey: true, diff --git a/pages/options.html b/pages/options.html index ca16bd9..f51e58a 100644 --- a/pages/options.html +++ b/pages/options.html @@ -24,6 +24,8 @@

+ +

diff --git a/pages/options.js b/pages/options.js index 386a052..1992ee0 100644 --- a/pages/options.js +++ b/pages/options.js @@ -6,6 +6,7 @@ function save_options() { const disableVP9 = document.getElementById("disableVP9").checked; const disableAV1 = document.getElementById("disableAV1").checked; const disableHPL = document.getElementById("disableHPL").checked; + const useDDPlus = document.getElementById("useDDPlus").checked; const preferredLocale = document.getElementById("preferredLocale").value; const preferredTextLocale = document.getElementById("preferredTextLocale").value; @@ -16,6 +17,7 @@ function save_options() { disableVP9: disableVP9, disableAV1: disableAV1, disableHPL: disableHPL, + useDDPlus: useDDPlus, preferredLocale: preferredLocale, preferredTextLocale: preferredTextLocale, }, function() { @@ -34,6 +36,7 @@ function reset_options() { document.getElementById("disableVP9").checked = false; document.getElementById("disableAV1").checked = true; document.getElementById("disableHPL").checked = false; + document.getElementById("useDDPlus").checked = false; document.getElementById("preferredLocale").value = null; document.getElementById("preferredTextLocale").value = null; @@ -44,6 +47,7 @@ function reset_options() { disableVP9: false, disableAV1: true, disableHPL: false, + useDDPlus: false, preferredLocale: null, preferredTextLocale: null, }, function() { @@ -63,6 +67,7 @@ function restore_options() { disableVP9: false, disableAV1: true, disableHPL: false, + useDDPlus: false, preferredLocale: null, preferredTextLocale: null, }, function(items) { @@ -72,6 +77,7 @@ function restore_options() { document.getElementById("disableVP9").checked = items.disableVP9; document.getElementById("disableAV1").checked = items.disableAV1; document.getElementById("disableHPL").checked = items.disableHPL; + document.getElementById("useDDPlus").checked = items.useDDPlus; document.getElementById("preferredLocale").value = items.preferredLocale; document.getElementById("preferredTextLocale").value = items.preferredTextLocale; }); diff --git a/rules.json b/rules.json deleted file mode 100644 index a948a65..0000000 --- a/rules.json +++ /dev/null @@ -1,26 +0,0 @@ -[ - { - "id": 1, - "priority": 1, - "action": { - "type": "redirect", - "redirect": { "extensionPath": "/cadmium-playercore-shim.js" } - }, - "condition": { - "urlFilter": "*://assets.nflxext.com/*/ffe/player/html/*", - "resourceTypes": ["script"] - } - }, - { - "id": 2, - "priority": 1, - "action": { - "type": "redirect", - "redirect": { "extensionPath": "/cadmium-playercore-shim.js" } - }, - "condition": { - "urlFilter": "*://assets.nflxext.com/player/html/ffe/*", - "resourceTypes": ["script"] - } - } -]