-
Notifications
You must be signed in to change notification settings - Fork 0
/
autolike.js
47 lines (35 loc) · 930 Bytes
/
autolike.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
// @ts-check
// NAME: Autolike
// AUTHOR: artemkozaev
// DESCRIPTION: Autolike
/// <reference path="../globals.d.ts" />
(function Autolike() {
const player = Spicetify.Player;
if (!getLikeButton() || !player) {
setTimeout(Autolike, 100);
return;
}
player.addEventListener("onprogress", watchChange);
const DEBOUNCE_TIME = 3000;
const LIKE_THRESHOLD = 0.95;
let debouncing = 0;
function watchChange(event) {
// run only once per 3 seconds
if (debouncing) {
if (event.timeStamp - debouncing > DEBOUNCE_TIME) debouncing = 0;
return;
}
debouncing = event.timeStamp;
const heart = getLikeButton();
if (
heart.ariaChecked === "true" ||
!player.isPlaying() ||
player.getProgressPercent() < LIKE_THRESHOLD
)
return;
heart.click();
}
function getLikeButton() {
return document.querySelector(".control-button-heart");
}
})();