-
Notifications
You must be signed in to change notification settings - Fork 4
/
injector.js
142 lines (131 loc) · 5.01 KB
/
injector.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var classicYoutubeActivated;
var watchedOverlayActivated;
load_options();
// Without this 1 ms delay, this would execute before the settings are loaded. No idea why...
// Inject CSS
setTimeout(function() {
// Hack to work around different loading times in different environments
repeatXtimes(3, 2000, function() {
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/cssVars.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
if (classicYoutubeActivated == true) {
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/index.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/masthead/index.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/masthead/menu-button.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/app-drawer/index.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/homepage/index.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/watchpage/index.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/masthead/search-box.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/buttons/index.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
docReady(function() {
// DOM is loaded and ready for manipulation here
var link = document.createElement("link");
link.href = chrome.extension.getURL("injections/classicYouTubeDesign/buttons/button-ripple.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
});
};
// if (watchedOverlayActivated == true) {
// docReady(function() {
// // DOM is loaded and ready for manipulation here
// var link = document.createElement("link");
// link.href = chrome.extension.getURL("injections/watchedOverlay.css");
// link.type = "text/css";
// link.rel = "stylesheet";
// document.getElementsByTagName("head")[0].appendChild(link);
// });
// };
})
}, 1);
// Load options from chrome.storage
function load_options() {
chrome.storage.sync.get(function(items) {
// Use default values, if necessary
if (items.classicYoutubeActivated == null) {
items.classicYoutubeActivated = true;
}
if (items.watchedOverlayActivated == null) {
items.watchedOverlayActivated = true;
}
classicYoutubeActivated = items.classicYoutubeActivated;
// window.alert("Value of classicYouTube option when loading options: " + items.classicYoutubeActivated);
watchedOverlayActivated = items.watchedOverlayActivated;
});
}
function docReady(fn) {
// see if DOM is already available
if (document.readyState === "complete") {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener("load", fn);
}
}
function repeatXtimes(amount, interval, fn) {
for (i = 0; i < amount; i++) {
setTimeout(fn, i * interval + 1);
}
}