Skip to content

Commit

Permalink
Add preferred language option (closes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
shirt-dev committed Apr 25, 2022
1 parent 5ac499f commit a793273
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
17 changes: 17 additions & 0 deletions cadmium-playercore-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ function get_profile_list() {
return custom_profiles;
}

// eslint-disable-next-line no-unused-vars
function get_preferred_locale() {
return globalOptions.preferredLocale;
}

do_patch(
"Hello world",
/(.*)/,
Expand Down Expand Up @@ -136,5 +141,17 @@ if (globalOptions.showAllTracks) {
);
}

do_patch(
"Set preferred audio locale",
/preferredAudioLocale:.\.preferredAudioLocale/,
"preferredAudioLocale: get_preferred_locale()"
);

do_patch(
"Set preferred text locale",
/preferredTextLocale:.\.preferredTextLocale/,
"preferredTextLocale: get_preferred_locale()"
);

// run our patched copy of playercore in a non-privileged context on the page
window.Function(cadmium_src)();
1 change: 1 addition & 0 deletions content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ chromeStorageGet({
setMaxBitrate: false,
disableVP9: false,
useDDPlus: false,
preferredLocale: "en",
}).then(items => {
// very messy workaround for accessing chrome storage outside of background / content scripts
let mainScript = document.createElement("script");
Expand Down
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"manifest_version": 2,
"name": "Netflix International",
"description": "Displays all available Netflix audio tracks.",
"version": "2.0.9",
"version": "2.0.10",
"author": "shirt",
"browser_action": {
"default_icon": "img/icon128.png"
"default_icon": "img/icon128.png",
"default_popup": "pages/options.html"
},
"browser_specific_settings": {
"gecko": {
Expand Down
41 changes: 41 additions & 0 deletions pages/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

<head>
<title>Netflix International Options</title>
<style>
body {
min-width: 300px;
}
</style>
</head>

<body>
Expand All @@ -16,6 +21,42 @@
<br>
<input type="checkbox" id="useDDPlus"><label for="useDDPlus">Use Dolby Digital Plus (Chromium Edge)</label>
<br>
<label for="preferredLocale">Preferred language</label>
<select name="preferredLocale" id="preferredLocale">
<option value="ar">ar</option>
<option value="cs">cs</option>
<option value="da">da</option>
<option value="de">de</option>
<option value="el">el</option>
<option value="en">en</option>
<option value="es">es</option>
<option value="fi">fi</option>
<option value="fr">fr</option>
<option value="he">he</option>
<option value="hi">hi</option>
<option value="hr">hr</option>
<option value="hu">hu</option>
<option value="id">id</option>
<option value="it">it</option>
<option value="ja">ja</option>
<option value="ko">ko</option>
<option value="ms">ms</option>
<option value="nb">nb</option>
<option value="nl">nl</option>
<option value="pl">pl</option>
<option value="pt">pt</option>
<option value="ro">ro</option>
<option value="ru">ru</option>
<option value="sv">sv</option>
<option value="ta">ta</option>
<option value="te">te</option>
<option value="th">th</option>
<option value="tr">tr</option>
<option value="uk">uk</option>
<option value="vi">vi</option>
<option value="zh">zh</option>
</select>
<br>

<div id="status"></div>
<button id="save">Save</button>
Expand Down
4 changes: 4 additions & 0 deletions pages/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ function save_options() {
const setMaxBitrate = document.getElementById("setMaxBitrate").checked;
const disableVP9 = document.getElementById("disableVP9").checked;
const useDDPlus = document.getElementById("useDDPlus").checked;
const preferredLocale = document.getElementById("preferredLocale").value;

chrome.storage.sync.set({
use6Channels: use6Channels,
showAllTracks: showAllTracks,
setMaxBitrate: setMaxBitrate,
disableVP9: disableVP9,
useDDPlus: useDDPlus,
preferredLocale: preferredLocale,
}, function() {
var status = document.getElementById("status");
status.textContent = "Options saved.";
Expand All @@ -28,12 +30,14 @@ function restore_options() {
setMaxBitrate: false,
disableVP9: false,
useDDPlus: false,
preferredLocale: "en",
}, function(items) {
document.getElementById("use51").checked = items.use6Channels;
document.getElementById("showAllTracks").checked = items.showAllTracks;
document.getElementById("setMaxBitrate").checked = items.setMaxBitrate;
document.getElementById("disableVP9").checked = items.disableVP9;
document.getElementById("useDDPlus").checked = items.useDDPlus;
document.getElementById("preferredLocale").value = items.preferredLocale;
});
}

Expand Down

0 comments on commit a793273

Please sign in to comment.