@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,486 @@
1
+ // Stand-ins for ad and analytics scripts: the public API of the script each
2
+ // replaces, doing nothing, so that pages which call it keep working. Each
3
+ // function runs in a page on its own: no imports, nothing from outside its
4
+ // body but the page's globals.
5
+ /** Google Publisher Tag (`googletag`): every slot renders empty. */
6
+ export function googletagServices() {
7
+ const w = window;
8
+ const tag = typeof w.googletag === "object" && w.googletag ? w.googletag : {};
9
+ if (tag.apiReady === true)
10
+ return;
11
+ w.googletag = tag;
12
+ // Methods documented to return their own object, for chained calls.
13
+ const chain = (target, names) => {
14
+ for (const name of names.split(" "))
15
+ target[name] = () => target;
16
+ return target;
17
+ };
18
+ const slots = [];
19
+ const listeners = [];
20
+ let initialLoad = true;
21
+ const service = (name) => {
22
+ const created = {
23
+ addEventListener(type, listener) {
24
+ listeners.push([`${name} ${type}`, listener]);
25
+ return created;
26
+ },
27
+ removeEventListener(type, listener) {
28
+ const index = listeners.findIndex(([key, fn]) => key === `${name} ${type}` && fn === listener);
29
+ if (index !== -1)
30
+ listeners.splice(index, 1);
31
+ return index !== -1;
32
+ },
33
+ getSlots: () => slots.slice(),
34
+ };
35
+ return created;
36
+ };
37
+ const render = (targets) => setTimeout(() => {
38
+ for (const slot of targets) {
39
+ const event = {
40
+ serviceName: "publisher_ads",
41
+ slot,
42
+ isEmpty: true,
43
+ size: null,
44
+ advertiserId: null,
45
+ campaignId: null,
46
+ creativeId: null,
47
+ lineItemId: null,
48
+ isBackfill: false,
49
+ slotContentChanged: false,
50
+ };
51
+ for (const [key, listener] of listeners.slice()) {
52
+ if (key === "publisher_ads slotRenderEnded")
53
+ listener(event);
54
+ }
55
+ }
56
+ }, 0);
57
+ const pubads = chain(Object.assign(service("publisher_ads"), {
58
+ clear: () => true,
59
+ collapseEmptyDivs: () => true,
60
+ disableInitialLoad() {
61
+ initialLoad = false;
62
+ },
63
+ display() { },
64
+ enableLazyLoad() { },
65
+ enableSingleRequest: () => true,
66
+ enableVideoAds() { },
67
+ get: () => null,
68
+ getAttributeKeys: () => [],
69
+ getTargeting: () => [],
70
+ getTargetingKeys: () => [],
71
+ isInitialLoadDisabled: () => !initialLoad,
72
+ refresh: (targets) => render(Array.isArray(targets) ? targets : slots),
73
+ registerRequestHook: () => () => { },
74
+ setCentering() { },
75
+ setVideoContent() { },
76
+ }), "clearCategoryExclusions clearTargeting set setCategoryExclusion setForceSafeFrame setLocation setPrivacySettings setPublisherProvidedId setSafeFrameConfig setTargeting updateCorrelator");
77
+ const companionAds = Object.assign(service("companion_ads"), {
78
+ setRefreshUnfilledSlots() { },
79
+ });
80
+ const content = Object.assign(service("content"), { setContent() { } });
81
+ const slot = (path, id) => {
82
+ const created = chain({
83
+ get: () => null,
84
+ getAdUnitPath: () => path,
85
+ getAttributeKeys: () => [],
86
+ getCategoryExclusions: () => [],
87
+ getConfig: () => ({}),
88
+ getResponseInformation: () => null,
89
+ getSlotElementId: () => id,
90
+ getSizes: () => [],
91
+ getTargeting: () => [],
92
+ getTargetingKeys: () => [],
93
+ }, "addService clearCategoryExclusions clearTargeting defineSizeMapping set setCategoryExclusion setClickUrl setCollapseEmptyDiv setConfig setForceSafeFrame setSafeFrameConfig setTargeting updateTargetingFromMap");
94
+ slots.push(created);
95
+ return created;
96
+ };
97
+ Object.assign(tag, {
98
+ apiReady: true,
99
+ pubadsReady: true,
100
+ companionAds: () => companionAds,
101
+ content: () => content,
102
+ defineOutOfPageSlot: (path, id) => slot(path, typeof id === "string" ? id : ""),
103
+ defineSlot: (path, _size, id) => slot(path, id),
104
+ destroySlots(targets) {
105
+ const removed = Array.isArray(targets) ? targets : slots.slice();
106
+ for (const target of removed) {
107
+ const index = slots.indexOf(target);
108
+ if (index !== -1)
109
+ slots.splice(index, 1);
110
+ }
111
+ return true;
112
+ },
113
+ disablePublisherConsole() { },
114
+ display(target) {
115
+ if (!initialLoad)
116
+ return;
117
+ render(slots.filter((each) => each === target || each.getSlotElementId() === target));
118
+ },
119
+ enableServices() { },
120
+ getConfig: () => ({}),
121
+ getVersion: () => "",
122
+ openConsole() { },
123
+ pubads: () => pubads,
124
+ setAdIframeTitle() { },
125
+ setConfig() { },
126
+ sizeMapping() {
127
+ const builder = { addSize: () => builder, build: () => [] };
128
+ return builder;
129
+ },
130
+ // Values aren't documented: pages pass them back as they are.
131
+ enums: {
132
+ OutOfPageFormat: {
133
+ BOTTOM_ANCHOR: 3,
134
+ GAME_MANUAL_INTERSTITIAL: 7,
135
+ INTERSTITIAL: 5,
136
+ LEFT_SIDE_RAIL: 8,
137
+ REWARDED: 4,
138
+ RIGHT_SIDE_RAIL: 9,
139
+ TOP_ANCHOR: 2,
140
+ },
141
+ TrafficSource: { ORGANIC: 0, PURCHASED: 1 },
142
+ },
143
+ });
144
+ if (!Array.isArray(tag.secureSignalProviders))
145
+ tag.secureSignalProviders = [];
146
+ let processed = 0;
147
+ const queued = Array.isArray(tag.cmd) ? tag.cmd : [];
148
+ tag.cmd = {
149
+ push(...commands) {
150
+ for (const command of commands) {
151
+ if (typeof command !== "function")
152
+ continue;
153
+ processed++;
154
+ try {
155
+ command.call(tag);
156
+ }
157
+ catch (error) {
158
+ setTimeout(() => {
159
+ throw error;
160
+ });
161
+ }
162
+ }
163
+ return processed;
164
+ },
165
+ };
166
+ tag.cmd.push(...queued);
167
+ }
168
+ /** Google Tag Manager: `dataLayer` pushes get their `eventCallback` called. */
169
+ export function googletagManager() {
170
+ const w = window;
171
+ const layer = Array.isArray(w.dataLayer) ? w.dataLayer : [];
172
+ w.dataLayer = layer;
173
+ const later = (fn) => {
174
+ if (typeof fn === "function")
175
+ setTimeout(fn, 0);
176
+ };
177
+ // An object pushed directly, or the `arguments` of `gtag(…, { event_callback })`.
178
+ const answer = (item) => {
179
+ if (typeof item !== "object" || item === null)
180
+ return;
181
+ later(item.eventCallback);
182
+ later(item[2]?.event_callback);
183
+ };
184
+ if (!layer.tokioProcessed) {
185
+ Object.defineProperty(layer, "tokioProcessed", { value: true });
186
+ layer.forEach(answer);
187
+ }
188
+ const push = Array.prototype.push;
189
+ layer.push = function (...items) {
190
+ items.forEach(answer);
191
+ return push.apply(this, items);
192
+ };
193
+ const container = {
194
+ dataLayer: { get: () => undefined, set() { }, reset() { } },
195
+ };
196
+ if (w.google_tag_manager === undefined) {
197
+ w.google_tag_manager = new Proxy({}, {
198
+ get: (_target, key) => typeof key === "string" && /^[A-Z]{1,3}-/.test(key)
199
+ ? container
200
+ : undefined,
201
+ });
202
+ }
203
+ }
204
+ /** Google Analytics `analytics.js` (`ga`): commands are dropped, callbacks called. */
205
+ export function googleAnalytics() {
206
+ const w = window;
207
+ const name = typeof w.GoogleAnalyticsObject === "string"
208
+ ? w.GoogleAnalyticsObject
209
+ : "ga";
210
+ const existing = w[name];
211
+ if (existing?.loaded === true)
212
+ return;
213
+ const later = (fn, ...args) => {
214
+ if (typeof fn === "function")
215
+ setTimeout(() => fn(...args), 0);
216
+ };
217
+ const callBack = (args) => {
218
+ for (const arg of args) {
219
+ if (typeof arg === "object" && arg !== null)
220
+ later(arg.hitCallback);
221
+ }
222
+ };
223
+ const trackers = new Map();
224
+ const tracker = (trackerName) => {
225
+ const created = {
226
+ get: () => undefined,
227
+ set() { },
228
+ send: (...args) => callBack(args),
229
+ };
230
+ trackers.set(trackerName, created);
231
+ return created;
232
+ };
233
+ const ga = function (command, ...args) {
234
+ if (typeof command === "function") {
235
+ later(command, trackers.get("t0") ?? tracker("t0"));
236
+ }
237
+ else {
238
+ callBack(args);
239
+ }
240
+ };
241
+ Object.assign(ga, {
242
+ create: (...args) => {
243
+ const named = args.find((arg) => typeof arg?.name === "string");
244
+ const trackerName = (typeof args[2] === "string" ? args[2] : named?.name) ?? "t0";
245
+ return tracker(trackerName);
246
+ },
247
+ getByName: (trackerName) => trackers.get(trackerName) ?? null,
248
+ getAll: () => [...trackers.values()],
249
+ remove: (trackerName) => trackers.delete(trackerName),
250
+ loaded: true,
251
+ });
252
+ w[name] = ga;
253
+ w.GoogleAnalyticsObject = name;
254
+ if (Array.isArray(existing?.q)) {
255
+ for (const queued of existing.q)
256
+ ga(...Array.from(queued));
257
+ }
258
+ }
259
+ /** Google Analytics `ga.js` (`_gaq`, `_gat`): trackers whose methods do nothing. */
260
+ export function googleAnalyticsGa() {
261
+ const w = window;
262
+ if (w._gat?._getTracker !== undefined)
263
+ return;
264
+ const noop = () => { };
265
+ const tracker = new Proxy({
266
+ _getAccount: () => "",
267
+ _getLinkerUrl: (url) => url,
268
+ _getName: () => "",
269
+ _getVersion: () => "",
270
+ _getVisitorCustomVar: () => undefined,
271
+ }, {
272
+ get: (target, key) => key in target
273
+ ? target[key]
274
+ : typeof key === "string" && key.startsWith("_")
275
+ ? noop
276
+ : undefined,
277
+ });
278
+ w._gat = {
279
+ _anonymizeIp: noop,
280
+ _createTracker: () => tracker,
281
+ _forceSSL: noop,
282
+ _getTracker: () => tracker,
283
+ _getTrackerByName: () => tracker,
284
+ };
285
+ const queued = Array.isArray(w._gaq) ? w._gaq : [];
286
+ w._gaq = {
287
+ _createAsyncTracker: () => tracker,
288
+ _getAsyncTracker: () => tracker,
289
+ push(...commands) {
290
+ for (const command of commands) {
291
+ if (typeof command === "function") {
292
+ try {
293
+ command.call(w._gat);
294
+ }
295
+ catch { }
296
+ }
297
+ else if (Array.isArray(command) &&
298
+ /(^|\.)_set$/.test(command[0]) &&
299
+ command[1] === "hitCallback" &&
300
+ typeof command[2] === "function") {
301
+ const callback = command[2];
302
+ setTimeout(() => callback(), 0);
303
+ }
304
+ }
305
+ return 0;
306
+ },
307
+ };
308
+ w._gaq.push(...queued);
309
+ }
310
+ /** Google Analytics Content Experiments (`cxApi`): always the original. */
311
+ export function googleAnalyticsCxApi() {
312
+ const noop = () => { };
313
+ window.cxApi = {
314
+ ORIGINAL_VARIATION: 0,
315
+ NO_CHOSEN_VARIATION: -1,
316
+ NOT_PARTICIPATING: -2,
317
+ chooseVariation: () => 0,
318
+ getChosenVariation: () => -1,
319
+ setAllowHash: noop,
320
+ setChosenVariation: noop,
321
+ setCookiePath: noop,
322
+ setDomainName: noop,
323
+ };
324
+ }
325
+ /** AdSense (`adsbygoogle`): every ad unit is marked as done and unfilled. */
326
+ export function googlesyndicationAdsbygoogle() {
327
+ const w = window;
328
+ const queue = Array.isArray(w.adsbygoogle) ? w.adsbygoogle : [];
329
+ w.adsbygoogle = queue;
330
+ const fill = () => {
331
+ const unit = document.querySelector("ins.adsbygoogle:not([data-adsbygoogle-status])");
332
+ unit?.setAttribute("data-adsbygoogle-status", "done");
333
+ unit?.setAttribute("data-ad-status", "unfilled");
334
+ };
335
+ const page = (item) => typeof item === "object" &&
336
+ item !== null &&
337
+ ("google_ad_client" in item || "enable_page_level_ads" in item);
338
+ if (queue.loaded !== true) {
339
+ for (const item of queue)
340
+ if (!page(item))
341
+ fill();
342
+ }
343
+ queue.loaded = true;
344
+ const push = Array.prototype.push;
345
+ queue.push = function (...items) {
346
+ for (const item of items)
347
+ if (!page(item))
348
+ fill();
349
+ return push.apply(this, items);
350
+ };
351
+ }
352
+ /** Amazon Publisher Services (`apstag`): bid requests come back empty. */
353
+ export function amazonApstag() {
354
+ const w = window;
355
+ const queued = Array.isArray(w.apstag?._Q) ? w.apstag._Q : [];
356
+ const fetchBids = (_config, callback) => {
357
+ if (typeof callback === "function")
358
+ setTimeout(() => callback([]), 0);
359
+ };
360
+ const withCallback = (_config, callback) => {
361
+ if (typeof callback === "function")
362
+ setTimeout(callback, 0);
363
+ };
364
+ w.apstag = {
365
+ _Q: [],
366
+ init() { },
367
+ fetchBids,
368
+ setDisplayBids() { },
369
+ targetingKeys: () => [],
370
+ renderImp() { },
371
+ dpa: withCallback,
372
+ rpa: withCallback,
373
+ upa: withCallback,
374
+ };
375
+ for (const [kind, args] of queued) {
376
+ if (kind === "f")
377
+ fetchBids(...Array.from(args));
378
+ }
379
+ }
380
+ /** Amazon's older `amzn_ads.js` (`amznads`): no ads, callbacks called. */
381
+ export function amazonAds() {
382
+ const w = window;
383
+ const noop = () => { };
384
+ const later = (fn) => {
385
+ if (typeof fn === "function")
386
+ setTimeout(fn, 0);
387
+ };
388
+ later(w.amznads?.asyncParams?.callbackFn);
389
+ w.amznads = {
390
+ getAds: noop,
391
+ getAdsCallback: (_id, callback) => later(callback),
392
+ getKeys: () => [],
393
+ getTokens: () => [],
394
+ hasAds: () => false,
395
+ renderAd: noop,
396
+ setTargetingForGPTAsync: noop,
397
+ setTargetingForGPTSync: noop,
398
+ };
399
+ }
400
+ /** comScore (`COMSCORE`, `_comscore`): beacons go nowhere. */
401
+ export function scorecardresearchBeacon() {
402
+ const w = window;
403
+ w.COMSCORE = { beacon() { } };
404
+ w._comscore = [];
405
+ }
406
+ /** Outbrain (`OBR`): widgets never load. */
407
+ export function outbrainWidget() {
408
+ const w = window;
409
+ const noop = () => { };
410
+ w.OBR = {
411
+ extern: { refreshWidget: noop, reloadWidget: noop, researchWidget: noop },
412
+ };
413
+ w.OB_releaseVer = "0";
414
+ }
415
+ /** Chartbeat (`pSUPERFLY`). */
416
+ export function chartbeat() {
417
+ window.pSUPERFLY = { activity() { }, virtualPage() { } };
418
+ }
419
+ /** Ligatus: its ad block detection flags. */
420
+ export function ligatusAngularTag() {
421
+ const w = window;
422
+ for (const key of ["adProtect", "uabpdl", "uabDetect"]) {
423
+ try {
424
+ Object.defineProperty(w, key, { configurable: true, value: true });
425
+ }
426
+ catch { }
427
+ }
428
+ }
429
+ /** AddThis (`addthis`): share buttons that do nothing. */
430
+ export function addthisWidget() {
431
+ const w = window;
432
+ const noop = () => { };
433
+ const layers = Object.assign(noop.bind(null), { refresh: noop });
434
+ w.addthis = {
435
+ addEventListener: noop,
436
+ button: noop,
437
+ counter: noop,
438
+ init: noop,
439
+ layers,
440
+ removeEventListener: noop,
441
+ share: noop,
442
+ toolbox: noop,
443
+ update: noop,
444
+ };
445
+ }
446
+ /** Google's ad status check for IMA: ads can play. */
447
+ export function doubleclickInstreamAdStatus() {
448
+ window.google_ad_status = 1;
449
+ }
450
+ /** The Sensors Analytics web SDK (`sensors`): events go nowhere. */
451
+ export function sensorsAnalytics() {
452
+ const w = window;
453
+ const name = typeof w.sensorsDataAnalytic201505 === "string"
454
+ ? w.sensorsDataAnalytic201505
455
+ : "sensors";
456
+ const noop = () => { };
457
+ const call = (...args) => {
458
+ const callback = args.at(-1);
459
+ if (typeof callback === "function")
460
+ setTimeout(callback, 0);
461
+ };
462
+ w[name] = {
463
+ para: {},
464
+ appendProfile: noop,
465
+ bind: noop,
466
+ deleteItem: noop,
467
+ deleteProfile: noop,
468
+ getAnonymousID: () => "",
469
+ getPresetProperties: () => ({}),
470
+ identify: noop,
471
+ incrementProfile: noop,
472
+ init: noop,
473
+ login: noop,
474
+ logout: noop,
475
+ quick: call,
476
+ register: noop,
477
+ registerPage: noop,
478
+ setItem: noop,
479
+ setOnceProfile: noop,
480
+ setProfile: noop,
481
+ track: call,
482
+ unbind: noop,
483
+ unsetProfile: noop,
484
+ use: noop,
485
+ };
486
+ }
@@ -0,0 +1,5 @@
1
+ import type { Scriptlet } from "./types.js";
2
+ export declare const abortOnPropertyRead: Scriptlet;
3
+ export declare const abortOnPropertyWrite: Scriptlet;
4
+ export declare const abortCurrentScript: Scriptlet;
5
+ export declare const abortOnStackTrace: Scriptlet;
@@ -0,0 +1,97 @@
1
+ import { abort, matcher, onChain, stackMatches, trap } from "./helpers.js";
2
+ export const abortOnPropertyRead = {
3
+ name: "abort-on-property-read",
4
+ aliases: ["aopr"],
5
+ run(chain = "") {
6
+ if (chain === "")
7
+ return;
8
+ onChain(window, chain, (owner, property) => {
9
+ // Writes go through: only reading the property aborts the script.
10
+ trap(owner, property, { get: abort });
11
+ });
12
+ },
13
+ };
14
+ export const abortOnPropertyWrite = {
15
+ name: "abort-on-property-write",
16
+ aliases: ["aopw"],
17
+ run(chain = "") {
18
+ if (chain === "")
19
+ return;
20
+ onChain(window, chain, (owner, property) => {
21
+ trap(owner, property, { set: abort });
22
+ });
23
+ },
24
+ };
25
+ /** The script a `data:` URL holds, or empty. */
26
+ function dataUrlText(src) {
27
+ const match = /^data:[^,]*?(;base64)?,(.*)$/s.exec(src);
28
+ if (match === null)
29
+ return "";
30
+ try {
31
+ return match[1] === undefined
32
+ ? decodeURIComponent(match[2])
33
+ : atob(match[2]);
34
+ }
35
+ catch {
36
+ return "";
37
+ }
38
+ }
39
+ export const abortCurrentScript = {
40
+ name: "abort-current-script",
41
+ aliases: ["acs", "abort-current-inline-script", "acis"],
42
+ run(chain = "", needle = "", srcNeedle = "") {
43
+ if (chain === "")
44
+ return;
45
+ const textMatches = matcher(needle);
46
+ const srcMatches = matcher(srcNeedle);
47
+ // Abort when the script that touches the property is the one the filter
48
+ // describes, by its text or by the script its `data:` URL holds.
49
+ const check = () => {
50
+ const script = document.currentScript;
51
+ if (!(script instanceof HTMLScriptElement))
52
+ return;
53
+ if (needle !== "" && !textMatches(script.textContent ?? ""))
54
+ return;
55
+ if (srcNeedle !== "" && !srcMatches(dataUrlText(script.src)))
56
+ return;
57
+ abort();
58
+ };
59
+ onChain(window, chain, (owner, property) => {
60
+ trap(owner, property, {
61
+ get(value) {
62
+ check();
63
+ return value;
64
+ },
65
+ set(next) {
66
+ check();
67
+ return next;
68
+ },
69
+ });
70
+ });
71
+ },
72
+ };
73
+ export const abortOnStackTrace = {
74
+ name: "abort-on-stack-trace",
75
+ aliases: ["aost"],
76
+ run(chain = "", needle = "") {
77
+ // Without a needle the scriptlet only logs, and there is no logger.
78
+ if (chain === "" || needle === "")
79
+ return;
80
+ const check = () => {
81
+ if (stackMatches(needle))
82
+ abort();
83
+ };
84
+ onChain(window, chain, (owner, property) => {
85
+ trap(owner, property, {
86
+ get(value) {
87
+ check();
88
+ return value;
89
+ },
90
+ set(next) {
91
+ check();
92
+ return next;
93
+ },
94
+ });
95
+ });
96
+ },
97
+ };
@@ -0,0 +1,5 @@
1
+ import type { Scriptlet } from "../types.js";
2
+ export declare const removeAttr: Scriptlet;
3
+ export declare const removeClass: Scriptlet;
4
+ export declare const setAttrScriptlet: Scriptlet;
5
+ export declare const trustedSetAttr: Scriptlet;
@@ -0,0 +1,92 @@
1
+ import { runAt } from "../helpers.js";
2
+ import { watch } from "./watch.js";
3
+ /**
4
+ * What `remove-attr` and `remove-class` share: act once the document is
5
+ * interactive (or `complete`, or now with `asap`), and keep at it with
6
+ * `stay`. `behavior` is their space-separated third argument.
7
+ */
8
+ function cleanUp(selector, behavior, clean, watched) {
9
+ const words = behavior.split(/\s+/);
10
+ const start = () => {
11
+ const observer = watch(selector, clean, watched);
12
+ if (!words.includes("stay"))
13
+ observer?.disconnect();
14
+ };
15
+ if (words.includes("asap"))
16
+ start();
17
+ else
18
+ runAt(words.includes("complete") ? "complete" : "interactive", start);
19
+ }
20
+ function names(list) {
21
+ return list
22
+ .split("|")
23
+ .map((name) => name.trim())
24
+ .filter((name) => name !== "");
25
+ }
26
+ export const removeAttr = {
27
+ name: "remove-attr",
28
+ aliases: ["ra"],
29
+ run(list = "", selector = "", behavior = "") {
30
+ const attributes = names(list);
31
+ if (attributes.length === 0)
32
+ return;
33
+ cleanUp(selector || attributes.map((name) => `[${name}]`).join(","), behavior, (element) => {
34
+ for (const name of attributes)
35
+ element.removeAttribute(name);
36
+ }, attributes);
37
+ },
38
+ };
39
+ export const removeClass = {
40
+ name: "remove-class",
41
+ aliases: ["rc"],
42
+ run(list = "", selector = "", behavior = "") {
43
+ const classes = names(list);
44
+ if (classes.length === 0)
45
+ return;
46
+ cleanUp(selector || classes.map((name) => `.${name}`).join(","), behavior, (element) => {
47
+ // `classList.remove` writes the attribute even when nothing goes,
48
+ // which the observer would see as a change, forever.
49
+ for (const name of classes) {
50
+ if (element.classList.contains(name))
51
+ element.classList.remove(name);
52
+ }
53
+ }, ["class"]);
54
+ },
55
+ };
56
+ function setAttr(selector = "", attribute = "", value, watched) {
57
+ if (selector === "" || attribute === "")
58
+ return;
59
+ watch(selector, (element) => {
60
+ const next = value(element);
61
+ if (next !== null && element.getAttribute(attribute) !== next) {
62
+ element.setAttribute(attribute, next);
63
+ }
64
+ }, [attribute, ...watched]);
65
+ }
66
+ export const setAttrScriptlet = {
67
+ name: "set-attr",
68
+ run(selector, attribute = "", text = "") {
69
+ // Copying a value into an event handler would run the page's text.
70
+ if (/^on/i.test(attribute))
71
+ return;
72
+ const copied = /^\[([^\]]+)\]$/.exec(text)?.[1];
73
+ if (copied !== undefined) {
74
+ setAttr(selector, attribute, (element) => element.getAttribute(copied), [
75
+ copied,
76
+ ]);
77
+ return;
78
+ }
79
+ const value = text === "''" ? "" : text;
80
+ if (value === "" ||
81
+ value === "true" ||
82
+ value === "false" ||
83
+ (/^\d+$/.test(value) && Number(value) < 32768)) {
84
+ setAttr(selector, attribute, () => value, []);
85
+ }
86
+ },
87
+ };
88
+ export const trustedSetAttr = {
89
+ name: "trusted-set-attr",
90
+ trusted: true,
91
+ run: (selector, attribute, text = "") => setAttr(selector, attribute, () => text, []),
92
+ };
@@ -0,0 +1,2 @@
1
+ import type { Scriptlet } from "../types.js";
2
+ export declare const trustedClickElement: Scriptlet;