-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
121 lines (105 loc) · 2.74 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
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
112
113
114
115
116
117
118
119
120
121
const url = window.location.href;
const urlsAccepted = [
{
url: "https://web.whatsapp.com/",
mainClass: "._3auIg"
},
{
url: "https://www.instagram.com/direct/",
mainClass: ".oJZym"
}
];
let speed = 1;
let motherClass, typePlatform, oldHref;
if (url.includes(urlsAccepted[0].url)) {
typePlatform = 0;
} else if (url.includes(urlsAccepted[1].url)) {
typePlatform = 1;
function urlHandler() {
oldHref = window.location.href;
let detect = function () {
if (oldHref != window.location.href) {
oldHref = window.location.href;
let divInstagram = document.querySelector("divAudioSpeeder");
if ((!divInstagram || divInstagram === null) && url.includes(urlsAccepted[1].url)) {
let intervalInsta = setInterval(() => {
if (document.querySelector(urlsAccepted[typePlatform].mainClass)) {
clearInterval(intervalInsta);
addBtn();
}
}, 1000);
}
}
};
_check = setInterval(() => {
detect()
}, 1500);
}
new urlHandler();
}
let interval = setInterval(() => {
if (document.querySelector(urlsAccepted[typePlatform].mainClass)) {
clearInterval(interval);
addBtn();
}
}, 1000);
function addBtn() {
let header = document.querySelector(urlsAccepted[typePlatform].mainClass);
let lessSpeed = document.createElement("lessSpeed");
lessSpeed.innerHTML = "≪";
lessSpeed.addEventListener("click", () => {
ctrSpeed(-1);
});
let moreSpeed = document.createElement("moreSpeed");
moreSpeed.innerHTML = "≫";
moreSpeed.addEventListener("click", () => {
ctrSpeed(1);
});
let speedBtn = document.createElement("speedCtrBtn");
speedBtn.classList.add("speederBtn");
speedBtn.addEventListener("click", () => {
setSpeed();
});
if (typePlatform === 0) { //WhatsApp
header.appendChild(lessSpeed);
header.appendChild(speedBtn);
header.appendChild(moreSpeed);
} else { //Instagram
let div = document.createElement("divAudioSpeeder");
div.appendChild(lessSpeed);
div.appendChild(speedBtn);
div.appendChild(moreSpeed);
header.appendChild(div);
}
refreshBtn();
}
function setSpeed() {
let audios = document.querySelectorAll("audio");
for (let index in audios) {
audios[index].playbackRate = speed;
}
}
function ctrSpeed(param) {
const min = 0.5;
const max = 3;
if (param > 0) {
speed += 0.25;
if (speed > max) {
speed = min;
}
} else {
speed -= 0.25;
if (speed < min) {
speed = max;
}
}
refreshBtn();
setSpeed();
}
function refreshBtn() {
if (!document.querySelector(".speederBtn")) {
return;
}
let btnSpeed = document.querySelector(".speederBtn");
btnSpeed.innerHTML = speed.toFixed(2) + "x";
}