-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathprevent-adfly.js
99 lines (90 loc) · 2.66 KB
/
prevent-adfly.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* eslint-disable func-names */
import { hit, setPropertyAccess, logMessage } from '../helpers';
/**
* @scriptlet prevent-adfly
*
* @description
* Prevents anti-adblock scripts on adfly short links.
*
* Related UBO scriptlet:
* https://github.com/gorhill/uBlock/wiki/Resources-Library#adfly-defuserjs-
*
* ### Syntax
*
* ```adblock
* example.org#%#//scriptlet('prevent-adfly')
* ```
*
* @added v1.0.4.
*/
export function preventAdfly(source) {
const isDigit = (data) => /^\d$/.test(data);
const handler = function (encodedURL) {
let evenChars = '';
let oddChars = '';
for (let i = 0; i < encodedURL.length; i += 1) {
if (i % 2 === 0) {
evenChars += encodedURL.charAt(i);
} else {
oddChars = encodedURL.charAt(i) + oddChars;
}
}
let data = (evenChars + oddChars).split('');
for (let i = 0; i < data.length; i += 1) {
if (isDigit(data[i])) {
for (let ii = i + 1; ii < data.length; ii += 1) {
if (isDigit(data[ii])) {
// eslint-disable-next-line no-bitwise
const temp = parseInt(data[i], 10) ^ parseInt(data[ii], 10);
if (temp < 10) {
data[i] = temp.toString();
}
i = ii;
break;
}
}
}
}
data = data.join('');
const decodedURL = window.atob(data).slice(16, -16);
if (window.stop) {
window.stop();
}
window.onbeforeunload = null;
window.location.href = decodedURL;
};
let val;
// Do not apply handler more than one time
let applyHandler = true;
const result = setPropertyAccess(window, 'ysmm', {
configurable: false,
set: (value) => {
if (applyHandler) {
applyHandler = false;
try {
if (typeof value === 'string') {
handler(value);
}
} catch (err) { } // eslint-disable-line no-empty
}
val = value;
},
get: () => val,
});
if (result) {
hit(source);
} else {
logMessage(source, 'Failed to set up prevent-adfly scriptlet');
}
}
export const preventAdflyNames = [
'prevent-adfly',
// there are no aliases for this scriptlet
];
// eslint-disable-next-line prefer-destructuring
preventAdfly.primaryName = preventAdflyNames[0];
preventAdfly.injections = [
setPropertyAccess,
hit,
logMessage,
];