-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
sharer-pw_auto_click.user.js
55 lines (49 loc) · 1.71 KB
/
sharer-pw_auto_click.user.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
// ==UserScript==
// @name sharer.pw auto click
// @namespace https://github.com/x94fujo6rpg/SomeTampermonkeyScripts
// @updateURL https://github.com/x94fujo6rpg/SomeTampermonkeyScripts/raw/master/sharer-pw_auto_click.user.js
// @downloadURL https://github.com/x94fujo6rpg/SomeTampermonkeyScripts/raw/master/sharer-pw_auto_click.user.js
// @version 0.2
// @description auto click and redirect to download link immediately
// @author x94fujo6
// @match https://sharer.pw/file/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
window.onload = main();
function main() {
let idButton = setInterval(() => { watcherButton(idButton); }, 100);
let idLink = setInterval(() => { watcherLink(idLink); }, 100);
}
function watcherButton(id) {
let button = document.getElementById("btndl");
if (!button) return;
console.log(`stop ${watcherButton.name}(${id})`);
clearInterval(id);
button.click();
}
function watcherLink(id) {
let links = getDownloadLink();
if (!links) return;
console.log(`stop ${watcherLink.name}(${id})`);
clearInterval(id);
if (links.length === 1) {
window.location.href = links[0];
} else {
console.log("multiple links detected!! abort");
console.log(links);
}
}
function getDownloadLink() {
let links = [];
[...document.querySelectorAll("a")]
.filter(e => e.textContent.includes("click here"))
.forEach(e => links.push(e.href));
if (links.length === 0) {
return false;
} else {
return links;
}
}
})();