-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeSpeed.js
65 lines (57 loc) · 1.82 KB
/
ChangeSpeed.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
// ==UserScript==
// @name ChangeSpeed
// @namespace https://github.com/MarcoPeraza/UserScripts/
// @version 1.0
// @description Change HTML Video Speed with Ctrl + Alt + +/- . All videos on page will play at the same speed.
// @author Marco
// @match *://*/*
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle(`
#changeSpeedOverlay {
border-radius: 15px;
position: fixed;
top: 5px;
right: 5px;
padding: 30px;
background-color: rgba(0, 0, 0, 0.5);
z-index: 10000;
align-items: center;
justify-content: center;
color: #fff;
font-size: 30px;
font-weight: bold;
display: flex;
}
`)
function ChangeSpeed_Main() {
'use strict';
var currentSpeed = 1;
function displaySpeed() {
document.getElementById('changeSpeedOverlay')?.remove();
var overlay = document.createElement('div');
overlay.id = 'changeSpeedOverlay';
overlay.innerHTML = "⏩︃ " + currentSpeed.toFixed(2);
document.body.appendChild(overlay);
setTimeout(() => overlay.remove(), 2000);
}
function applySpeed() {
document.getElementsByTagName('video')?.forEach?.(vid => {
vid.playbackRate = currentSpeed;
});
}
document.addEventListener('keydown', zEvent => {
if (zEvent.ctrlKey && zEvent.altKey && (zEvent.key === '=' || zEvent.key === '-')) { // = is + without holding shift
currentSpeed += (zEvent.key === '=') ? 0.25 : -0.25;
applySpeed();
displaySpeed();
}
});
// Set all videos to current speed when they are played
document.addEventListener('play', (event) => {
applySpeed();
}, {capture: true});
// Set speed for any elements that loaded before the above event was set up
applySpeed();
}
ChangeSpeed_Main();