@sv443-network/userutils 8.3.0 → 8.3.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.
- package/CHANGELOG.md +6 -0
- package/README.md +5 -2
- package/dist/index.global.js +6 -3
- package/dist/index.js +5 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -622,6 +622,7 @@ If no predicate is specified, all events will be discarded.
|
|
|
622
622
|
Calling this function will set the `Error.stackTraceLimit` to 100 (if it's not already higher) to ensure the stack trace is preserved.
|
|
623
623
|
|
|
624
624
|
⚠️ This function should be called as soon as possible (I recommend using `@run-at document-start`), as it will only intercept events that are *attached* after this function is called.
|
|
625
|
+
⚠️ Due to this function modifying the `addEventListener` prototype, it might break execution of the page's main script if the userscript is running in an isolated context (like it does in FireMonkey). In that case, calling this function will throw an error.
|
|
625
626
|
|
|
626
627
|
<details><summary><b>Example - click to view</b></summary>
|
|
627
628
|
|
|
@@ -655,7 +656,8 @@ If no predicate is specified, all events will be discarded.
|
|
|
655
656
|
This is essentially the same as [`interceptEvent()`](#interceptevent), but automatically uses the `unsafeWindow` (or falls back to regular `window`).
|
|
656
657
|
|
|
657
658
|
⚠️ This function should be called as soon as possible (I recommend using `@run-at document-start`), as it will only intercept events that are *attached* after this function is called.
|
|
658
|
-
⚠️ In order
|
|
659
|
+
⚠️ In order to have the best chance at intercepting events, the directive `@grant unsafeWindow` should be set.
|
|
660
|
+
⚠️ Due to this function modifying the `addEventListener` prototype, it might break execution of the page's main script if the userscript is running in an isolated context (like it does in FireMonkey). In that case, calling this function will throw an error.
|
|
659
661
|
|
|
660
662
|
<details><summary><b>Example - click to view</b></summary>
|
|
661
663
|
|
|
@@ -1769,12 +1771,13 @@ Usage:
|
|
|
1769
1771
|
```ts
|
|
1770
1772
|
fetchAdvanced(input: string | Request | URL, options?: {
|
|
1771
1773
|
timeout?: number,
|
|
1772
|
-
// any other options from fetch()
|
|
1774
|
+
// any other options from fetch()
|
|
1773
1775
|
}): Promise<Response>
|
|
1774
1776
|
```
|
|
1775
1777
|
|
|
1776
1778
|
A drop-in replacement for the native `fetch()` function that adds options like a timeout property.
|
|
1777
1779
|
The timeout will default to 10 seconds if left undefined. Set it to a negative number to disable the timeout.
|
|
1780
|
+
Pass an [AbortController's signal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to the `signal` property to be able to abort the request before it finishes or the timeout kicks in.
|
|
1778
1781
|
|
|
1779
1782
|
<details><summary><b>Example - click to view</b></summary>
|
|
1780
1783
|
|
package/dist/index.global.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// ==UserLibrary==
|
|
9
9
|
// @name UserUtils
|
|
10
10
|
// @description Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and more
|
|
11
|
-
// @version 8.3.
|
|
11
|
+
// @version 8.3.1
|
|
12
12
|
// @license MIT
|
|
13
13
|
// @copyright Sv443 (https://github.com/Sv443)
|
|
14
14
|
|
|
@@ -247,13 +247,16 @@ var UserUtils = (function (exports) {
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
function interceptEvent(eventObject, eventName, predicate = () => true) {
|
|
250
|
+
var _a;
|
|
251
|
+
if ((eventObject === window || eventObject === getUnsafeWindow()) && ((_a = GM == null ? void 0 : GM.info) == null ? void 0 : _a.scriptHandler) && GM.info.scriptHandler === "FireMonkey")
|
|
252
|
+
throw new Error("Intercepting window events is not supported on FireMonkey due to the isolated context the userscript runs in.");
|
|
250
253
|
Error.stackTraceLimit = Math.max(Error.stackTraceLimit, 100);
|
|
251
254
|
if (isNaN(Error.stackTraceLimit))
|
|
252
255
|
Error.stackTraceLimit = 100;
|
|
253
256
|
(function(original) {
|
|
254
257
|
eventObject.__proto__.addEventListener = function(...args) {
|
|
255
|
-
var
|
|
256
|
-
const origListener = typeof args[1] === "function" ? args[1] : (_b = (
|
|
258
|
+
var _a2, _b;
|
|
259
|
+
const origListener = typeof args[1] === "function" ? args[1] : (_b = (_a2 = args[1]) == null ? void 0 : _a2.handleEvent) != null ? _b : () => void 0;
|
|
257
260
|
args[1] = function(...a) {
|
|
258
261
|
if (args[0] === eventName && predicate(Array.isArray(a) ? a[0] : a))
|
|
259
262
|
return;
|
package/dist/index.js
CHANGED
|
@@ -227,13 +227,16 @@ function openInNewTab(href, background) {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
function interceptEvent(eventObject, eventName, predicate = () => true) {
|
|
230
|
+
var _a;
|
|
231
|
+
if ((eventObject === window || eventObject === getUnsafeWindow()) && ((_a = GM == null ? void 0 : GM.info) == null ? void 0 : _a.scriptHandler) && GM.info.scriptHandler === "FireMonkey")
|
|
232
|
+
throw new Error("Intercepting window events is not supported on FireMonkey due to the isolated context the userscript runs in.");
|
|
230
233
|
Error.stackTraceLimit = Math.max(Error.stackTraceLimit, 100);
|
|
231
234
|
if (isNaN(Error.stackTraceLimit))
|
|
232
235
|
Error.stackTraceLimit = 100;
|
|
233
236
|
(function(original) {
|
|
234
237
|
eventObject.__proto__.addEventListener = function(...args) {
|
|
235
|
-
var
|
|
236
|
-
const origListener = typeof args[1] === "function" ? args[1] : (_b = (
|
|
238
|
+
var _a2, _b;
|
|
239
|
+
const origListener = typeof args[1] === "function" ? args[1] : (_b = (_a2 = args[1]) == null ? void 0 : _a2.handleEvent) != null ? _b : () => void 0;
|
|
237
240
|
args[1] = function(...a) {
|
|
238
241
|
if (args[0] === eventName && predicate(Array.isArray(a) ? a[0] : a))
|
|
239
242
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sv443-network/userutils",
|
|
3
3
|
"libName": "UserUtils",
|
|
4
|
-
"version": "8.3.
|
|
4
|
+
"version": "8.3.1",
|
|
5
5
|
"description": "Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and more",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|