browser-extension-utils 0.1.16 → 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 CHANGED
@@ -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
@@ -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.16",
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",