-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
40 lines (35 loc) · 1.18 KB
/
index.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
function inject() {
//DECLARE HEAD ELEMENT
const head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
//INJECT SOCKETIO SCRIPT
const socketio = document.createElement("script");
socketio.setAttribute("src", chrome.extension.getURL('socket.js'));
socketio.type = "module";
socketio.async = false;
head.insertBefore(socketio, head.lastChild);
//SEND ALERT
//alert("injecting script...")
const injectscript = document.createElement('script');
injectscript.setAttribute("src", chrome.extension.getURL('inject.js'));
injectscript.id = "inject-script";
injectscript.async = false;
document.body.insertBefore(injectscript, document.body.lastChild);
}
var initvideo = document.querySelector("video");
if (!initvideo) {
var videoobserver = new MutationObserver(function (mutations, me) {
var video = document.querySelector("video");
if (video) {
inject()
me.disconnect(); //STOP OBSERVING
return;
}
});
//START OBSERVING
videoobserver.observe(document, {
childList: true,
subtree: true
});
} else {
inject()
}