-
Notifications
You must be signed in to change notification settings - Fork 11
/
content_script.js
62 lines (55 loc) · 1.52 KB
/
content_script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* eslint-disable no-undef */
var script_urls = [];
var urls = [
"netflix_max_bitrate.js"
];
// https://stackoverflow.com/a/45985333
function getBrowser() {
if (typeof chrome !== "undefined") {
if (typeof browser !== "undefined") {
return "Firefox";
} else {
return "Chrome";
}
} else {
return "Edge";
}
}
// 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);
});
}
}
chromeStorageGet({
use6Channels: true,
showAllTracks: true,
setMaxBitrate: false,
disableVP9: false,
disableAV1: true,
disableHPL: false,
useDDPlus: false,
preferredLocale: null,
preferredTextLocale: null,
}).then(items => {
// very messy workaround for accessing chrome storage outside of background / content scripts
let mainScript = document.createElement("script");
mainScript.type = "application/json";
mainScript.id = "netflix-intl-settings";
mainScript.text = 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 < urls.length; i++) {
const mainScriptUrl = chrome.runtime.getURL(urls[i]);
const mainScript = document.createElement('script');
mainScript.type = 'application/javascript';
mainScript.src = mainScriptUrl;
document.documentElement.appendChild(mainScript);
}
});