browser-extension-utils 0.1.17 → 0.1.19
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 +3 -0
- package/lib/index.js +27 -3
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -140,6 +140,9 @@ export function getOffsetPosition(
|
|
|
140
140
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
141
141
|
export async function runOnce(key: string, func: Function): Promise<any>
|
|
142
142
|
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
144
|
+
export function runWhenRootExists(func: Function): void
|
|
145
|
+
|
|
143
146
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
144
147
|
export function runWhenHeadExists(func: Function): void
|
|
145
148
|
|
package/lib/index.js
CHANGED
|
@@ -102,11 +102,13 @@ export const removeEventListener = (element, type, listener, options) => {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
export const getAttribute = (element, name) =>
|
|
105
|
-
element ? element.getAttribute(name) : null
|
|
105
|
+
element && element.getAttribute ? element.getAttribute(name) : null
|
|
106
106
|
export const setAttribute = (element, name, value) =>
|
|
107
|
-
element
|
|
107
|
+
element && element.setAttribute
|
|
108
|
+
? element.setAttribute(name, value)
|
|
109
|
+
: undefined
|
|
108
110
|
export const removeAttribute = (element, name) =>
|
|
109
|
-
element ? element.removeAttribute(name) : undefined
|
|
111
|
+
element && element.removeAttribute ? element.removeAttribute(name) : undefined
|
|
110
112
|
|
|
111
113
|
export const setAttributes = (element, attributes) => {
|
|
112
114
|
if (element && attributes) {
|
|
@@ -372,6 +374,7 @@ export const parseInt10 = (number, defaultValue) => {
|
|
|
372
374
|
return Number.isNaN(result) ? defaultValue : result
|
|
373
375
|
}
|
|
374
376
|
|
|
377
|
+
const rootFuncArray = []
|
|
375
378
|
const headFuncArray = []
|
|
376
379
|
const bodyFuncArray = []
|
|
377
380
|
let headBodyObserver
|
|
@@ -386,6 +389,14 @@ const startObserveHeadBodyExists = () => {
|
|
|
386
389
|
headBodyObserver.disconnect()
|
|
387
390
|
}
|
|
388
391
|
|
|
392
|
+
if (doc.documentElement && rootFuncArray.length > 0) {
|
|
393
|
+
for (const func of rootFuncArray) {
|
|
394
|
+
func()
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
rootFuncArray.length = 0
|
|
398
|
+
}
|
|
399
|
+
|
|
389
400
|
if (doc.head && headFuncArray.length > 0) {
|
|
390
401
|
for (const func of headFuncArray) {
|
|
391
402
|
func()
|
|
@@ -409,6 +420,19 @@ const startObserveHeadBodyExists = () => {
|
|
|
409
420
|
})
|
|
410
421
|
}
|
|
411
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Run function when document.documentElement exsits.
|
|
425
|
+
*/
|
|
426
|
+
export const runWhenRootExists = (func) => {
|
|
427
|
+
if (!doc.documentElement) {
|
|
428
|
+
rootFuncArray.push(func)
|
|
429
|
+
startObserveHeadBodyExists()
|
|
430
|
+
return
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
func()
|
|
434
|
+
}
|
|
435
|
+
|
|
412
436
|
/**
|
|
413
437
|
* Run function when document.head exsits.
|
|
414
438
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-extension-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "Utilities for developing browser extensions and userscripts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/utags/browser-extension-utils#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"prettier": "^
|
|
33
|
-
"xo": "^0.
|
|
32
|
+
"prettier": "^3.0.2",
|
|
33
|
+
"xo": "^0.56.0"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"lib/",
|