-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinject.js
57 lines (39 loc) · 1.44 KB
/
inject.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
/*
This is the content script.
*/
console.log("injection completed");
// inject listen.js into current webpage
var s = document.createElement('script');
s.src = chrome.extension.getURL("listen.js");
s.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
// retrieve current video information from this page
var currentVideo = document.getElementById('movie_player');
var currentTitle = document.getElementById('eow-title').getAttribute('title');
var currentDate = document.getElementById('eow-date').innerHTML;
var currentUrl = window.location.href;
// Send request for currentTitle, current Url and CurrentDate
chrome.extension.sendRequest({
"greeting": "hello",
"currentTitle": currentTitle,
"currentUrl": currentUrl,
"currentDate": currentDate
});
// Go check listen.js and listen to what ever youtube is telling
document.addEventListener('build', function(e){
var status = e.target.value;
chrome.extension.sendRequest({"afgelopen": "afgelopen","status":status});
}, false);
// Listen for video controls to be pushed.
chrome.extension.onRequest.addListener(function(hi, sender, sendResponse) {
if(hi.action == "play"){ // if counter is 1, play current video
currentVideo.playVideo();
}
else if(hi.action == "pause"){ // if counter is 2, pause current video
currentVideo.pauseVideo();
}
else
sendResponse({}); // close request
});