browser-extension-utils 0.1.15 → 0.1.17
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/lib/index.d.ts +4 -1
- package/lib/index.js +25 -7
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ export function getOffsetPosition(
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
141
|
-
export function runOnce(key: string, func: Function): any
|
|
141
|
+
export async function runOnce(key: string, func: Function): Promise<any>
|
|
142
142
|
|
|
143
143
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
144
144
|
export function runWhenHeadExists(func: Function): void
|
|
@@ -146,6 +146,9 @@ export function runWhenHeadExists(func: Function): void
|
|
|
146
146
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
147
147
|
export function runWhenBodyExists(func: Function): void
|
|
148
148
|
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
150
|
+
export function runWhenDomReady(func: Function): void
|
|
151
|
+
|
|
149
152
|
export async function sleep(time: number): Promise<void>
|
|
150
153
|
|
|
151
154
|
export type Cache = {
|
package/lib/index.js
CHANGED
|
@@ -323,17 +323,17 @@ export const getOffsetPosition = (element, referElement) => {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
const runOnceCache = {}
|
|
326
|
-
export const runOnce = (key, func) => {
|
|
327
|
-
if (!key) {
|
|
328
|
-
return func()
|
|
329
|
-
}
|
|
330
|
-
|
|
326
|
+
export const runOnce = async (key, func) => {
|
|
331
327
|
if (Object.hasOwn(runOnceCache, key)) {
|
|
332
328
|
return runOnceCache[key]
|
|
333
329
|
}
|
|
334
330
|
|
|
335
|
-
const result = func()
|
|
336
|
-
|
|
331
|
+
const result = await func()
|
|
332
|
+
|
|
333
|
+
if (key) {
|
|
334
|
+
runOnceCache[key] = result
|
|
335
|
+
}
|
|
336
|
+
|
|
337
337
|
return result
|
|
338
338
|
}
|
|
339
339
|
|
|
@@ -435,6 +435,24 @@ export const runWhenBodyExists = (func) => {
|
|
|
435
435
|
func()
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Equals to jQuery.domready
|
|
440
|
+
*/
|
|
441
|
+
export const runWhenDomReady = (func) => {
|
|
442
|
+
if (doc.readyState === "interactive" || doc.readyState === "complete") {
|
|
443
|
+
return func()
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const handler = () => {
|
|
447
|
+
if (doc.readyState === "interactive" || doc.readyState === "complete") {
|
|
448
|
+
func()
|
|
449
|
+
removeEventListener(doc, "readystatechange", handler)
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
addEventListener(doc, "readystatechange", handler)
|
|
454
|
+
}
|
|
455
|
+
|
|
438
456
|
export const isVisible = (element) => {
|
|
439
457
|
if (typeof element.checkVisibility === "function") {
|
|
440
458
|
return element.checkVisibility()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-extension-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "Utilities for developing browser extensions and userscripts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/
|
|
18
|
+
"url": "git+https://github.com/utags/browser-extension-utils.git"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"extensions",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"author": "Pipecraft",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
28
|
+
"url": "https://github.com/utags/browser-extension-utils/issues"
|
|
29
29
|
},
|
|
30
|
-
"homepage": "https://github.com/
|
|
30
|
+
"homepage": "https://github.com/utags/browser-extension-utils#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"prettier": "^2.8.8",
|
|
33
33
|
"xo": "^0.55.0"
|