-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.js
More file actions
60 lines (58 loc) · 2.04 KB
/
loader.js
File metadata and controls
60 lines (58 loc) · 2.04 KB
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
(function(){
// Thanks RəAnna !
window.Intercom = {}, window.amplitude = { __VERSION__: true };
function $(selector) {return document.querySelectorAll(selector);}
function loadScript(URL, code) {
// Check if DOM is ready
if (!$('.loading-box.d-none').length || !$('.logout').length) {
setTimeout(function(){loadScript(URL, code);}, 200);
} else {
var script = document.createElement('script');
if (URL === null && typeof code === 'string') {
script.className = 'pi-custom-script';
script.type = 'text/javascript';
script.innerHTML = code;
$('head')[0].appendChild(script);
} else {
typeof URL == 'undefined' ? script.id = 'pi-script' : script.className = 'pi-custom-script';
script.type = 'text/javascript';
typeof URL !== 'undefined' ? script.src = URL : script.src = 'https://rawgit.com/Plug-It/pi/pre-release/js/pi.js';
$('head')[0].appendChild(script);
}
}
}
function autoReload() {
// if not completely loaded, call again until loaded
if (!$('#video').length && !$('.spinner').length) setTimeout(autoReload, 200);
else if ($('#video').length) {
setTimeout(function(){location.reload();}, 60*1000);
}
}
function removeVideo() {
if (!$('#video').length && !$('.spinner').length) setTimeout(removeVideo, 200);
else if ($('#video').length) {
$('.content')[0].removeChild($('#video')[0]);
}
}
// Retrieve options
chrome.storage.sync.get({
// Default settings
enabled: true,
autof5: true,
hideVideo: true,
custom_enabled: false,
scripts: [],
custom_code: ''
}, function(items) {
if (items.enabled) loadScript();
if (items.autof5) autoReload();
if (items.hideVideo) removeVideo();
if (items.custom_enabled) {
var scripts = items.scripts;
for (var i = 0; i < scripts.length; i++) {
if (scripts[i][0] && scripts[i][1].length) loadScript(scripts[i][1]);
}
}
if (items.custom_code.length) loadScript(null, items.custom_code);
});
})();