-
Notifications
You must be signed in to change notification settings - Fork 91
/
content_script.js
67 lines (60 loc) · 1.65 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
63
64
65
66
67
// From EME Logger extension
urls = [
'netflix_max_bitrate.js'
];
// promisify chrome storage API for easier chaining
function chromeStorageGet(opts) {
return new Promise((resolve, reject) => {
chrome.storage.sync.get(opts, (items) => {
if (chrome.runtime.lastError) {
reject(new Error(chrome.runtime.lastError));
} else {
resolve(items);
}
});
});
}
function addSettingsToHtml(settings) {
const mainScript = document.createElement('script');
mainScript.type = 'application/json';
mainScript.text = JSON.stringify(settings);
mainScript.id = "netflix-4k-5.1ddplus-settings";
document.documentElement.appendChild(mainScript);
console.log("Loaded settings");
}
async function loadScripts() {
for (let i = 0; i < urls.length; i++) {
const mainScriptUrl = await chrome.runtime.getURL(urls[i]);
const mainScript = document.createElement('script');
mainScript.type = 'application/javascript';
mainScript.src = mainScriptUrl;
document.documentElement.appendChild(mainScript);
}
}
chromeStorageGet({
setMaxBitrate: false,
useallSub: false,
useddplus: false,
useAVC: false,
useFHD: false,
useHA: false,
useAVCH: false,
usevp9: false,
useav1: false,
useprk: false,
usedef: false,
usef4k: false,
usef12k: false,
closeimsc: false,
useimscn: false,
usehevc: false,
imdef: false,
usesl: false,
useb: false,
}).then(items => {
addSettingsToHtml(items);
}).then(() => {
return loadScripts();
}).catch(error => {
console.error("Error:", error);
});