browser-extension-utils 0.3.2 → 0.3.4

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.ts CHANGED
@@ -22,7 +22,9 @@ export const uniq = <T>(array: T[]): T[] => [...new Set(array)]
22
22
  export const $ = (
23
23
  selector: string,
24
24
  context: Element | Document = doc
25
- ): HTMLElement | null => context.querySelector(selector)!
25
+ ): HTMLElement | undefined =>
26
+ (context ? context.querySelector<HTMLElement>(selector) : undefined) ||
27
+ undefined
26
28
 
27
29
  export const $$ = (
28
30
  selector: string,
@@ -30,7 +32,7 @@ export const $$ = (
30
32
  ): HTMLElement[] =>
31
33
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
32
34
  // @ts-ignore
33
- [...context.querySelectorAll(selector)] as HTMLElement[]
35
+ [...(context ? context.querySelectorAll(selector) : [])] as HTMLElement[]
34
36
 
35
37
  export const addStyle = (
36
38
  style: string,
package/lib/userscript.ts CHANGED
@@ -40,7 +40,8 @@ export const addElement =
40
40
  for (const entry of Object.entries(attributes)) {
41
41
  // Some userscript managers do not support innerHTML
42
42
  // Stay do not support multiple classes: GM_addElement('div', {"class": "a b"}). Remove `|class` when it is supported
43
- if (/^(on\w+|innerHTML|class)$/.test(entry[0])) {
43
+ // Stay do not support data-* attributes
44
+ if (/^(on\w+|innerHTML|class|data-.+)$/.test(entry[0])) {
44
45
  entries2.push(entry)
45
46
  } else {
46
47
  entries1.push(entry)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-utils",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Utilities for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.ts",