-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
background.js
113 lines (92 loc) · 2.48 KB
/
background.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
(function() {
var url = window.location.href.toString().trim();
if (url.indexOf('youtube.com') == -1)
return;
console.log("YouTube Speed Toolbar Started - I Love Cristo <3");
// Insert control.
var s = document.createElement('div');
var offset = 200;
s.innerHTML = `
<style>
.yt-toolbar-content {
position: fixed;
top: calc((100% / 2) - `+ (offset / 2) +`px);
right: 0px;
width: 33px;
height: `+ offset +`px;
background-color: rgba(0, 0, 0, 0);
z-index: 99999;
display: none;
}
input[type=range][orient=vertical] {
-webkit-appearance: slider-vertical;
width: 8px;
height: 175px;
padding: 0 5px;
outline: none;
}
.yt-range-speed-output {
font-size: 12px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
</style>
<div class='yt-toolbar-content' >
<!--
YouTube default speed range:
0.25
0.5
0.75
1 = Normal
1.25
1.5
1.75
2
Control:
$('video').playbackRate = 1
-->
<center>
<input type="range" class="yt-range-speed" min="0.05" max="5" step="0.05" value="1" orient="vertical" ><br>
<output class="yt-range-speed-output" >1.00</output>
</center>
</div>
`;
document.body.appendChild(s);
// Controle speed.
var speed = document.querySelector('.yt-range-speed');
var output = document.querySelector('.yt-range-speed-output');
// Startup.
var speedValue = 1;
var vel = document.getElementsByTagName('video');
if (vel) {
if (vel[0]) {
if (vel[0].playbackRate) {
speedValue = vel[0].playbackRate;
}
}
}
speed.value = speedValue;
output.textContent = parseFloat(speedValue).toFixed(2);
// Realtime control.
speed.addEventListener('input', function() {
var value = parseFloat(speed.value).toFixed(2);
output.textContent = value;
var speedValue = parseFloat(speed.value);
console.log('Speed value: '+ speedValue);
document.getElementsByTagName('video')[0].playbackRate = speedValue;
});
// Visibility control.
var internvalSpeedRunning = false;
setInterval(function() {
if (internvalSpeedRunning == false) {
internvalSpeedRunning = true;
var url = window.location.href.toString().trim();
if (url.indexOf('youtube.com') != -1 && url.indexOf('watch') != -1) {
document.querySelector('.yt-toolbar-content').style.display = 'block';
} else {
document.querySelector('.yt-toolbar-content').style.display = 'none';
}
internvalSpeedRunning = false;
}
}, 1000);
})();