browser-extension-utils 0.1.8 → 0.1.10
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 +6 -1
- package/lib/index.js +55 -4
- package/package.json +2 -1
package/lib/index.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ export function noStyleSpace(text: string): string
|
|
|
111
111
|
|
|
112
112
|
export function createSetStyle(styleText: string): SetStyle
|
|
113
113
|
|
|
114
|
-
export function isUrl(text: string): boolean
|
|
114
|
+
export function isUrl(text: string | undefined): boolean
|
|
115
115
|
|
|
116
116
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
117
117
|
export function throttle(func: Function, interval: number): Function
|
|
@@ -138,6 +138,9 @@ export function getOffsetPosition(
|
|
|
138
138
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
139
139
|
export function runOnce(key: string, func: Function): any
|
|
140
140
|
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
142
|
+
export function runWhenHeadExists(func: Function): void
|
|
143
|
+
|
|
141
144
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
142
145
|
export function runWhenBodyExists(func: Function): void
|
|
143
146
|
|
|
@@ -152,6 +155,8 @@ export const cache: Cache
|
|
|
152
155
|
|
|
153
156
|
export function isVisible(element: HTMLElement): boolean
|
|
154
157
|
|
|
158
|
+
export function isTouchScreen(): boolean
|
|
159
|
+
|
|
155
160
|
export function parseInt10(
|
|
156
161
|
number: string | undefined,
|
|
157
162
|
defaultValue?: number
|
package/lib/index.js
CHANGED
|
@@ -348,14 +348,63 @@ export const parseInt10 = (number, defaultValue) => {
|
|
|
348
348
|
return Number.isNaN(result) ? defaultValue : result
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
+
const headFuncArray = []
|
|
352
|
+
const bodyFuncArray = []
|
|
353
|
+
let headBodyObserver
|
|
354
|
+
|
|
355
|
+
const startObserveHeadBodyExists = () => {
|
|
356
|
+
if (headBodyObserver) {
|
|
357
|
+
return
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
headBodyObserver = new MutationObserver(() => {
|
|
361
|
+
if (doc.head && doc.body) {
|
|
362
|
+
headBodyObserver.disconnect()
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (doc.head && headFuncArray.length > 0) {
|
|
366
|
+
for (const func of headFuncArray) {
|
|
367
|
+
func()
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
headFuncArray.length = 0
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (doc.body && bodyFuncArray.length > 0) {
|
|
374
|
+
for (const func of bodyFuncArray) {
|
|
375
|
+
func()
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
bodyFuncArray.length = 0
|
|
379
|
+
}
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
headBodyObserver.observe(doc, {
|
|
383
|
+
childList: true,
|
|
384
|
+
subtree: true,
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Run function when document.head exsits.
|
|
390
|
+
*/
|
|
391
|
+
export const runWhenHeadExists = (func) => {
|
|
392
|
+
if (!doc.head) {
|
|
393
|
+
headFuncArray.push(func)
|
|
394
|
+
startObserveHeadBodyExists()
|
|
395
|
+
return
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
func()
|
|
399
|
+
}
|
|
400
|
+
|
|
351
401
|
/**
|
|
352
|
-
* Run function when document.body exsits. The function
|
|
402
|
+
* Run function when document.body exsits. The function executed before DOMContentLoaded.
|
|
353
403
|
*/
|
|
354
404
|
export const runWhenBodyExists = (func) => {
|
|
355
405
|
if (!doc.body) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}, 10)
|
|
406
|
+
bodyFuncArray.push(func)
|
|
407
|
+
startObserveHeadBodyExists()
|
|
359
408
|
return
|
|
360
409
|
}
|
|
361
410
|
|
|
@@ -369,3 +418,5 @@ export const isVisible = (element) => {
|
|
|
369
418
|
|
|
370
419
|
return element.offsetParent !== null
|
|
371
420
|
}
|
|
421
|
+
|
|
422
|
+
export const isTouchScreen = () => "ontouchstart" in win
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-extension-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Utilities for developing browser extensions and userscripts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"GM_addElement",
|
|
49
49
|
"GM_addStyle",
|
|
50
50
|
"GM_registerMenuCommand",
|
|
51
|
+
"MutationObserver",
|
|
51
52
|
"history",
|
|
52
53
|
"window",
|
|
53
54
|
"top",
|