-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun-on-likes-page.js
48 lines (40 loc) · 957 Bytes
/
run-on-likes-page.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
(() => {
const selectorsAll = [
'.sc-button-more',
'.sc-button-addtoset',
'.addToPlaylistButton[title=""]',
'button[title="Close"]',
];
addToPlaylist(selectorsAll);
function addToPlaylist (_selectors) {
const selectors = [..._selectors];
selecting(selectors.shift())
.then(element => {
element.click();
if (selectors.length) {
addToPlaylist(selectors);
} else {
document.querySelector('.soundList__item').remove();
setTimeout(() => addToPlaylist([...selectorsAll]), 500);
}
})
.catch(err => {
console.error('Something went wrong!');
console.trace(err);
});
}
function selecting (selector) {
return new Promise((resolve, reject) => {
const pooling = setInterval(() => {
const element = document.querySelector(selector);
if (element) {
resolve(element);
}
}, 100);
setTimeout(() => {
clearInterval(pooling);
reject();
}, 5000);
});
}
})();