@sv443-network/userutils 2.0.0 → 3.0.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.
- package/CHANGELOG.md +40 -0
- package/README.md +381 -156
- package/dist/index.global.js +186 -96
- package/dist/index.js +185 -95
- package/dist/index.mjs +184 -92
- package/dist/lib/{config.d.ts → ConfigManager.d.ts} +8 -5
- package/dist/lib/SelectorObserver.d.ts +84 -0
- package/dist/lib/array.d.ts +2 -0
- package/dist/lib/dom.d.ts +34 -32
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/math.d.ts +12 -5
- package/dist/lib/misc.d.ts +3 -3
- package/dist/lib/translation.d.ts +2 -2
- package/package.json +10 -4
- package/dist/lib/onSelector.d.ts +0 -40
package/dist/lib/misc.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type Stringifiable = string | {
|
|
|
3
3
|
toString(): string;
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
|
-
* Automatically appends an `s` to the passed
|
|
6
|
+
* Automatically appends an `s` to the passed {@linkcode word}, if {@linkcode num} is not equal to 1
|
|
7
7
|
* @param word A word in singular form, to auto-convert to plural
|
|
8
8
|
* @param num If this is an array or NodeList, the amount of items is used
|
|
9
9
|
*/
|
|
@@ -11,8 +11,8 @@ export declare function autoPlural(word: Stringifiable, num: number | unknown[]
|
|
|
11
11
|
/** Pauses async execution for the specified time in ms */
|
|
12
12
|
export declare function pauseFor(time: number): Promise<void>;
|
|
13
13
|
/**
|
|
14
|
-
* Calls the passed
|
|
15
|
-
* Any subsequent calls to this function will reset the timer and discard previous calls.
|
|
14
|
+
* Calls the passed {@linkcode func} after the specified {@linkcode timeout} in ms (defaults to 300).
|
|
15
|
+
* Any subsequent calls to this function will reset the timer and discard all previous calls.
|
|
16
16
|
*/
|
|
17
17
|
export declare function debounce<TFunc extends (...args: TArgs[]) => void, TArgs = any>(func: TFunc, timeout?: number): (...args: TArgs[]) => void;
|
|
18
18
|
/** Options for the `fetchAdvanced()` function */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Stringifiable } from "./misc";
|
|
2
2
|
/**
|
|
3
|
-
* Returns the translated text for the specified key in the current language set by
|
|
3
|
+
* Returns the translated text for the specified key in the current language set by {@linkcode tr.setLanguage()}
|
|
4
4
|
* If the key is not found in the previously registered translation, the key itself is returned.
|
|
5
5
|
*
|
|
6
|
-
* ⚠️ Remember to register a language with
|
|
6
|
+
* ⚠️ Remember to register a language with {@linkcode tr.addLanguage()} and set it as active with {@linkcode tr.setLanguage()} before using this function, otherwise it will always return the key itself.
|
|
7
7
|
* @param key Key of the translation to return
|
|
8
8
|
* @param args Optional arguments to be passed to the translated text. They will replace placeholders in the format `%n`, where `n` is the 1-indexed argument number
|
|
9
9
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sv443-network/userutils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, manage persistent user configurations, modify the DOM more easily and more",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
"post-build-global": "npm run node-ts -- ./tools/post-build-global.mts",
|
|
15
15
|
"dev": "npm run build-common -- --sourcemap --watch --onSuccess \"npm run build-types && echo Finished building.\"",
|
|
16
16
|
"publish-package": "changeset publish",
|
|
17
|
-
"node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm"
|
|
17
|
+
"node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm",
|
|
18
|
+
"test-serve": "npm run node-ts -- ./test/TestPage/server.mts",
|
|
19
|
+
"test-dev": "cd test/TestScript && npm run dev",
|
|
20
|
+
"test": "concurrently \"npm run test-serve\" \"npm run test-dev\""
|
|
18
21
|
},
|
|
19
22
|
"repository": {
|
|
20
23
|
"type": "git",
|
|
@@ -35,14 +38,17 @@
|
|
|
35
38
|
"homepage": "https://github.com/Sv443-Network/UserUtils",
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"@changesets/cli": "^2.26.2",
|
|
41
|
+
"@types/express": "^4.17.19",
|
|
38
42
|
"@types/greasemonkey": "^4.0.4",
|
|
39
43
|
"@types/node": "^20.5.9",
|
|
40
44
|
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
41
45
|
"@typescript-eslint/parser": "^6.2.1",
|
|
46
|
+
"concurrently": "^8.2.1",
|
|
42
47
|
"eslint": "^8.46.0",
|
|
48
|
+
"express": "^4.18.2",
|
|
43
49
|
"ts-node": "^10.9.1",
|
|
44
50
|
"tslib": "^2.6.1",
|
|
45
|
-
"tsup": "^7.
|
|
51
|
+
"tsup": "^7.1.0",
|
|
46
52
|
"typescript": "^5.1.6"
|
|
47
53
|
},
|
|
48
54
|
"files": [
|
|
@@ -55,4 +61,4 @@
|
|
|
55
61
|
"/CHANGELOG.md",
|
|
56
62
|
"/LICENSE.txt"
|
|
57
63
|
]
|
|
58
|
-
}
|
|
64
|
+
}
|
package/dist/lib/onSelector.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/** Options for the `onSelector()` function */
|
|
2
|
-
export type OnSelectorOpts<TElem extends Element = HTMLElement> = SelectorOptsOne<TElem> | SelectorOptsAll<TElem>;
|
|
3
|
-
type SelectorOptsOne<TElem extends Element> = SelectorOptsCommon & {
|
|
4
|
-
/** Whether to use `querySelectorAll()` instead - default is false */
|
|
5
|
-
all?: false;
|
|
6
|
-
/** Gets called whenever the selector was found in the DOM */
|
|
7
|
-
listener: (element: TElem) => void;
|
|
8
|
-
};
|
|
9
|
-
type SelectorOptsAll<TElem extends Element> = SelectorOptsCommon & {
|
|
10
|
-
/** Whether to use `querySelectorAll()` instead - default is false */
|
|
11
|
-
all: true;
|
|
12
|
-
/** Gets called whenever the selector was found in the DOM */
|
|
13
|
-
listener: (elements: NodeListOf<TElem>) => void;
|
|
14
|
-
};
|
|
15
|
-
type SelectorOptsCommon = {
|
|
16
|
-
/** Whether to call the listener continuously instead of once - default is false */
|
|
17
|
-
continuous?: boolean;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Calls the `listener` as soon as the `selector` exists in the DOM.
|
|
21
|
-
* Listeners are deleted when they are called once, unless `options.continuous` is set.
|
|
22
|
-
* Multiple listeners with the same selector may be registered.
|
|
23
|
-
* @param selector The selector to listen for
|
|
24
|
-
* @param options Used for switching to `querySelectorAll()` and for calling the listener continuously
|
|
25
|
-
* @template TElem The type of element that the listener will return as its argument (defaults to the generic HTMLElement)
|
|
26
|
-
*/
|
|
27
|
-
export declare function onSelector<TElem extends Element = HTMLElement>(selector: string, options: OnSelectorOpts<TElem>): void;
|
|
28
|
-
/**
|
|
29
|
-
* Removes all listeners registered in `onSelector()` that have the given selector
|
|
30
|
-
* @returns Returns true when all listeners with the associated selector were found and removed, false otherwise
|
|
31
|
-
*/
|
|
32
|
-
export declare function removeOnSelector(selector: string): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Initializes a MutationObserver that checks for all registered selectors whenever an element is added to or removed from the `<body>`
|
|
35
|
-
* @param options For fine-tuning what triggers the MutationObserver's checking function - `subtree` and `childList` are set to true by default
|
|
36
|
-
*/
|
|
37
|
-
export declare function initOnSelector(options?: MutationObserverInit): void;
|
|
38
|
-
/** Returns all currently registered selectors, as a map of selector strings to their associated options */
|
|
39
|
-
export declare function getSelectorMap(): Map<string, OnSelectorOpts<HTMLElement>[]>;
|
|
40
|
-
export {};
|