-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_scriptlets.js
79 lines (78 loc) · 2.47 KB
/
my_scriptlets.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
// based on https://github.com/NanoAdblocker/NanoFilters/blob/master/NanoFilters/NanoResources.txt#L283
/// click-element.js
/// alias ce.js
// [required] 1: element to click;
// [optional] 2: url should match given token; 3: timeout, if not set, it will click directly.
// example.com##+js(ce, element)
// example.com##+js(ce, element, href, timeout)
// example.com##+js(ce, element, , timeout)
(() => {
let selector = '{{1}}';
if ( selector === '' || selector === '{{1}}' ) {
return;
}
let href = '{{2}}';
if ( href === '' || href === '{{2}}' ) {
href = '';
}
let msecs = '{{3}}';
if ( msecs === '{{3}}' ) {
msecs = '';
}
let timeout = parseInt(msecs, 10);
if ( isNaN(timeout) || isFinite(timeout) === false ) {
timeout = 0;
}
var click = function() {
var elements = document.querySelectorAll(selector);
for ( var element of elements ) {
element.click();
}
};
if (window.location.href.indexOf(href) !== -1 ) {
setTimeout(function() {
if ( document.readyState === 'interactive' ||
document.readyState === 'complete' ) {
click();
} else {
addEventListener('DOMContentLoaded', click);
}
}, timeout);
}
})();
// Taken from AdGuard
/// click-element-observer.js
/// alias ceo.js
// [required] 1: element to click;
// [optional] 2: url should match given token; 3: disconnectTimeout.
// example.com##+js(ceo, element)
// example.com##+js(ceo, element, href, disconnectTimeout)
// example.com##+js(ceo, element, , disconnectTimeout)
(() => {
let aelem = '{{1}}';
if ( aelem === '' || aelem === '{{1}}' ) {
return;
}
let bhref = '{{2}}';
if ( bhref === '' || bhref === '{{2}}' ) {
bhref = '';
}
let dmsecs = '{{3}}';
if ( dmsecs === '{{3}}' ) {
dmsecs = '';
}
let etimeout = parseInt(dmsecs, 10);
if ( isNaN(etimeout) || isFinite(etimeout) === false ) {
etimeout = 10000;
}
if ( window.location.href.indexOf(bhref) !== -1 ) {
const o = new MutationObserver(function() {
const e = document.querySelector(aelem);
e && (o.disconnect(), e.click())
});
o.observe(document,{ childList:!0, subtree:!0 }),
setTimeout(function() {
o.disconnect()
}, etimeout)
}
})();