@tokioapp/adblock 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -2
  3. package/THIRD_PARTY_NOTICES.md +50 -0
  4. package/dist/content/cosmetics.d.ts +22 -0
  5. package/dist/content/cosmetics.js +173 -0
  6. package/dist/content/mainWorld.d.ts +8 -0
  7. package/dist/content/mainWorld.js +10 -0
  8. package/dist/content/preload.d.ts +1 -0
  9. package/dist/content/preload.js +34 -0
  10. package/dist/content/procedural.d.ts +19 -0
  11. package/dist/content/procedural.js +212 -0
  12. package/dist/cosmetic/engine.d.ts +95 -0
  13. package/dist/cosmetic/engine.js +268 -0
  14. package/dist/electron/blocker.d.ts +84 -0
  15. package/dist/electron/blocker.js +320 -0
  16. package/dist/electron/channels.d.ts +10 -0
  17. package/dist/electron/channels.js +6 -0
  18. package/dist/electron/scheme.d.ts +21 -0
  19. package/dist/electron/scheme.js +21 -0
  20. package/dist/engine.d.ts +86 -0
  21. package/dist/engine.js +163 -0
  22. package/dist/index.d.ts +13 -0
  23. package/dist/index.js +12 -0
  24. package/dist/lists/defaults.d.ts +6 -0
  25. package/dist/lists/defaults.js +59 -0
  26. package/dist/lists/manager.d.ts +86 -0
  27. package/dist/lists/manager.js +154 -0
  28. package/dist/lists/preprocessor.d.ts +21 -0
  29. package/dist/lists/preprocessor.js +152 -0
  30. package/dist/lists/storage.d.ts +37 -0
  31. package/dist/lists/storage.js +66 -0
  32. package/dist/network/engine.d.ts +105 -0
  33. package/dist/network/engine.js +431 -0
  34. package/dist/network/filterIndex.d.ts +40 -0
  35. package/dist/network/filterIndex.js +343 -0
  36. package/dist/network/modifiers.d.ts +23 -0
  37. package/dist/network/modifiers.js +192 -0
  38. package/dist/network/pattern.d.ts +7 -0
  39. package/dist/network/pattern.js +145 -0
  40. package/dist/network/request.d.ts +50 -0
  41. package/dist/network/request.js +136 -0
  42. package/dist/network/tokens.d.ts +5 -0
  43. package/dist/network/tokens.js +150 -0
  44. package/dist/parser/cosmetic.d.ts +21 -0
  45. package/dist/parser/cosmetic.js +171 -0
  46. package/dist/parser/hosts.d.ts +20 -0
  47. package/dist/parser/hosts.js +143 -0
  48. package/dist/parser/index.d.ts +40 -0
  49. package/dist/parser/index.js +158 -0
  50. package/dist/parser/network.d.ts +6 -0
  51. package/dist/parser/network.js +474 -0
  52. package/dist/parser/selector.d.ts +25 -0
  53. package/dist/parser/selector.js +522 -0
  54. package/dist/parser/types.d.ts +175 -0
  55. package/dist/parser/types.js +75 -0
  56. package/dist/preload.cjs +1988 -0
  57. package/dist/psl/psl.d.ts +32 -0
  58. package/dist/psl/psl.js +119 -0
  59. package/dist/resources/binary.d.ts +9 -0
  60. package/dist/resources/binary.js +54 -0
  61. package/dist/resources/defusers.d.ts +29 -0
  62. package/dist/resources/defusers.js +180 -0
  63. package/dist/resources/documents.d.ts +12 -0
  64. package/dist/resources/documents.js +56 -0
  65. package/dist/resources/ima.d.ts +6 -0
  66. package/dist/resources/ima.js +313 -0
  67. package/dist/resources/index.d.ts +14 -0
  68. package/dist/resources/index.js +85 -0
  69. package/dist/resources/surrogates.d.ts +30 -0
  70. package/dist/resources/surrogates.js +486 -0
  71. package/dist/scriptlets/abort.d.ts +5 -0
  72. package/dist/scriptlets/abort.js +97 -0
  73. package/dist/scriptlets/dom/attributes.d.ts +5 -0
  74. package/dist/scriptlets/dom/attributes.js +92 -0
  75. package/dist/scriptlets/dom/click.d.ts +2 -0
  76. package/dist/scriptlets/dom/click.js +107 -0
  77. package/dist/scriptlets/dom/cookies.d.ts +16 -0
  78. package/dist/scriptlets/dom/cookies.js +194 -0
  79. package/dist/scriptlets/dom/createHtml.d.ts +2 -0
  80. package/dist/scriptlets/dom/createHtml.js +27 -0
  81. package/dist/scriptlets/dom/dialogs.d.ts +3 -0
  82. package/dist/scriptlets/dom/dialogs.js +21 -0
  83. package/dist/scriptlets/dom/hrefSanitizer.d.ts +2 -0
  84. package/dist/scriptlets/dom/hrefSanitizer.js +91 -0
  85. package/dist/scriptlets/dom/index.d.ts +3 -0
  86. package/dist/scriptlets/dom/index.js +38 -0
  87. package/dist/scriptlets/dom/navigation.d.ts +5 -0
  88. package/dist/scriptlets/dom/navigation.js +60 -0
  89. package/dist/scriptlets/dom/nodeText.d.ts +3 -0
  90. package/dist/scriptlets/dom/nodeText.js +98 -0
  91. package/dist/scriptlets/dom/spoofCss.d.ts +2 -0
  92. package/dist/scriptlets/dom/spoofCss.js +58 -0
  93. package/dist/scriptlets/dom/storage.d.ts +5 -0
  94. package/dist/scriptlets/dom/storage.js +50 -0
  95. package/dist/scriptlets/dom/watch.d.ts +8 -0
  96. package/dist/scriptlets/dom/watch.js +41 -0
  97. package/dist/scriptlets/events.d.ts +2 -0
  98. package/dist/scriptlets/events.js +42 -0
  99. package/dist/scriptlets/helpers.d.ts +58 -0
  100. package/dist/scriptlets/helpers.js +206 -0
  101. package/dist/scriptlets/index.d.ts +6 -0
  102. package/dist/scriptlets/index.js +47 -0
  103. package/dist/scriptlets/network/edit.d.ts +9 -0
  104. package/dist/scriptlets/network/edit.js +104 -0
  105. package/dist/scriptlets/network/eval.d.ts +3 -0
  106. package/dist/scriptlets/network/eval.js +22 -0
  107. package/dist/scriptlets/network/fetch.d.ts +10 -0
  108. package/dist/scriptlets/network/fetch.js +145 -0
  109. package/dist/scriptlets/network/index.d.ts +3 -0
  110. package/dist/scriptlets/network/index.js +43 -0
  111. package/dist/scriptlets/network/jsonPath.d.ts +13 -0
  112. package/dist/scriptlets/network/jsonPath.js +482 -0
  113. package/dist/scriptlets/network/media.d.ts +3 -0
  114. package/dist/scriptlets/network/media.js +97 -0
  115. package/dist/scriptlets/network/methods.d.ts +5 -0
  116. package/dist/scriptlets/network/methods.js +139 -0
  117. package/dist/scriptlets/network/prune.d.ts +13 -0
  118. package/dist/scriptlets/network/prune.js +194 -0
  119. package/dist/scriptlets/network/rendering.d.ts +4 -0
  120. package/dist/scriptlets/network/rendering.js +46 -0
  121. package/dist/scriptlets/network/replace.d.ts +5 -0
  122. package/dist/scriptlets/network/replace.js +168 -0
  123. package/dist/scriptlets/network/request.d.ts +19 -0
  124. package/dist/scriptlets/network/request.js +124 -0
  125. package/dist/scriptlets/network/util.d.ts +19 -0
  126. package/dist/scriptlets/network/util.js +80 -0
  127. package/dist/scriptlets/network/webrtc.d.ts +3 -0
  128. package/dist/scriptlets/network/webrtc.js +62 -0
  129. package/dist/scriptlets/network/windowOpen.d.ts +2 -0
  130. package/dist/scriptlets/network/windowOpen.js +28 -0
  131. package/dist/scriptlets/network/xhr.d.ts +9 -0
  132. package/dist/scriptlets/network/xhr.js +177 -0
  133. package/dist/scriptlets/runner.d.ts +8 -0
  134. package/dist/scriptlets/runner.js +19 -0
  135. package/dist/scriptlets/setConstant.d.ts +5 -0
  136. package/dist/scriptlets/setConstant.js +117 -0
  137. package/dist/scriptlets/timers.d.ts +5 -0
  138. package/dist/scriptlets/timers.js +66 -0
  139. package/dist/scriptlets/types.d.ts +32 -0
  140. package/dist/scriptlets/types.js +1 -0
  141. package/dist/util.d.ts +5 -0
  142. package/dist/util.js +16 -0
  143. package/package.json +83 -4
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Tells where a hostname's registrable domain starts, from Mozilla's Public
3
+ * Suffix List (<https://publicsuffix.org>): the request `a.example.co.uk` is
4
+ * first-party to `b.example.co.uk`, and `example.*` means `example.co.uk`.
5
+ * The list is data the host's machine downloads; without it the class guesses.
6
+ */
7
+ export declare class PublicSuffixList {
8
+ private readonly exact;
9
+ private readonly wildcard;
10
+ private readonly exception;
11
+ private readonly domains;
12
+ /** `text` is the content of `public_suffix_list.dat`, when there is one. */
13
+ constructor(text?: string);
14
+ /** Whether the real list was given, or the class is guessing. */
15
+ get loaded(): boolean;
16
+ /**
17
+ * The public suffix of a hostname (`co.uk` for `www.example.co.uk`). Empty
18
+ * for an IP address.
19
+ */
20
+ publicSuffix(hostname: string): string;
21
+ /**
22
+ * The registrable domain (`example.co.uk`), or the hostname itself when it
23
+ * has none: an IP address, a public suffix, `localhost`.
24
+ */
25
+ domain(hostname: string): string;
26
+ /**
27
+ * The hostname with its public suffix replaced by `*` (`www.example.*`),
28
+ * which `example.*` in a filter is compared with. Empty when the hostname
29
+ * has no name before its suffix.
30
+ */
31
+ entity(hostname: string): string;
32
+ }
@@ -0,0 +1,119 @@
1
+ import { domainToASCII } from "node:url";
2
+ const IP = /^(?:\d{1,3}\.){3}\d{1,3}$|^\[/;
3
+ // eslint-disable-next-line no-control-regex
4
+ const NON_ASCII = /[^\x00-\x7f]/;
5
+ // Without the list: second-level names that country domains commonly sell
6
+ // under (`example.co.uk`). A guess, used until the real list is downloaded.
7
+ const COMMON_SECOND_LEVEL = new Set([
8
+ "ac",
9
+ "co",
10
+ "com",
11
+ "edu",
12
+ "gov",
13
+ "mil",
14
+ "ne",
15
+ "net",
16
+ "nom",
17
+ "or",
18
+ "org",
19
+ ]);
20
+ const CACHE_SIZE = 8192;
21
+ /**
22
+ * Tells where a hostname's registrable domain starts, from Mozilla's Public
23
+ * Suffix List (<https://publicsuffix.org>): the request `a.example.co.uk` is
24
+ * first-party to `b.example.co.uk`, and `example.*` means `example.co.uk`.
25
+ * The list is data the host's machine downloads; without it the class guesses.
26
+ */
27
+ export class PublicSuffixList {
28
+ exact = new Set();
29
+ wildcard = new Set();
30
+ exception = new Set();
31
+ domains = new Map();
32
+ /** `text` is the content of `public_suffix_list.dat`, when there is one. */
33
+ constructor(text = "") {
34
+ for (let line of text.split(/\r?\n/)) {
35
+ // A rule ends at the first whitespace; `//` starts a comment.
36
+ line = line.trim().split(/\s/)[0].toLowerCase();
37
+ if (line === "" || line.startsWith("//"))
38
+ continue;
39
+ const set = line.startsWith("!")
40
+ ? this.exception
41
+ : line.startsWith("*.")
42
+ ? this.wildcard
43
+ : this.exact;
44
+ if (set !== this.exact)
45
+ line = line.slice(line.startsWith("!") ? 1 : 2);
46
+ // Request hostnames are punycode.
47
+ set.add(NON_ASCII.test(line) ? domainToASCII(line) : line);
48
+ }
49
+ }
50
+ /** Whether the real list was given, or the class is guessing. */
51
+ get loaded() {
52
+ return this.exact.size > 0;
53
+ }
54
+ /**
55
+ * The public suffix of a hostname (`co.uk` for `www.example.co.uk`). Empty
56
+ * for an IP address.
57
+ */
58
+ publicSuffix(hostname) {
59
+ if (IP.test(hostname))
60
+ return "";
61
+ if (!this.loaded) {
62
+ const labels = hostname.split(".");
63
+ const last = labels.at(-1);
64
+ return labels.length > 2 &&
65
+ last.length === 2 &&
66
+ COMMON_SECOND_LEVEL.has(labels.at(-2))
67
+ ? `${labels.at(-2)}.${last}`
68
+ : last;
69
+ }
70
+ // From the whole hostname down: the first rule to match is the longest.
71
+ let start = 0;
72
+ for (;;) {
73
+ const suffix = start === 0 ? hostname : hostname.slice(start);
74
+ const dot = hostname.indexOf(".", start);
75
+ if (this.exception.has(suffix)) {
76
+ return dot === -1 ? "" : hostname.slice(dot + 1);
77
+ }
78
+ if (this.exact.has(suffix))
79
+ return suffix;
80
+ if (dot === -1)
81
+ return suffix;
82
+ if (this.wildcard.has(hostname.slice(dot + 1)))
83
+ return suffix;
84
+ start = dot + 1;
85
+ }
86
+ }
87
+ /**
88
+ * The registrable domain (`example.co.uk`), or the hostname itself when it
89
+ * has none: an IP address, a public suffix, `localhost`.
90
+ */
91
+ domain(hostname) {
92
+ let domain = this.domains.get(hostname);
93
+ if (domain !== undefined)
94
+ return domain;
95
+ const suffix = this.publicSuffix(hostname);
96
+ if (suffix === "" || suffix.length >= hostname.length) {
97
+ domain = hostname;
98
+ }
99
+ else {
100
+ const before = hostname.length - suffix.length - 1;
101
+ domain = hostname.slice(hostname.lastIndexOf(".", before - 1) + 1);
102
+ }
103
+ if (this.domains.size >= CACHE_SIZE)
104
+ this.domains.clear();
105
+ this.domains.set(hostname, domain);
106
+ return domain;
107
+ }
108
+ /**
109
+ * The hostname with its public suffix replaced by `*` (`www.example.*`),
110
+ * which `example.*` in a filter is compared with. Empty when the hostname
111
+ * has no name before its suffix.
112
+ */
113
+ entity(hostname) {
114
+ const suffix = this.publicSuffix(hostname);
115
+ if (suffix === "" || suffix.length >= hostname.length)
116
+ return "";
117
+ return `${hostname.slice(0, hostname.length - suffix.length)}*`;
118
+ }
119
+ }
@@ -0,0 +1,9 @@
1
+ /** A 1x1 transparent GIF89a: 43 bytes. */
2
+ export declare function gif(): Uint8Array;
3
+ /** A transparent PNG: 8-bit RGBA, every pixel 0. */
4
+ export declare function png(width: number, height: number): Uint8Array;
5
+ /**
6
+ * A silent MP3 of about `seconds`: frames whose side information and data
7
+ * are all zero, so every granule decodes to silence.
8
+ */
9
+ export declare function mp3(seconds: number): Uint8Array;
@@ -0,0 +1,54 @@
1
+ // The image and sound resources, built from their format specifications.
2
+ import { crc32, deflateSync } from "node:zlib";
3
+ /** A 1x1 transparent GIF89a: 43 bytes. */
4
+ export function gif() {
5
+ return Uint8Array.of(...[0x47, 0x49, 0x46, 0x38, 0x39, 0x61], // "GIF89a"
6
+ // Logical screen: 1x1, a global color table of 2 colors, background 0.
7
+ ...[1, 0, 1, 0, 0x80, 0, 0], ...[0, 0, 0, 0xff, 0xff, 0xff],
8
+ // Graphic control extension: color 0 is transparent.
9
+ ...[0x21, 0xf9, 4, 1, 0, 0, 0, 0],
10
+ // Image descriptor: 1x1 at 0,0, no local color table.
11
+ ...[0x2c, 0, 0, 0, 0, 1, 0, 1, 0, 0],
12
+ // LZW, minimum code size 2: the 3-bit codes clear (4), 0, end (5),
13
+ // packed from the low bit up, in one 2-byte sub-block.
14
+ ...[2, 2, 0x44, 0x01, 0], 0x3b);
15
+ }
16
+ function chunk(type, data) {
17
+ const out = Buffer.alloc(12 + data.length);
18
+ out.writeUInt32BE(data.length, 0);
19
+ out.write(type, 4, "latin1");
20
+ out.set(data, 8);
21
+ out.writeUInt32BE(crc32(out.subarray(4, 8 + data.length)), 8 + data.length);
22
+ return out;
23
+ }
24
+ /** A transparent PNG: 8-bit RGBA, every pixel 0. */
25
+ export function png(width, height) {
26
+ const header = Buffer.alloc(13);
27
+ header.writeUInt32BE(width, 0);
28
+ header.writeUInt32BE(height, 4);
29
+ header.set([8, 6, 0, 0, 0], 8); // depth 8, RGBA, deflate, no filter, no interlace
30
+ // Each row is a filter byte (0, none) and its pixels, all zero.
31
+ const pixels = Buffer.alloc(height * (1 + width * 4));
32
+ return Buffer.concat([
33
+ Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
34
+ chunk("IHDR", header),
35
+ chunk("IDAT", deflateSync(pixels)),
36
+ chunk("IEND", new Uint8Array()),
37
+ ]);
38
+ }
39
+ // MPEG-1 Layer III, 32 kbit/s, 48 kHz, mono, no CRC: every frame is
40
+ // 144 * 32000 / 48000 = 96 bytes and lasts 1152 / 48000 = 24 ms.
41
+ const FRAME_BYTES = 96;
42
+ const FRAME_SECONDS = 0.024;
43
+ /**
44
+ * A silent MP3 of about `seconds`: frames whose side information and data
45
+ * are all zero, so every granule decodes to silence.
46
+ */
47
+ export function mp3(seconds) {
48
+ const frames = Math.round(seconds / FRAME_SECONDS);
49
+ const out = new Uint8Array(frames * FRAME_BYTES);
50
+ for (let i = 0; i < frames; i++) {
51
+ out.set([0xff, 0xfb, 0x14, 0xc0], i * FRAME_BYTES);
52
+ }
53
+ return out;
54
+ }
@@ -0,0 +1,29 @@
1
+ /** FuckAdBlock 3.2, BlockAdBlock and SniffAdBlock, always "not detected". */
2
+ export declare function nofab(): void;
3
+ /**
4
+ * BlockAdblock: refuses `eval()` of code that names it, which its payloads
5
+ * do once decoded, and lets every other `eval()` through.
6
+ */
7
+ export declare function nobab(): void;
8
+ /**
9
+ * BlockAdblock 4.2b: the same guard as `nobab`, on `eval()` and on code
10
+ * made with `Function()`.
11
+ */
12
+ export declare function nobab2(): void;
13
+ /** PopAds: aborts the script that sets `PopAds` or `popns`. */
14
+ export declare function popads(): void;
15
+ /** PopAds: `PopAds` and `popns` are there, as fixed empty objects. */
16
+ export declare function popadsDummy(): void;
17
+ /** FingerprintJS 2: the same meaningless fingerprint for everyone. */
18
+ export declare function fingerprint2(): void;
19
+ /** FingerprintJS 3: an agent whose visitor id is the same for everyone. */
20
+ export declare function fingerprint3(): void;
21
+ /** The bait script sites host as `prebid-ads.js`: ads can run. */
22
+ export declare function prebidAds(): void;
23
+ /**
24
+ * AMP: its boilerplate keeps the body hidden by an 8-second `-amp-start`
25
+ * animation, which the AMP runtime cancels once it loads. Cancels it.
26
+ */
27
+ export declare function ampprojectV0(): void;
28
+ /** Resources that also work as scriptlets: name → the self-contained function. */
29
+ export declare const DEFUSERS: Readonly<Record<string, () => void>>;
@@ -0,0 +1,180 @@
1
+ // Resources that also work as scriptlets. Each function runs in a page on
2
+ // its own, as a redirected script or a scriptlet: it imports nothing and
3
+ // uses nothing from outside its body but the page's globals. This file
4
+ // imports nothing either, so the scriptlet bundle can take it as is.
5
+ /** FuckAdBlock 3.2, BlockAdBlock and SniffAdBlock, always "not detected". */
6
+ export function nofab() {
7
+ const w = window;
8
+ const Detector = function () { };
9
+ const later = (fn) => {
10
+ if (typeof fn === "function")
11
+ setTimeout(fn, 1);
12
+ };
13
+ const notDetected = [];
14
+ Object.assign(Detector.prototype, {
15
+ setOption() {
16
+ return this;
17
+ },
18
+ check() {
19
+ notDetected.forEach(later);
20
+ return true;
21
+ },
22
+ emitEvent() {
23
+ return this;
24
+ },
25
+ clearEvent() { },
26
+ on(detected, fn) {
27
+ if (!detected) {
28
+ notDetected.push(fn);
29
+ later(fn);
30
+ }
31
+ return this;
32
+ },
33
+ onDetected() {
34
+ return this;
35
+ },
36
+ onNotDetected(fn) {
37
+ return this.on(false, fn);
38
+ },
39
+ });
40
+ const instance = new Detector();
41
+ for (const name of ["FuckAdBlock", "BlockAdBlock", "SniffAdBlock"]) {
42
+ const lower = name[0].toLowerCase() + name.slice(1);
43
+ for (const [key, value] of [
44
+ [name, Detector],
45
+ [lower, instance],
46
+ ]) {
47
+ try {
48
+ // The detector's own script may still run: its writes are ignored.
49
+ Object.defineProperty(w, key, {
50
+ configurable: true,
51
+ get: () => value,
52
+ set() { },
53
+ });
54
+ }
55
+ catch { }
56
+ }
57
+ }
58
+ }
59
+ /**
60
+ * BlockAdblock: refuses `eval()` of code that names it, which its payloads
61
+ * do once decoded, and lets every other `eval()` through.
62
+ */
63
+ export function nobab() {
64
+ const original = window.eval;
65
+ window.eval = new Proxy(original, {
66
+ apply(target, self, args) {
67
+ const code = args[0];
68
+ return typeof code === "string" && /blockadblock/i.test(code)
69
+ ? undefined
70
+ : Reflect.apply(target, self, args);
71
+ },
72
+ });
73
+ }
74
+ /**
75
+ * BlockAdblock 4.2b: the same guard as `nobab`, on `eval()` and on code
76
+ * made with `Function()`.
77
+ */
78
+ export function nobab2() {
79
+ const w = window;
80
+ const blocked = (args) => args.some((arg) => typeof arg === "string" && /blockadblock/i.test(arg));
81
+ w.eval = new Proxy(w.eval, {
82
+ apply: (target, self, args) => blocked(args) ? undefined : Reflect.apply(target, self, args),
83
+ });
84
+ w.Function = new Proxy(w.Function, {
85
+ apply: (target, self, args) => blocked(args) ? () => { } : Reflect.apply(target, self, args),
86
+ construct: (target, args, newTarget) => blocked(args) ? () => { } : Reflect.construct(target, args, newTarget),
87
+ });
88
+ }
89
+ /** PopAds: aborts the script that sets `PopAds` or `popns`. */
90
+ export function popads() {
91
+ for (const key of ["PopAds", "popns"]) {
92
+ try {
93
+ Object.defineProperty(window, key, {
94
+ configurable: true,
95
+ get: () => undefined,
96
+ set() {
97
+ throw new ReferenceError("magic");
98
+ },
99
+ });
100
+ }
101
+ catch { }
102
+ }
103
+ }
104
+ /** PopAds: `PopAds` and `popns` are there, as fixed empty objects. */
105
+ export function popadsDummy() {
106
+ for (const key of ["PopAds", "popns"]) {
107
+ try {
108
+ Object.defineProperty(window, key, {
109
+ configurable: true,
110
+ value: Object.freeze({}),
111
+ writable: false,
112
+ });
113
+ }
114
+ catch { }
115
+ }
116
+ }
117
+ /** FingerprintJS 2: the same meaningless fingerprint for everyone. */
118
+ export function fingerprint2() {
119
+ const hash = "00000000000000000000000000000000";
120
+ const later = (fn, ...args) => {
121
+ if (typeof fn === "function")
122
+ setTimeout(() => fn(...args), 1);
123
+ };
124
+ const Fingerprint2 = function () { };
125
+ // Version 1's API: `new Fingerprint2().get((hash, components) => …)`.
126
+ Fingerprint2.prototype.get = (fn) => later(fn, hash, []);
127
+ Fingerprint2.get = (options, fn) => later(typeof options === "function" ? options : fn, []);
128
+ Fingerprint2.getPromise = () => Promise.resolve([]);
129
+ Fingerprint2.getV18 = (options, fn) => later(typeof options === "function" ? options : fn, hash, []);
130
+ Fingerprint2.x64hash128 = () => hash;
131
+ Fingerprint2.VERSION = "2.1.0";
132
+ window.Fingerprint2 = Fingerprint2;
133
+ }
134
+ /** FingerprintJS 3: an agent whose visitor id is the same for everyone. */
135
+ export function fingerprint3() {
136
+ const hash = "00000000000000000000000000000000";
137
+ const result = {
138
+ visitorId: hash,
139
+ confidence: { score: 0 },
140
+ components: {},
141
+ version: "3.4.2",
142
+ };
143
+ window.FingerprintJS = {
144
+ load: () => Promise.resolve({ get: () => Promise.resolve(result) }),
145
+ hashComponents: () => hash,
146
+ componentsToDebugString: () => "{}",
147
+ };
148
+ }
149
+ /** The bait script sites host as `prebid-ads.js`: ads can run. */
150
+ export function prebidAds() {
151
+ const w = window;
152
+ w.canRunAds = true;
153
+ w.isAdBlockActive = false;
154
+ }
155
+ /**
156
+ * AMP: its boilerplate keeps the body hidden by an 8-second `-amp-start`
157
+ * animation, which the AMP runtime cancels once it loads. Cancels it.
158
+ */
159
+ export function ampprojectV0() {
160
+ const id = "tokio-amp-start";
161
+ if (document.getElementById(id) !== null)
162
+ return;
163
+ const style = document.createElement("style");
164
+ style.id = id;
165
+ style.textContent =
166
+ "body { animation: none !important; -webkit-animation: none !important; }";
167
+ (document.head ?? document.documentElement).append(style);
168
+ }
169
+ /** Resources that also work as scriptlets: name → the self-contained function. */
170
+ export const DEFUSERS = {
171
+ nobab,
172
+ nobab2,
173
+ nofab,
174
+ popads,
175
+ "popads-dummy": popadsDummy,
176
+ fingerprint2,
177
+ fingerprint3,
178
+ "prebid-ads": prebidAds,
179
+ ampproject_v0: ampprojectV0,
180
+ };
@@ -0,0 +1,12 @@
1
+ /** A VAST response with no ads, which players read as "nothing to play". */
2
+ export declare const vast: (version: "2.0" | "3.0" | "4.0") => string;
3
+ /** A VMAP 1.0 playlist with no ad breaks. */
4
+ export declare const VMAP = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<vmap:VMAP xmlns:vmap=\"http://www.iab.net/videosuite/vmap\" version=\"1.0\"/>\n";
5
+ export declare const NOOP_HTML = "<!doctype html><html><head></head><body></body></html>\n";
6
+ /**
7
+ * What a blocked frame shows instead: its original address, a link that
8
+ * opens it in a new tab, and a click anywhere else loads it in the frame.
9
+ * The address comes in the query, `click2load.html?url=<encodeURIComponent
10
+ * (original)>`; anything but an http(s) address shows nothing to load.
11
+ */
12
+ export declare const CLICK2LOAD = "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Blocked frame</title>\n<style>\nhtml, body { height: 100%; margin: 0; }\nbody { display: flex; align-items: center; justify-content: center; box-sizing: border-box; padding: 8px;\n font: 13px/1.4 system-ui, sans-serif; color: #333; background: #f2f2f2; cursor: pointer; }\nmain { max-width: 100%; text-align: center; }\np { margin: 0 0 6px; }\ncode { display: block; overflow-wrap: anywhere; user-select: all; cursor: text; color: #555; }\na { color: inherit; }\n</style>\n</head>\n<body>\n<main>\n<p>This frame was blocked. Click to load it.</p>\n<code id=\"url\"></code>\n<p><a id=\"open\" target=\"_blank\" rel=\"noopener noreferrer\">Open in a new tab</a></p>\n</main>\n<script>\n(function () {\n var url = new URLSearchParams(location.search).get(\"url\") || \"\";\n if (!/^https?:\\/\\//i.test(url)) {\n document.querySelector(\"main\").textContent = \"This frame was blocked.\";\n document.body.style.cursor = \"default\";\n return;\n }\n document.getElementById(\"url\").textContent = url;\n document.getElementById(\"open\").href = url;\n document.body.addEventListener(\"click\", function (event) {\n if (event.target.closest(\"a, code\")) return;\n location.replace(url);\n });\n})();\n</script>\n</body>\n</html>\n";
@@ -0,0 +1,56 @@
1
+ // The HTML and XML resources.
2
+ const XML = '<?xml version="1.0" encoding="UTF-8"?>\n';
3
+ /** A VAST response with no ads, which players read as "nothing to play". */
4
+ export const vast = (version) => version === "4.0"
5
+ ? `${XML}<VAST version="4.0" xmlns="http://www.iab.com/VAST"/>\n`
6
+ : `${XML}<VAST version="${version}"/>\n`;
7
+ /** A VMAP 1.0 playlist with no ad breaks. */
8
+ export const VMAP = `${XML}<vmap:VMAP xmlns:vmap="http://www.iab.net/videosuite/vmap" version="1.0"/>\n`;
9
+ export const NOOP_HTML = "<!doctype html><html><head></head><body></body></html>\n";
10
+ /**
11
+ * What a blocked frame shows instead: its original address, a link that
12
+ * opens it in a new tab, and a click anywhere else loads it in the frame.
13
+ * The address comes in the query, `click2load.html?url=<encodeURIComponent
14
+ * (original)>`; anything but an http(s) address shows nothing to load.
15
+ */
16
+ export const CLICK2LOAD = `<!doctype html>
17
+ <html lang="en">
18
+ <head>
19
+ <meta charset="utf-8">
20
+ <meta name="viewport" content="width=device-width, initial-scale=1">
21
+ <title>Blocked frame</title>
22
+ <style>
23
+ html, body { height: 100%; margin: 0; }
24
+ body { display: flex; align-items: center; justify-content: center; box-sizing: border-box; padding: 8px;
25
+ font: 13px/1.4 system-ui, sans-serif; color: #333; background: #f2f2f2; cursor: pointer; }
26
+ main { max-width: 100%; text-align: center; }
27
+ p { margin: 0 0 6px; }
28
+ code { display: block; overflow-wrap: anywhere; user-select: all; cursor: text; color: #555; }
29
+ a { color: inherit; }
30
+ </style>
31
+ </head>
32
+ <body>
33
+ <main>
34
+ <p>This frame was blocked. Click to load it.</p>
35
+ <code id="url"></code>
36
+ <p><a id="open" target="_blank" rel="noopener noreferrer">Open in a new tab</a></p>
37
+ </main>
38
+ <script>
39
+ (function () {
40
+ var url = new URLSearchParams(location.search).get("url") || "";
41
+ if (!/^https?:\\/\\//i.test(url)) {
42
+ document.querySelector("main").textContent = "This frame was blocked.";
43
+ document.body.style.cursor = "default";
44
+ return;
45
+ }
46
+ document.getElementById("url").textContent = url;
47
+ document.getElementById("open").href = url;
48
+ document.body.addEventListener("click", function (event) {
49
+ if (event.target.closest("a, code")) return;
50
+ location.replace(url);
51
+ });
52
+ })();
53
+ </script>
54
+ </body>
55
+ </html>
56
+ `;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The IMA SDK for HTML5 (`google.ima`), from its public reference: every
3
+ * ad request fails with "VAST empty response", so players play the content.
4
+ * Runs in pages on its own: no imports, nothing from outside its body.
5
+ */
6
+ export declare function googleIma(): void;