forked from lkmvip/netflix-4K-DDplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_script.js
59 lines (55 loc) · 1.97 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
// From EME Logger extension
/*
script_urls = [
'https://cdn.rawgit.com/ricmoo/aes-js/master/index.js',
'https://cdn.rawgit.com/Caligatio/jsSHA/master/dist/sha.js'
]
*/
urls = [
//'msl_client.js',
'netflix_max_bitrate.js'
]
// very messy workaround for accessing chrome storage outside of background / content scripts
chrome.storage.sync.get(['useallSub', 'useddplus', 'useAVC', 'useDV', 'useFHD', 'useHA', 'useAVCH', 'setMaxBitrate'], function(items) {
var useallSub = items.useallSub;
var useddplus = items.useddplus;
var useAVC = items.useAVC;
var useDV = items.useDV;
var useFHD = items.useFHD;
var useHA = items.useHA;
var useAVCH = items.useAVCH;
var setMaxBitrate = items.setMaxBitrate;
var mainScript = document.createElement('script');
mainScript.type = 'application/javascript';
mainScript.text = 'var useallSub = ' + useallSub + ';' + '\n'
+ 'var useddplus = ' + useddplus + ';' + '\n'
+ 'var useAVC = ' + useAVC + ';' + '\n'
+ 'var useDV = ' + useDV + ';' + '\n'
+ 'var useFHD = ' + useFHD + ';' + '\n'
+ 'var useHA = ' + useHA + ';' + '\n'
+ 'var useAVCH = ' + useAVCH + ';' + '\n'
+ 'var setMaxBitrate = ' + setMaxBitrate + ';';
document.documentElement.appendChild(mainScript);
});
/*
for (var i = 0; i < script_urls.length; i++) {
var script = document.createElement('script');
script.src = script_urls[i];
document.documentElement.appendChild(script);
}
*/
for (var i = 0; i < urls.length; i++) {
var mainScriptUrl = chrome.runtime.getURL(urls[i]);
var xhr = new XMLHttpRequest();
xhr.open('GET', mainScriptUrl, true);
xhr.onload = function(e) {
var xhr = e.target;
var mainScript = document.createElement('script');
mainScript.type = 'application/javascript';
if (xhr.status == 200) {
mainScript.text = xhr.responseText;
document.documentElement.appendChild(mainScript);
}
};
xhr.send();
}