@browserless.io/browserless 2.34.0 → 2.34.1

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 (183) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/extensions/ublocklite/README.md +1 -1
  3. package/extensions/ublocklite/_locales/bs/messages.json +58 -58
  4. package/extensions/ublocklite/_locales/ro/messages.json +1 -1
  5. package/extensions/ublocklite/_locales/sr/messages.json +28 -28
  6. package/extensions/ublocklite/css/unpicker-ui.css +1 -0
  7. package/extensions/ublocklite/js/background.js +5 -3
  8. package/extensions/ublocklite/js/fetch.js +1 -1
  9. package/extensions/ublocklite/js/filter-manager.js +45 -9
  10. package/extensions/ublocklite/js/ruleset-manager.js +5 -5
  11. package/extensions/ublocklite/js/scripting/css-procedural.js +2 -0
  12. package/extensions/ublocklite/js/scripting/css-specific.js +2 -0
  13. package/extensions/ublocklite/js/scripting-manager.js +2 -2
  14. package/extensions/ublocklite/js/static-filtering-parser.js +17 -10
  15. package/extensions/ublocklite/manifest.json +2 -2
  16. package/extensions/ublocklite/rulesets/generic-details.json +1 -1
  17. package/extensions/ublocklite/rulesets/main/adguard-mobile.json +1 -1
  18. package/extensions/ublocklite/rulesets/main/annoyances-cookies.json +6 -5
  19. package/extensions/ublocklite/rulesets/main/annoyances-others.json +2 -1
  20. package/extensions/ublocklite/rulesets/main/chn-0.json +12 -8
  21. package/extensions/ublocklite/rulesets/main/deu-0.json +5 -7
  22. package/extensions/ublocklite/rulesets/main/dpollock-0.json +2 -0
  23. package/extensions/ublocklite/rulesets/main/easylist.json +13 -71
  24. package/extensions/ublocklite/rulesets/main/easyprivacy.json +20 -8
  25. package/extensions/ublocklite/rulesets/main/fra-0.json +2 -0
  26. package/extensions/ublocklite/rulesets/main/ind-0.json +10 -7
  27. package/extensions/ublocklite/rulesets/main/irn-0.json +1 -4
  28. package/extensions/ublocklite/rulesets/main/jpn-1.json +12 -12
  29. package/extensions/ublocklite/rulesets/main/kor-1.json +3 -1
  30. package/extensions/ublocklite/rulesets/main/nor-0.json +1 -1
  31. package/extensions/ublocklite/rulesets/main/pgl.json +1 -3
  32. package/extensions/ublocklite/rulesets/main/pol-0.json +1 -2
  33. package/extensions/ublocklite/rulesets/main/rus-0.json +4 -4
  34. package/extensions/ublocklite/rulesets/main/rus-1.json +3 -1
  35. package/extensions/ublocklite/rulesets/main/spa-1.json +6 -2
  36. package/extensions/ublocklite/rulesets/main/stevenblack-hosts.json +2966 -2308
  37. package/extensions/ublocklite/rulesets/main/swe-1.json +17 -14
  38. package/extensions/ublocklite/rulesets/main/tur-0.json +11 -3
  39. package/extensions/ublocklite/rulesets/main/ublock-badware.json +5 -6
  40. package/extensions/ublocklite/rulesets/main/ublock-filters.json +32 -20
  41. package/extensions/ublocklite/rulesets/main/ubol-tests.json +17 -0
  42. package/extensions/ublocklite/rulesets/main/urlhaus-full.json +230 -164
  43. package/extensions/ublocklite/rulesets/main/vie-1.json +22 -16
  44. package/extensions/ublocklite/rulesets/modify-headers/rus-0.json +0 -1
  45. package/extensions/ublocklite/rulesets/modify-headers/ublock-filters.json +3 -2
  46. package/extensions/ublocklite/rulesets/redirect/annoyances-overlays.json +1 -1
  47. package/extensions/ublocklite/rulesets/redirect/jpn-1.json +0 -1
  48. package/extensions/ublocklite/rulesets/redirect/ublock-filters.json +15 -23
  49. package/extensions/ublocklite/rulesets/redirect/vie-1.json +34 -2
  50. package/extensions/ublocklite/rulesets/regex/chn-0.json +3 -1
  51. package/extensions/ublocklite/rulesets/regex/easylist.json +0 -2
  52. package/extensions/ublocklite/rulesets/regex/jpn-1.json +1 -1
  53. package/extensions/ublocklite/rulesets/regex/ublock-filters.json +4 -5
  54. package/extensions/ublocklite/rulesets/removeparam/adguard-spyware-url.json +4 -4
  55. package/extensions/ublocklite/rulesets/removeparam/rus-1.json +1 -0
  56. package/extensions/ublocklite/rulesets/removeparam/ublock-filters.json +2 -1
  57. package/extensions/ublocklite/rulesets/ruleset-details.json +151 -151
  58. package/extensions/ublocklite/rulesets/scripting/generic/chn-0.js +1 -1
  59. package/extensions/ublocklite/rulesets/scripting/generic/deu-0.js +2 -2
  60. package/extensions/ublocklite/rulesets/scripting/generic/easylist.js +3 -3
  61. package/extensions/ublocklite/rulesets/scripting/generic/idn-0.js +1 -1
  62. package/extensions/ublocklite/rulesets/scripting/generic/jpn-1.js +2 -2
  63. package/extensions/ublocklite/rulesets/scripting/generic/ublock-filters.js +3 -3
  64. package/extensions/ublocklite/rulesets/scripting/generichigh/easylist.css +1 -12
  65. package/extensions/ublocklite/rulesets/scripting/generichigh/idn-0.css +3 -0
  66. package/extensions/ublocklite/rulesets/scripting/generichigh/rus-0.css +1 -0
  67. package/extensions/ublocklite/rulesets/scripting/procedural/adguard-mobile.js +3 -3
  68. package/extensions/ublocklite/rulesets/scripting/procedural/annoyances-notifications.js +1 -1
  69. package/extensions/ublocklite/rulesets/scripting/procedural/annoyances-others.js +3 -3
  70. package/extensions/ublocklite/rulesets/scripting/procedural/annoyances-overlays.js +3 -3
  71. package/extensions/ublocklite/rulesets/scripting/procedural/annoyances-social.js +3 -3
  72. package/extensions/ublocklite/rulesets/scripting/procedural/chn-0.js +3 -3
  73. package/extensions/ublocklite/rulesets/scripting/procedural/easylist.js +3 -3
  74. package/extensions/ublocklite/rulesets/scripting/procedural/irn-0.js +3 -3
  75. package/extensions/ublocklite/rulesets/scripting/procedural/jpn-1.js +3 -3
  76. package/extensions/ublocklite/rulesets/scripting/procedural/rus-0.js +3 -3
  77. package/extensions/ublocklite/rulesets/scripting/procedural/swe-1.js +1 -1
  78. package/extensions/ublocklite/rulesets/scripting/procedural/tur-0.js +3 -3
  79. package/extensions/ublocklite/rulesets/scripting/procedural/ublock-filters.js +3 -3
  80. package/extensions/ublocklite/rulesets/scripting/scriptlet/adguard-mobile.set-cookie-reload.js +1 -1
  81. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-cookies.set-cookie.js +2 -2
  82. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-cookies.set-local-storage-item.js +2 -2
  83. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-cookies.trusted-click-element.js +1 -1
  84. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-cookies.trusted-set-cookie.js +2 -2
  85. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-overlays.addEventListener-defuser.js +2 -2
  86. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-overlays.prevent-setTimeout.js +2 -2
  87. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-overlays.set-constant.js +1 -1
  88. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-overlays.set-cookie.js +2 -2
  89. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-overlays.trusted-click-element.js +1 -1
  90. package/extensions/ublocklite/rulesets/scripting/scriptlet/annoyances-overlays.trusted-replace-outbound-text.js +427 -0
  91. package/extensions/ublocklite/rulesets/scripting/scriptlet/chn-0.abort-current-script.js +2 -2
  92. package/extensions/ublocklite/rulesets/scripting/scriptlet/chn-0.json-prune-fetch-response.js +588 -0
  93. package/extensions/ublocklite/rulesets/scripting/scriptlet/irn-0.prevent-window-open.js +1 -1
  94. package/extensions/ublocklite/rulesets/scripting/scriptlet/irn-0.remove-node-text.js +2 -2
  95. package/extensions/ublocklite/rulesets/scripting/scriptlet/jpn-1.abort-current-script.js +2 -2
  96. package/extensions/ublocklite/rulesets/scripting/scriptlet/rus-0.abort-on-property-write.js +2 -2
  97. package/extensions/ublocklite/rulesets/scripting/scriptlet/rus-0.addEventListener-defuser.js +3 -3
  98. package/extensions/ublocklite/rulesets/scripting/scriptlet/spa-1.abort-on-property-read.js +2 -2
  99. package/extensions/ublocklite/rulesets/scripting/scriptlet/spa-1.addEventListener-defuser.js +2 -2
  100. package/extensions/ublocklite/rulesets/scripting/scriptlet/spa-1.prevent-fetch.js +1 -1
  101. package/extensions/ublocklite/rulesets/scripting/scriptlet/spa-1.prevent-window-open.js +1 -1
  102. package/extensions/ublocklite/rulesets/scripting/scriptlet/spa-1.set-constant.js +2 -2
  103. package/extensions/ublocklite/rulesets/scripting/scriptlet/tur-0.abort-on-property-read.js +1 -1
  104. package/extensions/ublocklite/rulesets/scripting/scriptlet/tur-0.addEventListener-defuser.js +2 -2
  105. package/extensions/ublocklite/rulesets/scripting/scriptlet/tur-0.adjust-setInterval.js +2 -2
  106. package/extensions/ublocklite/rulesets/scripting/scriptlet/tur-0.prevent-window-open.js +1 -1
  107. package/extensions/ublocklite/rulesets/scripting/scriptlet/tur-0.set-constant.js +2 -2
  108. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.abort-current-script.js +3 -3
  109. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.abort-on-property-read.js +1 -1
  110. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.abort-on-stack-trace.js +2 -2
  111. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.addEventListener-defuser.js +3 -3
  112. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.adjust-setInterval.js +3 -3
  113. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.adjust-setTimeout.js +2 -2
  114. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.json-edit-fetch-response.js +927 -0
  115. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.json-prune-fetch-response.js +2 -2
  116. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.json-prune.js +2 -2
  117. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.noeval-if.js +3 -3
  118. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.prevent-fetch.js +3 -3
  119. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.prevent-window-open.js +3 -3
  120. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.prevent-xhr.js +2 -2
  121. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.remove-cookie.js +2 -2
  122. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.remove-node-text.js +2 -2
  123. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.set-constant.js +3 -3
  124. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.set-cookie.js +1 -1
  125. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.set-local-storage-item.js +2 -2
  126. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.trusted-replace-argument.js +2 -2
  127. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.trusted-replace-node-text.js +3 -3
  128. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.trusted-replace-outbound-text.js +2 -2
  129. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.trusted-set-constant.js +2 -2
  130. package/extensions/ublocklite/rulesets/scripting/scriptlet/ublock-filters.trusted-set-local-storage-item.js +1 -1
  131. package/extensions/ublocklite/rulesets/scripting/scriptlet/vie-1.abort-current-script.js +2 -2
  132. package/extensions/ublocklite/rulesets/scripting/scriptlet/vie-1.abort-on-property-read.js +2 -2
  133. package/extensions/ublocklite/rulesets/scripting/specific/adguard-mobile.js +3 -3
  134. package/extensions/ublocklite/rulesets/scripting/specific/annoyances-cookies.js +3 -3
  135. package/extensions/ublocklite/rulesets/scripting/specific/annoyances-notifications.js +3 -3
  136. package/extensions/ublocklite/rulesets/scripting/specific/annoyances-others.js +3 -3
  137. package/extensions/ublocklite/rulesets/scripting/specific/annoyances-overlays.js +3 -3
  138. package/extensions/ublocklite/rulesets/scripting/specific/annoyances-social.js +3 -3
  139. package/extensions/ublocklite/rulesets/scripting/specific/chn-0.js +3 -3
  140. package/extensions/ublocklite/rulesets/scripting/specific/deu-0.js +3 -3
  141. package/extensions/ublocklite/rulesets/scripting/specific/easylist.js +3 -3
  142. package/extensions/ublocklite/rulesets/scripting/specific/fra-0.js +3 -3
  143. package/extensions/ublocklite/rulesets/scripting/specific/hun-0.js +1 -1
  144. package/extensions/ublocklite/rulesets/scripting/specific/idn-0.js +3 -3
  145. package/extensions/ublocklite/rulesets/scripting/specific/ind-0.js +3 -3
  146. package/extensions/ublocklite/rulesets/scripting/specific/irn-0.js +3 -3
  147. package/extensions/ublocklite/rulesets/scripting/specific/isr-0.js +3 -3
  148. package/extensions/ublocklite/rulesets/scripting/specific/ita-0.js +3 -3
  149. package/extensions/ublocklite/rulesets/scripting/specific/jpn-1.js +3 -3
  150. package/extensions/ublocklite/rulesets/scripting/specific/kor-1.js +2 -2
  151. package/extensions/ublocklite/rulesets/scripting/specific/nld-0.js +1 -1
  152. package/extensions/ublocklite/rulesets/scripting/specific/nor-0.js +1 -1
  153. package/extensions/ublocklite/rulesets/scripting/specific/pol-0.js +3 -3
  154. package/extensions/ublocklite/rulesets/scripting/specific/rus-0.js +3 -3
  155. package/extensions/ublocklite/rulesets/scripting/specific/spa-1.js +3 -3
  156. package/extensions/ublocklite/rulesets/scripting/specific/swe-1.js +3 -3
  157. package/extensions/ublocklite/rulesets/scripting/specific/tur-0.js +3 -3
  158. package/extensions/ublocklite/rulesets/scripting/specific/ublock-filters.js +3 -3
  159. package/extensions/ublocklite/rulesets/scripting/specific/ukr-0.js +3 -3
  160. package/extensions/ublocklite/rulesets/scripting/specific/vie-1.js +3 -3
  161. package/extensions/ublocklite/rulesets/scriptlet-details.json +63 -32
  162. package/extensions/ublocklite/rulesets/strictblock/adguard-mobile.json +9 -0
  163. package/extensions/ublocklite/rulesets/strictblock/chn-0.json +69 -0
  164. package/extensions/ublocklite/rulesets/strictblock/dpollock-0.json +2 -0
  165. package/extensions/ublocklite/rulesets/strictblock/easylist.json +1 -1
  166. package/extensions/ublocklite/rulesets/strictblock/easyprivacy.json +14 -70
  167. package/extensions/ublocklite/rulesets/strictblock/jpn-1.json +176 -174
  168. package/extensions/ublocklite/rulesets/strictblock/nor-0.json +1 -1
  169. package/extensions/ublocklite/rulesets/strictblock/pgl.json +1 -3
  170. package/extensions/ublocklite/rulesets/strictblock/pol-0.json +1 -0
  171. package/extensions/ublocklite/rulesets/strictblock/spa-1.json +1 -0
  172. package/extensions/ublocklite/rulesets/strictblock/stevenblack-hosts.json +2966 -2308
  173. package/extensions/ublocklite/rulesets/strictblock/ublock-badware.json +486 -484
  174. package/extensions/ublocklite/rulesets/strictblock/ublock-filters.json +1 -1
  175. package/extensions/ublocklite/rulesets/strictblock/urlhaus-full.json +230 -164
  176. package/extensions/ublocklite/rulesets/strictblock/vie-1.json +1 -1
  177. package/extensions/ublocklite/ublock.zip +0 -0
  178. package/package.json +7 -7
  179. package/scripts/build-open-api.js +15 -1
  180. package/static/docs/swagger.json +2 -2
  181. package/static/docs/swagger.min.json +1 -1
  182. package/static/function/client.js +71 -68
  183. package/static/function/index.html +71 -68
