-
Notifications
You must be signed in to change notification settings - Fork 2
/
content.js
86 lines (73 loc) · 2.56 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var videoSeletor;
var videoContainerSelector;
var urlHost = window.location.host;
if (urlHost.indexOf("youku") > -1) {
videoSeletor = "#ykPlayer video";
videoContainerSelector = "#ykPlayer .youku-film-player";
} else if (urlHost.indexOf("iqiyi") > -1) {
videoSeletor = "#flashbox video";
videoContainerSelector = "#flashbox .pw-video";
}
var $video = document.querySelector(videoSeletor);
var container = document.createElement("DIV");
container.style.position = "absolute";
container.style.top = 0;
container.style.right = 0;
container.style.opacity = 0.7;
container.style.zIndex = 99999;
container.className = "ynk-playback-control";
var downBtn = document.createElement("BUTTON");
downBtn.appendChild(document.createTextNode("<<"));
downBtn.addEventListener("click", function () {
$video.playbackRate -= 0.25;
updateRate();
})
var rateBtn = document.createElement("BUTTON");
rateBtn.style.width = "40px";
rateBtn.appendChild(document.createTextNode("Rate"));
rateBtn.addEventListener("click", function () {
$video.playbackRate = 1;
updateRate();
})
var upBtn = document.createElement("BUTTON");
upBtn.appendChild(document.createTextNode(">>"));
upBtn.addEventListener("click", function () {
$video.playbackRate += 0.25;
updateRate();
})
var fullScreenBtn = document.createElement("BUTTON");
fullScreenBtn.appendChild(document.createTextNode("[ ]"));
fullScreenBtn.addEventListener("click", function () {
if(document.webkitIsFullScreen){
document.webkitExitFullscreen();
}else{
$video.parentElement.webkitRequestFullScreen();
}
})
function updateRate() {
rateBtn.innerHTML = $video.playbackRate;
}
container.appendChild(downBtn);
container.appendChild(rateBtn);
container.appendChild(upBtn);
container.appendChild(fullScreenBtn);
function youkuVideoElementInserted(e) {
console.log(e.target.nodeName);
if (e.target.nodeName === "VIDEO") {
document.body.querySelector(videoContainerSelector).appendChild(container);
updateRate();
document.querySelector("#ykPlayer").removeEventListener("DOMNodeInserted", youkuVideoElementInserted)
}
}
if (document.body.querySelector(videoContainerSelector)) {
document.body.querySelector(videoContainerSelector).appendChild(container);
updateRate();
} else {
$("#ykPlayer").on("DOMNodeInserted", function (e) {
if (e.target.nodeName === "VIDEO") {
$video = document.querySelector(videoSeletor);
document.body.querySelector(videoContainerSelector).appendChild(container);
updateRate();
}
})
}