-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentScript.js
68 lines (64 loc) · 2.36 KB
/
contentScript.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
'use strict';
if (Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'playing') == undefined) {
Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
get: function(){
return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
}
})
}
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
var vids = document.getElementsByTagName('video')
for ( var i = 0; i < vids.length; i++ ) {
var currentRate = vids.item(i).playbackRate
console.log(currentRate)
switch (message) {
case 'toggle-info':
sendResponse(currentRate)
break;
case 'toggle-play':
vids.item(i).play()
break;
case 'toggle-pause':
if (!vids.item(i).playing) { return; }
vids.item(i).pause()
break;
case 'toggle-reduce-speed':
if (!vids.item(i).playing) { return; }
if (currentRate > 0.5) {
vids.item(i).playbackRate = currentRate - 0.25
sendMessage(vids.item(i).playbackRate)
}
break;
case 'toggle-increase-speed':
if (!vids.item(i).playing) { return; }
if (currentRate != 2) {
vids.item(i).playbackRate = currentRate + 0.25
sendMessage(vids.item(i).playbackRate)
}
break;
default:
vids.item(i).playbackRate = message
}
}
});
function sendMessage(value) {
chrome.runtime.sendMessage({playback_rate: value});
}
// (function() {
// var vids = document.getElementsByTagName('video')
// for ( var i = 0; i < vids.length; i++ ) {
// vid.onratechange = function() {
// sendMessage(this.playbackRate)
// };
// }
// })();
// var vid = document.getElementById("myVideo");
// vid.onplay = function() {
// alert("The video has started to play");
// };
// vid.onratechange = function() {myFunction()};
// function myFunction() {
// alert("The playing speed of the video was changed");
// }
//Событеи смены скорость и передавать в экстеншен
//Событие плей и пауза