@@ -0,0 +1,927 @@
1
+ /*******************************************************************************
2
+
3
+ uBlock Origin Lite - a comprehensive, MV3-compliant content blocker
4
+ Copyright (C) 2014-present Raymond Hill
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program. If not, see {http://www.gnu.org/licenses/}.
18
+
19
+ Home: https://github.com/gorhill/uBlock
20
+
21
+ */
22
+
23
+ // ruleset: ublock-filters
24
+
25
+ // Important!
26
+ // Isolate from global scope
27
+
28
+ // Start of local scope
29
+ (function uBOL_jsonEditFetchResponse() {
30
+
31
+ /******************************************************************************/
32
+
33
+ function jsonEditFetchResponse(jsonq = '', ...args) {
34
+ jsonEditFetchResponseFn(false, jsonq, ...args);
35
+ }
36
+
37
+ function jsonEditFetchResponseFn(trusted, jsonq = '') {
38
+ const safe = safeSelf();
39
+ const logPrefix = safe.makeLogPrefix(
40
+ `${trusted ? 'trusted-' : ''}json-edit-fetch-response`,
41
+ jsonq
42
+ );
43
+ const jsonp = JSONPath.create(jsonq);
44
+ if ( jsonp.valid === false || jsonp.value !== undefined && trusted !== true ) {
45
+ return safe.uboLog(logPrefix, 'Bad JSONPath query');
46
+ }
47
+ const extraArgs = safe.getExtraArgs(Array.from(arguments), 2);
48
+ const propNeedles = parsePropertiesToMatchFn(extraArgs.propsToMatch, 'url');
49
+ proxyApplyFn('fetch', function(context) {
50
+ const args = context.callArgs;
51
+ const fetchPromise = context.reflect();
52
+ if ( propNeedles.size !== 0 ) {
53
+ const objs = [ args[0] instanceof Object ? args[0] : { url: args[0] } ];
54
+ if ( objs[0] instanceof Request ) {
55
+ try {
56
+ objs[0] = safe.Request_clone.call(objs[0]);
57
+ } catch(ex) {
58
+ safe.uboErr(logPrefix, 'Error:', ex);
59
+ }
60
+ }
61
+ if ( args[1] instanceof Object ) {
62
+ objs.push(args[1]);
63
+ }
64
+ const matched = matchObjectPropertiesFn(propNeedles, ...objs);
65
+ if ( matched === undefined ) { return fetchPromise; }
66
+ if ( safe.logLevel > 1 ) {
67
+ safe.uboLog(logPrefix, `Matched "propsToMatch":\n\t${matched.join('\n\t')}`);
68
+ }
69
+ }
70
+ return fetchPromise.then(responseBefore => {
71
+ const response = responseBefore.clone();
72
+ return response.json().then(obj => {
73
+ if ( typeof obj !== 'object' ) { return responseBefore; }
74
+ const objAfter = jsonp.apply(obj);
75
+ if ( objAfter === undefined ) { return responseBefore; }
76
+ safe.uboLog(logPrefix, 'Edited');
77
+ const responseAfter = Response.json(objAfter, {
78
+ status: responseBefore.status,
79
+ statusText: responseBefore.statusText,
80
+ headers: responseBefore.headers,
81
+ });
82
+ Object.defineProperties(responseAfter, {
83
+ ok: { value: responseBefore.ok },
84
+ redirected: { value: responseBefore.redirected },
85
+ type: { value: responseBefore.type },
86
+ url: { value: responseBefore.url },
87
+ });
88
+ return responseAfter;
89
+ }).catch(reason => {
90
+ safe.uboErr(logPrefix, 'Error:', reason);
91
+ return responseBefore;
92
+ });
93
+ }).catch(reason => {
94
+ safe.uboErr(logPrefix, 'Error:', reason);
95
+ return fetchPromise;
96
+ });
97
+ });
98
+ }
99
+
100
+ class JSONPath {
101
+ static create(query) {
102
+ const jsonp = new JSONPath();
103
+ jsonp.compile(query);
104
+ return jsonp;
105
+ }
106
+ static toJSON(obj, stringifier, ...args) {
107
+ return (stringifier || JSON.stringify)(obj, ...args)
108
+ .replace(/\//g, '\\/');
109
+ }
110
+ get value() {
111
+ return this.#compiled && this.#compiled.rval;
112
+ }
113
+ set value(v) {
114
+ if ( this.#compiled === undefined ) { return; }
115
+ this.#compiled.rval = v;
116
+ }
117
+ get valid() {
118
+ return this.#compiled !== undefined;
119
+ }
120
+ compile(query) {
121
+ this.#compiled = undefined;
122
+ const r = this.#compile(query, 0);
123
+ if ( r === undefined ) { return; }
124
+ if ( r.i !== query.length ) {
125
+ let val;
126
+ if ( query.startsWith('=', r.i) ) {
127
+ if ( /^=repl\(.+\)$/.test(query.slice(r.i)) ) {
128
+ r.modify = 'repl';
129
+ val = query.slice(r.i+6, -1);
130
+ } else {
131
+ val = query.slice(r.i+1);
132
+ }
133
+ } else if ( query.startsWith('+=', r.i) ) {
134
+ r.modify = '+';
135
+ val = query.slice(r.i+2);
136
+ }
137
+ try { r.rval = JSON.parse(val); }
138
+ catch { return; }
139
+ }
140
+ this.#compiled = r;
141
+ }
142
+ evaluate(root) {
143
+ if ( this.valid === false ) { return []; }
144
+ this.#root = root;
145
+ const paths = this.#evaluate(this.#compiled.steps, []);
146
+ this.#root = null;
147
+ return paths;
148
+ }
149
+ apply(root) {
150
+ if ( this.valid === false ) { return; }
151
+ const { rval } = this.#compiled;
152
+ this.#root = { '$': root };
153
+ const paths = this.#evaluate(this.#compiled.steps, []);
154
+ let i = paths.length
155
+ if ( i === 0 ) { this.#root = null; return; }
156
+ while ( i-- ) {
157
+ const { obj, key } = this.#resolvePath(paths[i]);
158
+ if ( rval !== undefined ) {
159
+ this.#modifyVal(obj, key);
160
+ } else if ( Array.isArray(obj) && typeof key === 'number' ) {
161
+ obj.splice(key, 1);
162
+ } else {
163
+ delete obj[key];
164
+ }
165
+ }
166
+ const result = this.#root['$'] ?? null;
167
+ this.#root = null;
168
+ return result;
169
+ }
170
+ dump() {
171
+ return JSON.stringify(this.#compiled);
172
+ }
173
+ toJSON(obj, ...args) {
174
+ return JSONPath.toJSON(obj, null, ...args)
175
+ }
176
+ get [Symbol.toStringTag]() {
177
+ return 'JSONPath';
178
+ }
179
+ #UNDEFINED = 0;
180
+ #ROOT = 1;
181
+ #CURRENT = 2;
182
+ #CHILDREN = 3;
183
+ #DESCENDANTS = 4;
184
+ #reUnquotedIdentifier = /^[A-Za-z_][\w]*|^\*/;
185
+ #reExpr = /^([!=^$*]=|[<>]=?)(.+?)\]/;
186
+ #reIndice = /^-?\d+/;
187
+ #root;
188
+ #compiled;
189
+ #compile(query, i) {
190
+ if ( query.length === 0 ) { return; }
191
+ const steps = [];
192
+ let c = query.charCodeAt(i);
193
+ if ( c === 0x24 /* $ */ ) {
194
+ steps.push({ mv: this.#ROOT });
195
+ i += 1;
196
+ } else if ( c === 0x40 /* @ */ ) {
197
+ steps.push({ mv: this.#CURRENT });
198
+ i += 1;
199
+ } else {
200
+ steps.push({ mv: i === 0 ? this.#ROOT : this.#CURRENT });
201
+ }
202
+ let mv = this.#UNDEFINED;
203
+ for (;;) {
204
+ if ( i === query.length ) { break; }
205
+ c = query.charCodeAt(i);
206
+ if ( c === 0x20 /* whitespace */ ) {
207
+ i += 1;
208
+ continue;
209
+ }
210
+ // Dot accessor syntax
211
+ if ( c === 0x2E /* . */ ) {
212
+ if ( mv !== this.#UNDEFINED ) { return; }
213
+ if ( query.startsWith('..', i) ) {
214
+ mv = this.#DESCENDANTS;
215
+ i += 2;
216
+ } else {
217
+ mv = this.#CHILDREN;
218
+ i += 1;
219
+ }
220
+ continue;
221
+ }
222
+ if ( c !== 0x5B /* [ */ ) {
223
+ if ( mv === this.#UNDEFINED ) {
224
+ const step = steps.at(-1);
225
+ if ( step === undefined ) { return; }
226
+ i = this.#compileExpr(query, step, i);
227
+ break;
228
+ }
229
+ const s = this.#consumeUnquotedIdentifier(query, i);
230
+ if ( s === undefined ) { return; }
231
+ steps.push({ mv, k: s });
232
+ i += s.length;
233
+ mv = this.#UNDEFINED;
234
+ continue;
235
+ }
236
+ // Bracket accessor syntax
237
+ if ( query.startsWith('[?', i) ) {
238
+ const not = query.charCodeAt(i+2) === 0x21 /* ! */;
239
+ const j = i + 2 + (not ? 1 : 0);
240
+ const r = this.#compile(query, j);
241
+ if ( r === undefined ) { return; }
242
+ if ( query.startsWith(']', r.i) === false ) { return; }
243
+ if ( not ) { r.steps.at(-1).not = true; }
244
+ steps.push({ mv: mv || this.#CHILDREN, steps: r.steps });
245
+ i = r.i + 1;
246
+ mv = this.#UNDEFINED;
247
+ continue;
248
+ }
249
+ if ( query.startsWith('[*]', i) ) {
250
+ mv ||= this.#CHILDREN;
251
+ steps.push({ mv, k: '*' });
252
+ i += 3;
253
+ mv = this.#UNDEFINED;
254
+ continue;
255
+ }
256
+ const r = this.#consumeIdentifier(query, i+1);
257
+ if ( r === undefined ) { return; }
258
+ mv ||= this.#CHILDREN;
259
+ steps.push({ mv, k: r.s });
260
+ i = r.i + 1;
261
+ mv = this.#UNDEFINED;
262
+ }
263
+ if ( steps.length === 0 ) { return; }
264
+ if ( mv !== this.#UNDEFINED ) { return; }
265
+ return { steps, i };
266
+ }
267
+ #evaluate(steps, pathin) {
268
+ let resultset = [];
269
+ if ( Array.isArray(steps) === false ) { return resultset; }
270
+ for ( const step of steps ) {
271
+ switch ( step.mv ) {
272
+ case this.#ROOT:
273
+ resultset = [ [ '$' ] ];
274
+ break;
275
+ case this.#CURRENT:
276
+ resultset = [ pathin ];
277
+ break;
278
+ case this.#CHILDREN:
279
+ case this.#DESCENDANTS:
280
+ resultset = this.#getMatches(resultset, step);
281
+ break;
282
+ default:
283
+ break;
284
+ }
285
+ }
286
+ return resultset;
287
+ }
288
+ #getMatches(listin, step) {
289
+ const listout = [];
290
+ for ( const pathin of listin ) {
291
+ const { value: owner } = this.#resolvePath(pathin);
292
+ if ( step.k === '*' ) {
293
+ this.#getMatchesFromAll(pathin, step, owner, listout);
294
+ } else if ( step.k !== undefined ) {
295
+ this.#getMatchesFromKeys(pathin, step, owner, listout);
296
+ } else if ( step.steps ) {
297
+ this.#getMatchesFromExpr(pathin, step, owner, listout);
298
+ }
299
+ }
300
+ return listout;
301
+ }
302
+ #getMatchesFromAll(pathin, step, owner, out) {
303
+ const recursive = step.mv === this.#DESCENDANTS;
304
+ for ( const { path } of this.#getDescendants(owner, recursive) ) {
305
+ out.push([ ...pathin, ...path ]);
306
+ }
307
+ }
308
+ #getMatchesFromKeys(pathin, step, owner, out) {
309
+ const kk = Array.isArray(step.k) ? step.k : [ step.k ];
310
+ for ( const k of kk ) {
311
+ const normalized = this.#evaluateExpr(step, owner, k);
312
+ if ( normalized === undefined ) { continue; }
313
+ out.push([ ...pathin, normalized ]);
314
+ }
315
+ if ( step.mv !== this.#DESCENDANTS ) { return; }
316
+ for ( const { obj, key, path } of this.#getDescendants(owner, true) ) {
317
+ for ( const k of kk ) {
318
+ const normalized = this.#evaluateExpr(step, obj[key], k);
319
+ if ( normalized === undefined ) { continue; }
320
+ out.push([ ...pathin, ...path, normalized ]);
321
+ }
322
+ }
323
+ }
324
+ #getMatchesFromExpr(pathin, step, owner, out) {
325
+ const recursive = step.mv === this.#DESCENDANTS;
326
+ if ( Array.isArray(owner) === false ) {
327
+ const r = this.#evaluate(step.steps, pathin);
328
+ if ( r.length !== 0 ) { out.push(pathin); }
329
+ if ( recursive !== true ) { return; }
330
+ }
331
+ for ( const { obj, key, path } of this.#getDescendants(owner, recursive) ) {
332
+ if ( Array.isArray(obj[key]) ) { continue; }
333
+ const q = [ ...pathin, ...path ];
334
+ const r = this.#evaluate(step.steps, q);
335
+ if ( r.length === 0 ) { continue; }
336
+ out.push(q);
337
+ }
338
+ }
339
+ #normalizeKey(owner, key) {
340
+ if ( typeof key === 'number' ) {
341
+ if ( Array.isArray(owner) ) {
342
+ return key >= 0 ? key : owner.length + key;
343
+ }
344
+ }
345
+ return key;
346
+ }
347
+ #getDescendants(v, recursive) {
348
+ const iterator = {
349
+ next() {
350
+ const n = this.stack.length;
351
+ if ( n === 0 ) {
352
+ this.value = undefined;
353
+ this.done = true;
354
+ return this;
355
+ }
356
+ const details = this.stack[n-1];
357
+ const entry = details.keys.next();
358
+ if ( entry.done ) {
359
+ this.stack.pop();
360
+ this.path.pop();
361
+ return this.next();
362
+ }
363
+ this.path[n-1] = entry.value;
364
+ this.value = {
365
+ obj: details.obj,
366
+ key: entry.value,
367
+ path: this.path.slice(),
368
+ };
369
+ const v = this.value.obj[this.value.key];
370
+ if ( recursive ) {
371
+ if ( Array.isArray(v) ) {
372
+ this.stack.push({ obj: v, keys: v.keys() });
373
+ } else if ( typeof v === 'object' && v !== null ) {
374
+ this.stack.push({ obj: v, keys: Object.keys(v).values() });
375
+ }
376
+ }
377
+ return this;
378
+ },
379
+ path: [],
380
+ value: undefined,
381
+ done: false,
382
+ stack: [],
383
+ [Symbol.iterator]() { return this; },
384
+ };
385
+ if ( Array.isArray(v) ) {
386
+ iterator.stack.push({ obj: v, keys: v.keys() });
387
+ } else if ( typeof v === 'object' && v !== null ) {
388
+ iterator.stack.push({ obj: v, keys: Object.keys(v).values() });
389
+ }
390
+ return iterator;
391
+ }
392
+ #consumeIdentifier(query, i) {
393
+ const keys = [];
394
+ for (;;) {
395
+ const c0 = query.charCodeAt(i);
396
+ if ( c0 === 0x5D /* ] */ ) { break; }
397
+ if ( c0 === 0x2C /* , */ ) {
398
+ i += 1;
399
+ continue;
400
+ }
401
+ if ( c0 === 0x27 /* ' */ ) {
402
+ const r = this.#consumeQuotedIdentifier(query, i+1);
403
+ if ( r === undefined ) { return; }
404
+ keys.push(r.s);
405
+ i = r.i;
406
+ continue;
407
+ }
408
+ if ( c0 === 0x2D /* - */ || c0 >= 0x30 && c0 <= 0x39 ) {
409
+ const match = this.#reIndice.exec(query.slice(i));
410
+ if ( match === null ) { return; }
411
+ const indice = parseInt(query.slice(i), 10);
412
+ keys.push(indice);
413
+ i += match[0].length;
414
+ continue;
415
+ }
416
+ const s = this.#consumeUnquotedIdentifier(query, i);
417
+ if ( s === undefined ) { return; }
418
+ keys.push(s);
419
+ i += s.length;
420
+ }
421
+ return { s: keys.length === 1 ? keys[0] : keys, i };
422
+ }
423
+ #consumeQuotedIdentifier(query, i) {
424
+ const len = query.length;
425
+ const parts = [];
426
+ let beg = i, end = i;
427
+ for (;;) {
428
+ if ( end === len ) { return; }
429
+ const c = query.charCodeAt(end);
430
+ if ( c === 0x27 /* ' */ ) {
431
+ parts.push(query.slice(beg, end));
432
+ end += 1;
433
+ break;
434
+ }
435
+ if ( c === 0x5C /* \ */ && (end+1) < len ) {
436
+ parts.push(query.slice(beg, end));
437
+ const d = query.chatCodeAt(end+1);
438
+ if ( d === 0x27 || d === 0x5C ) {
439
+ end += 1;
440
+ beg = end;
441
+ }
442
+ }
443
+ end += 1;
444
+ }
445
+ return { s: parts.join(''), i: end };
446
+ }
447
+ #consumeUnquotedIdentifier(query, i) {
448
+ const match = this.#reUnquotedIdentifier.exec(query.slice(i));
449
+ if ( match === null ) { return; }
450
+ return match[0];
451
+ }
452
+ #compileExpr(query, step, i) {
453
+ const match = this.#reExpr.exec(query.slice(i));
454
+ if ( match === null ) { return i; }
455
+ try {
456
+ step.rval = JSON.parse(match[2]);
457
+ step.op = match[1];
458
+ } catch {
459
+ }
460
+ return i + match[1].length + match[2].length;
461
+ }
462
+ #resolvePath(path) {
463
+ if ( path.length === 0 ) { return { value: this.#root }; }
464
+ const key = path.at(-1);
465
+ let obj = this.#root
466
+ for ( let i = 0, n = path.length-1; i < n; i++ ) {
467
+ obj = obj[path[i]];
468
+ }
469
+ return { obj, key, value: obj[key] };
470
+ }
471
+ #evaluateExpr(step, owner, key) {
472
+ if ( owner === undefined || owner === null ) { return; }
473
+ if ( typeof key === 'number' ) {
474
+ if ( Array.isArray(owner) === false ) { return; }
475
+ }
476
+ const k = this.#normalizeKey(owner, key);
477
+ const hasOwn = Object.hasOwn(owner, k);
478
+ if ( step.op !== undefined && hasOwn === false ) { return; }
479
+ const target = step.not !== true;
480
+ const v = owner[k];
481
+ let outcome = false;
482
+ switch ( step.op ) {
483
+ case '==': outcome = (v === step.rval) === target; break;
484
+ case '!=': outcome = (v !== step.rval) === target; break;
485
+ case '<': outcome = (v < step.rval) === target; break;
486
+ case '<=': outcome = (v <= step.rval) === target; break;
487
+ case '>': outcome = (v > step.rval) === target; break;
488
+ case '>=': outcome = (v >= step.rval) === target; break;
489
+ case '^=': outcome = `${v}`.startsWith(step.rval) === target; break;
490
+ case '$=': outcome = `${v}`.endsWith(step.rval) === target; break;
491
+ case '*=': outcome = `${v}`.includes(step.rval) === target; break;
492
+ default: outcome = hasOwn === target; break;
493
+ }
494
+ if ( outcome ) { return k; }
495
+ }
496
+ #modifyVal(obj, key) {
497
+ const { modify, rval } = this.#compiled;
498
+ switch ( modify ) {
499
+ case undefined:
500
+ obj[key] = rval;
501
+ break;
502
+ case '+': {
503
+ if ( rval instanceof Object === false ) { return; }
504
+ const lval = obj[key];
505
+ if ( lval instanceof Object === false ) { return; }
506
+ if ( Array.isArray(lval) ) { return; }
507
+ for ( const [ k, v ] of Object.entries(rval) ) {
508
+ lval[k] = v;
509
+ }
510
+ break;
511
+ }
512
+ case 'repl': {
513
+ const lval = obj[key];
514
+ if ( typeof lval !== 'string' ) { return; }
515
+ if ( this.#compiled.re === undefined ) {
516
+ this.#compiled.re = null;
517
+ try {
518
+ this.#compiled.re = rval.regex !== undefined
519
+ ? new RegExp(rval.regex, rval.flags)
520
+ : new RegExp(rval.pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
521
+ } catch {
522
+ }
523
+ }
524
+ if ( this.#compiled.re === null ) { return; }
525
+ obj[key] = lval.replace(this.#compiled.re, rval.replacement);
526
+ break;
527
+ }
528
+ default:
529
+ break;
530
+ }
531
+ }
532
+ }
533
+
534
+ function matchObjectPropertiesFn(propNeedles, ...objs) {
535
+ const safe = safeSelf();
536
+ const matched = [];
537
+ for ( const obj of objs ) {
538
+ if ( obj instanceof Object === false ) { continue; }
539
+ for ( const [ prop, details ] of propNeedles ) {
540
+ let value = obj[prop];
541
+ if ( value === undefined ) { continue; }
542
+ if ( typeof value !== 'string' ) {
543
+ try { value = safe.JSON_stringify(value); }
544
+ catch { }
545
+ if ( typeof value !== 'string' ) { continue; }
546
+ }
547
+ if ( safe.testPattern(details, value) === false ) { return; }
548
+ matched.push(`${prop}: ${value}`);
549
+ }
550
+ }
551
+ return matched;
552
+ }
553
+
554
+ function parsePropertiesToMatchFn(propsToMatch, implicit = '') {
555
+ const safe = safeSelf();
556
+ const needles = new Map();
557
+ if ( propsToMatch === undefined || propsToMatch === '' ) { return needles; }
558
+ const options = { canNegate: true };
559
+ for ( const needle of safe.String_split.call(propsToMatch, /\s+/) ) {
560
+ let [ prop, pattern ] = safe.String_split.call(needle, ':');
561
+ if ( prop === '' ) { continue; }
562
+ if ( pattern !== undefined && /[^$\w -]/.test(prop) ) {
563
+ prop = `${prop}:${pattern}`;
564
+ pattern = undefined;
565
+ }
566
+ if ( pattern !== undefined ) {
567
+ needles.set(prop, safe.initPattern(pattern, options));
568
+ } else if ( implicit !== '' ) {
569
+ needles.set(implicit, safe.initPattern(prop, options));
570
+ }
571
+ }
572
+ return needles;
573
+ }
574
+
575
+ function proxyApplyFn(
576
+ target = '',
577
+ handler = ''
578
+ ) {
579
+ let context = globalThis;
580
+ let prop = target;
581
+ for (;;) {
582
+ const pos = prop.indexOf('.');
583
+ if ( pos === -1 ) { break; }
584
+ context = context[prop.slice(0, pos)];
585
+ if ( context instanceof Object === false ) { return; }
586
+ prop = prop.slice(pos+1);
587
+ }
588
+ const fn = context[prop];
589
+ if ( typeof fn !== 'function' ) { return; }
590
+ if ( proxyApplyFn.CtorContext === undefined ) {
591
+ proxyApplyFn.ctorContexts = [];
592
+ proxyApplyFn.CtorContext = class {
593
+ constructor(...args) {
594
+ this.init(...args);
595
+ }
596
+ init(callFn, callArgs) {
597
+ this.callFn = callFn;
598
+ this.callArgs = callArgs;
599
+ return this;
600
+ }
601
+ reflect() {
602
+ const r = Reflect.construct(this.callFn, this.callArgs);
603
+ this.callFn = this.callArgs = this.private = undefined;
604
+ proxyApplyFn.ctorContexts.push(this);
605
+ return r;
606
+ }
607
+ static factory(...args) {
608
+ return proxyApplyFn.ctorContexts.length !== 0
609
+ ? proxyApplyFn.ctorContexts.pop().init(...args)
610
+ : new proxyApplyFn.CtorContext(...args);
611
+ }
612
+ };
613
+ proxyApplyFn.applyContexts = [];
614
+ proxyApplyFn.ApplyContext = class {
615
+ constructor(...args) {
616
+ this.init(...args);
617
+ }
618
+ init(callFn, thisArg, callArgs) {
619
+ this.callFn = callFn;
620
+ this.thisArg = thisArg;
621
+ this.callArgs = callArgs;
622
+ return this;
623
+ }
624
+ reflect() {
625
+ const r = Reflect.apply(this.callFn, this.thisArg, this.callArgs);
626
+ this.callFn = this.thisArg = this.callArgs = this.private = undefined;
627
+ proxyApplyFn.applyContexts.push(this);
628
+ return r;
629
+ }
630
+ static factory(...args) {
631
+ return proxyApplyFn.applyContexts.length !== 0
632
+ ? proxyApplyFn.applyContexts.pop().init(...args)
633
+ : new proxyApplyFn.ApplyContext(...args);
634
+ }
635
+ };
636
+ }
637
+ const fnStr = fn.toString();
638
+ const toString = (function toString() { return fnStr; }).bind(null);
639
+ const proxyDetails = {
640
+ apply(target, thisArg, args) {
641
+ return handler(proxyApplyFn.ApplyContext.factory(target, thisArg, args));
642
+ },
643
+ get(target, prop) {
644
+ if ( prop === 'toString' ) { return toString; }
645
+ return Reflect.get(target, prop);
646
+ },
647
+ };
648
+ if ( fn.prototype?.constructor === fn ) {
649
+ proxyDetails.construct = function(target, args) {
650
+ return handler(proxyApplyFn.CtorContext.factory(target, args));
651
+ };
652
+ }
653
+ context[prop] = new Proxy(fn, proxyDetails);
654
+ }
655
+
656
+ function safeSelf() {
657
+ if ( scriptletGlobals.safeSelf ) {
658
+ return scriptletGlobals.safeSelf;
659
+ }
660
+ const self = globalThis;
661
+ const safe = {
662
+ 'Array_from': Array.from,
663
+ 'Error': self.Error,
664
+ 'Function_toStringFn': self.Function.prototype.toString,
665
+ 'Function_toString': thisArg => safe.Function_toStringFn.call(thisArg),
666
+ 'Math_floor': Math.floor,
667
+ 'Math_max': Math.max,
668
+ 'Math_min': Math.min,
669
+ 'Math_random': Math.random,
670
+ 'Object': Object,
671
+ 'Object_defineProperty': Object.defineProperty.bind(Object),
672
+ 'Object_defineProperties': Object.defineProperties.bind(Object),
673
+ 'Object_fromEntries': Object.fromEntries.bind(Object),
674
+ 'Object_getOwnPropertyDescriptor': Object.getOwnPropertyDescriptor.bind(Object),
675
+ 'Object_hasOwn': Object.hasOwn.bind(Object),
676
+ 'RegExp': self.RegExp,
677
+ 'RegExp_test': self.RegExp.prototype.test,
678
+ 'RegExp_exec': self.RegExp.prototype.exec,
679
+ 'Request_clone': self.Request.prototype.clone,
680
+ 'String': self.String,
681
+ 'String_fromCharCode': String.fromCharCode,
682
+ 'String_split': String.prototype.split,
683
+ 'XMLHttpRequest': self.XMLHttpRequest,
684
+ 'addEventListener': self.EventTarget.prototype.addEventListener,
685
+ 'removeEventListener': self.EventTarget.prototype.removeEventListener,
686
+ 'fetch': self.fetch,
687
+ 'JSON': self.JSON,
688
+ 'JSON_parseFn': self.JSON.parse,
689
+ 'JSON_stringifyFn': self.JSON.stringify,
690
+ 'JSON_parse': (...args) => safe.JSON_parseFn.call(safe.JSON, ...args),
691
+ 'JSON_stringify': (...args) => safe.JSON_stringifyFn.call(safe.JSON, ...args),
692
+ 'log': console.log.bind(console),
693
+ // Properties
694
+ logLevel: 0,
695
+ // Methods
696
+ makeLogPrefix(...args) {
697
+ return this.sendToLogger && `[${args.join(' \u205D ')}]` || '';
698
+ },
699
+ uboLog(...args) {
700
+ if ( this.sendToLogger === undefined ) { return; }
701
+ if ( args === undefined || args[0] === '' ) { return; }
702
+ return this.sendToLogger('info', ...args);
703
+
704
+ },
705
+ uboErr(...args) {
706
+ if ( this.sendToLogger === undefined ) { return; }
707
+ if ( args === undefined || args[0] === '' ) { return; }
708
+ return this.sendToLogger('error', ...args);
709
+ },
710
+ escapeRegexChars(s) {
711
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
712
+ },
713
+ initPattern(pattern, options = {}) {
714
+ if ( pattern === '' ) {
715
+ return { matchAll: true, expect: true };
716
+ }
717
+ const expect = (options.canNegate !== true || pattern.startsWith('!') === false);
718
+ if ( expect === false ) {
719
+ pattern = pattern.slice(1);
720
+ }
721
+ const match = /^\/(.+)\/([gimsu]*)$/.exec(pattern);
722
+ if ( match !== null ) {
723
+ return {
724
+ re: new this.RegExp(
725
+ match[1],
726
+ match[2] || options.flags
727
+ ),
728
+ expect,
729
+ };
730
+ }
731
+ if ( options.flags !== undefined ) {
732
+ return {
733
+ re: new this.RegExp(this.escapeRegexChars(pattern),
734
+ options.flags
735
+ ),
736
+ expect,
737
+ };
738
+ }
739
+ return { pattern, expect };
740
+ },
741
+ testPattern(details, haystack) {
742
+ if ( details.matchAll ) { return true; }
743
+ if ( details.re ) {
744
+ return this.RegExp_test.call(details.re, haystack) === details.expect;
745
+ }
746
+ return haystack.includes(details.pattern) === details.expect;
747
+ },
748
+ patternToRegex(pattern, flags = undefined, verbatim = false) {
749
+ if ( pattern === '' ) { return /^/; }
750
+ const match = /^\/(.+)\/([gimsu]*)$/.exec(pattern);
751
+ if ( match === null ) {
752
+ const reStr = this.escapeRegexChars(pattern);
753
+ return new RegExp(verbatim ? `^${reStr}$` : reStr, flags);
754
+ }
755
+ try {
756
+ return new RegExp(match[1], match[2] || undefined);
757
+ }
758
+ catch {
759
+ }
760
+ return /^/;
761
+ },
762
+ getExtraArgs(args, offset = 0) {
763
+ const entries = args.slice(offset).reduce((out, v, i, a) => {
764
+ if ( (i & 1) === 0 ) {
765
+ const rawValue = a[i+1];
766
+ const value = /^\d+$/.test(rawValue)
767
+ ? parseInt(rawValue, 10)
768
+ : rawValue;
769
+ out.push([ a[i], value ]);
770
+ }
771
+ return out;
772
+ }, []);
773
+ return this.Object_fromEntries(entries);
774
+ },
775
+ onIdle(fn, options) {
776
+ if ( self.requestIdleCallback ) {
777
+ return self.requestIdleCallback(fn, options);
778
+ }
779
+ return self.requestAnimationFrame(fn);
780
+ },
781
+ offIdle(id) {
782
+ if ( self.requestIdleCallback ) {
783
+ return self.cancelIdleCallback(id);
784
+ }
785
+ return self.cancelAnimationFrame(id);
786
+ }
787
+ };
788
+ scriptletGlobals.safeSelf = safe;
789
+ if ( scriptletGlobals.bcSecret === undefined ) { return safe; }
790
+ // This is executed only when the logger is opened
791
+ safe.logLevel = scriptletGlobals.logLevel || 1;
792
+ let lastLogType = '';
793
+ let lastLogText = '';
794
+ let lastLogTime = 0;
795
+ safe.toLogText = (type, ...args) => {
796
+ if ( args.length === 0 ) { return; }
797
+ const text = `[${document.location.hostname || document.location.href}]${args.join(' ')}`;
798
+ if ( text === lastLogText && type === lastLogType ) {
799
+ if ( (Date.now() - lastLogTime) < 5000 ) { return; }
800
+ }
801
+ lastLogType = type;
802
+ lastLogText = text;
803
+ lastLogTime = Date.now();
804
+ return text;
805
+ };
806
+ try {
807
+ const bc = new self.BroadcastChannel(scriptletGlobals.bcSecret);
808
+ let bcBuffer = [];
809
+ safe.sendToLogger = (type, ...args) => {
810
+ const text = safe.toLogText(type, ...args);
811
+ if ( text === undefined ) { return; }
812
+ if ( bcBuffer === undefined ) {
813
+ return bc.postMessage({ what: 'messageToLogger', type, text });
814
+ }
815
+ bcBuffer.push({ type, text });
816
+ };
817
+ bc.onmessage = ev => {
818
+ const msg = ev.data;
819
+ switch ( msg ) {
820
+ case 'iamready!':
821
+ if ( bcBuffer === undefined ) { break; }
822
+ bcBuffer.forEach(({ type, text }) =>
823
+ bc.postMessage({ what: 'messageToLogger', type, text })
824
+ );
825
+ bcBuffer = undefined;
826
+ break;
827
+ case 'setScriptletLogLevelToOne':
828
+ safe.logLevel = 1;
829
+ break;
830
+ case 'setScriptletLogLevelToTwo':
831
+ safe.logLevel = 2;
832
+ break;
833
+ }
834
+ };
835
+ bc.postMessage('areyouready?');
836
+ } catch {
837
+ safe.sendToLogger = (type, ...args) => {
838
+ const text = safe.toLogText(type, ...args);
839
+ if ( text === undefined ) { return; }
840
+ safe.log(`uBO ${text}`);
841
+ };
842
+ }
843
+ return safe;
844
+ }
845
+
846
+ /******************************************************************************/
847
+
848
+ const scriptletGlobals = {}; // eslint-disable-line
849
+ const argsList = [[".pageProps.__APOLLO_STATE__.*[?.__typename==\"AotSidebar\"]","propsToMatch","/_next/data"]];
850
+ const hostnamesMap = new Map([["asiaon.*",0],["asiaontop.com",0]]);
851
+ const exceptionsMap = new Map([]);
852
+ const hasEntities = true;
853
+ const hasAncestors = false;
854
+
855
+ const collectArgIndices = (hn, map, out) => {
856
+ let argsIndices = map.get(hn);
857
+ if ( argsIndices === undefined ) { return; }
858
+ if ( typeof argsIndices !== 'number' ) {
859
+ for ( const argsIndex of argsIndices ) {
860
+ out.add(argsIndex);
861
+ }
862
+ } else {
863
+ out.add(argsIndices);
864
+ }
865
+ };
866
+
867
+ const indicesFromHostname = (hostname, suffix = '') => {
868
+ const hnParts = hostname.split('.');
869
+ const hnpartslen = hnParts.length;
870
+ if ( hnpartslen === 0 ) { return; }
871
+ for ( let i = 0; i < hnpartslen; i++ ) {
872
+ const hn = `${hnParts.slice(i).join('.')}${suffix}`;
873
+ collectArgIndices(hn, hostnamesMap, todoIndices);
874
+ collectArgIndices(hn, exceptionsMap, tonotdoIndices);
875
+ }
876
+ if ( hasEntities ) {
877
+ const n = hnpartslen - 1;
878
+ for ( let i = 0; i < n; i++ ) {
879
+ for ( let j = n; j > i; j-- ) {
880
+ const en = `${hnParts.slice(i,j).join('.')}.*${suffix}`;
881
+ collectArgIndices(en, hostnamesMap, todoIndices);
882
+ collectArgIndices(en, exceptionsMap, tonotdoIndices);
883
+ }
884
+ }
885
+ }
886
+ };
887
+
888
+ const entries = (( ) => {
889
+ const docloc = document.location;
890
+ const origins = [ docloc.origin ];
891
+ if ( docloc.ancestorOrigins ) {
892
+ origins.push(...docloc.ancestorOrigins);
893
+ }
894
+ return origins.map((origin, i) => {
895
+ const beg = origin.lastIndexOf('://');
896
+ if ( beg === -1 ) { return; }
897
+ const hn = origin.slice(beg+3)
898
+ const end = hn.indexOf(':');
899
+ return { hn: end === -1 ? hn : hn.slice(0, end), i };
900
+ }).filter(a => a !== undefined);
901
+ })();
902
+ if ( entries.length === 0 ) { return; }
903
+
904
+ const todoIndices = new Set();
905
+ const tonotdoIndices = new Set();
906
+
907
+ indicesFromHostname(entries[0].hn);
908
+ if ( hasAncestors ) {
909
+ for ( const entry of entries ) {
910
+ if ( entry.i === 0 ) { continue; }
911
+ indicesFromHostname(entry.hn, '>>');
912
+ }
913
+ }
914
+
915
+ // Apply scriplets
916
+ for ( const i of todoIndices ) {
917
+ if ( tonotdoIndices.has(i) ) { continue; }
918
+ try { jsonEditFetchResponse(...argsList[i]); }
919
+ catch { }
920
+ }
921
+
922
+ /******************************************************************************/
923
+
924
+ // End of local scope
925
+ })();
926
+
927
+ void 0;