browser-extension-utils 0.1.17 → 0.1.18

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 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
@@ -372,6 +372,7 @@ export const parseInt10 = (number, defaultValue) => {
372
372
  return Number.isNaN(result) ? defaultValue : result
373
373
  }
374
374
 
375
+ const rootFuncArray = []
375
376
  const headFuncArray = []
376
377
  const bodyFuncArray = []
377
378
  let headBodyObserver
@@ -386,6 +387,14 @@ const startObserveHeadBodyExists = () => {
386
387
  headBodyObserver.disconnect()
387
388
  }
388
389
 
390
+ if (doc.documentElement && rootFuncArray.length > 0) {
391
+ for (const func of rootFuncArray) {
392
+ func()
393
+ }
394
+
395
+ rootFuncArray.length = 0
396
+ }
397
+
389
398
  if (doc.head && headFuncArray.length > 0) {
390
399
  for (const func of headFuncArray) {
391
400
  func()
@@ -409,6 +418,19 @@ const startObserveHeadBodyExists = () => {
409
418
  })
410
419
  }
411
420
 
421
+ /**
422
+ * Run function when document.documentElement exsits.
423
+ */
424
+ export const runWhenRootExists = (func) => {
425
+ if (!doc.documentElement) {
426
+ rootFuncArray.push(func)
427
+ startObserveHeadBodyExists()
428
+ return
429
+ }
430
+
431
+ func()
432
+ }
433
+
412
434
  /**
413
435
  * Run function when document.head exsits.
414
436
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-utils",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
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": "^2.8.8",
33
- "xo": "^0.55.0"
32
+ "prettier": "^3.0.2",
33
+ "xo": "^0.56.0"
34
34
  },
35
35
  "files": [
36
36
  "lib/",