forked from truedread/netflix-1080p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_script.js
executable file
·47 lines (39 loc) · 1.47 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
// From EME Logger extension
script_urls = [
'https://cdn.rawgit.com/ricmoo/aes-js/master/index.js',
'https://cdn.rawgit.com/Caligatio/jsSHA/master/src/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(['use6Channels', 'setMaxBitrate'], function(items) {
var use6Channels = items.use6Channels;
var setMaxBitrate = items.setMaxBitrate;
var mainScript = document.createElement('script');
mainScript.type = 'application/javascript';
mainScript.text = 'var use6Channels = ' + use6Channels + ';' + '\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.extension.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();
}