-
Notifications
You must be signed in to change notification settings - Fork 2
/
repl.js
52 lines (50 loc) · 1.83 KB
/
repl.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
// replace for inline scripts - scriptlet for uBlock Origin
// example filter:
// hipsonyc.com##+js(rpx, /click.*_blank.*location\.href/, /^window\.location\.href.*\'$/, )
//
// example.com##+js(rpx, param1, param2, param3)
// param1 (regex): matching a specific inline script
// param2 regular expression, to search for
// param3 The new value (to replace with)
/// rpx.js
(function() {
'use strict';
let needle = '{{1}}';
if ( needle === '' || needle === '{{1}}' ) {
needle = '';
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
needle = needle.slice(1,-1);
} else {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
needle = new RegExp(needle, "gms");
let what = '{{2}}';
if ( what === '' || what === '{{2}}' ) {
what = '';
} else if ( what.startsWith('/') && what.endsWith('/') ) {
what = what.slice(1,-1);
} else {
what = what.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
what = new RegExp(what, "gms");
let by = '{{3}}';
if ( by === '' || by === '{{3}}' ) {
by = '';
}
const obs = new MutationObserver((mutationsList) => {
for (const mut of mutationsList) {
for (const node of mut.addedNodes) {
if (node.tagName === 'SCRIPT') {
if (needle.test(node.textContent) ) {
let ttt = node.textContent;
console.log('uBO: in:'+ttt);
ttt = ttt.replace(what, by);
console.log('uBO: out:'+ttt);
node.textContent = ttt;
}
}
}
}
});
obs.observe(document.documentElement, { childList: true, subtree: true });
})();