-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (33 loc) · 1.17 KB
/
index.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
const speeds = [{ '0.5x': 0.5 }, { '1x': 1 }, { '1.5x': 1.5 }, { '2x': 2 }];
let currentSpeed = speeds[1];
function getKeyValue(currentSpeed) {
return Object.keys(currentSpeed);
}
const interval = setInterval(() => {
const header = document.querySelector('._3auIg');
if (header) {
clearInterval(interval);
const button = document.createElement('button');
button.innerHTML = getKeyValue(currentSpeed);
button.classList.add('twoTimesButton');
button.addEventListener('click', () => {
const audios = document.querySelectorAll('audio');
const indexOfCurrtentSpeed = speeds.findIndex(
(speed) => speed === currentSpeed
);
if (audios.length) {
currentSpeed =
speeds.length - 1 !== indexOfCurrtentSpeed
? speeds[indexOfCurrtentSpeed + 1]
: speeds[0];
button.innerHTML = getKeyValue(currentSpeed);
audios.forEach((audio) => {
audio.onplay = () =>
(audio.playbackRate = currentSpeed[getKeyValue(currentSpeed)]);
audio.playbackRate = currentSpeed[getKeyValue(currentSpeed)];
});
}
});
header.appendChild(button);
}
}, 1000);