-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
67 lines (50 loc) · 1.59 KB
/
content.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
var myPlayer = document.querySelectorAll("video")[0];
var interval;
console.log("startTime set to :" + 0);
var startTime = 0;
console.log("stopTime set to :" + myPlayer.duration);
var stopTime = myPlayer.duration;
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request === "start") {
console.log("setting start as:" + myPlayer.currentTime)
startTime = myPlayer.currentTime;
}
if (request === "stop") {
console.log("setting stop as:" + myPlayer.currentTime)
stopTime = myPlayer.currentTime;
loopFun();
}
if (request === "end") {
console.log("ending loop");
clearInterval(interval);
}
if (request === "loop") {
loopFun();
}
});
function loopFun(){
console.log(`Loop starting from ${startTime} to ${stopTime}`);
if (interval != undefined) {
clearInterval(interval);
console.log("clear setInterval");
myPlayer.currentTime = startTime;
}
interval = setInterval(function () {
if (myPlayer.currentTime >= stopTime || myPlayer.currentTime <= startTime) {
console.log("Jump to start");
myPlayer.currentTime = startTime;
}
}, 500);
};
//alert('Grrr.')
// chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
// const re = new RegExp('bear', 'gi')
// const matches = document.documentElement.innerHTML.match(re)
// sendResponse({count: matches.length})
// })
// const re = new RegExp('bear', 'gi')
// const matches = document.documentElement.innerHTML.match(re) || []
// chrome.runtime.sendMessage({
// url: window.location.href,
// count: matches.length
// })