forked from AdguardTeam/Scriptlets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir-string.js
More file actions
55 lines (51 loc) · 1.54 KB
/
dir-string.js
File metadata and controls
55 lines (51 loc) · 1.54 KB
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
import { hit } from '../helpers/index';
/* eslint-disable max-len */
/**
* @scriptlet dir-string
*
* @description
* Wraps the `console.dir` API to call the `toString` method of the argument.
* There are several adblock circumvention systems that detect browser devtools
* and hide themselves. Therefore, if we force them to think
* that devtools are open (using this scriptlet),
* it will automatically disable the adblock circumvention script.
*
* Related ABP source:
* https://github.com/adblockplus/adblockpluscore/blob/6b2a309054cc23432102b85d13f12559639ef495/lib/content/snippets.js#L766
*
* **Syntax**
* ```
* example.org#%#//scriptlet('dir-string'[, times])
* ```
* - `times` - optional, the number of times to call the `toString` method of the argument to `console.dir`
*
* **Example**
* ```
* ! Run 2 times
* example.org#%#//scriptlet('dir-string', '2')
* ```
*/
/* eslint-enable max-len */
export function dirString(source, times) {
const { dir } = console;
times = parseInt(times, 10);
function dirWrapper(object) {
// eslint-disable-next-line no-unused-vars
let temp;
for (let i = 0; i < times; i += 1) {
// eslint-disable-next-line no-unused-expressions
temp = `${object}`;
}
if (typeof dir === 'function') {
dir.call(this, object);
}
hit(source, temp);
}
// eslint-disable-next-line no-console
console.dir = dirWrapper;
}
dirString.names = [
'dir-string',
'abp-dir-string',
];
dirString.injections = [hit];