browser-extension-utils 0.0.7 → 0.0.9

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
@@ -3,29 +3,29 @@ export function uniq(array: any[]): any[]
3
3
  export function toCamelCase(text: string): string
4
4
 
5
5
  export function $(
6
- element: HTMLElement | string,
6
+ element: HTMLElement | Document | string,
7
7
  selectors?: string
8
8
  ): HTMLElement
9
9
 
10
10
  export function querySelector(
11
- element: HTMLElement | string,
11
+ element: HTMLElement | Document | string,
12
12
  selectors?: string
13
13
  ): HTMLElement
14
14
 
15
15
  export function $$(
16
- element: HTMLElement | string,
16
+ element: HTMLElement | Document | string,
17
17
  selectors?: string
18
18
  ): HTMLElement[]
19
19
 
20
20
  export function querySelectorAll(
21
- element: HTMLElement | string,
21
+ element: HTMLElement | Document | string,
22
22
  selectors?: string
23
23
  ): HTMLElement[]
24
24
 
25
25
  export function createElement(tagName: string): HTMLElement
26
26
 
27
27
  export function addEventListener(
28
- element: HTMLElement,
28
+ element: HTMLElement | Document | EventTarget,
29
29
  type: string | Record<string, unknown>,
30
30
  listener?
31
31
  ): void
package/lib/index.js CHANGED
@@ -40,20 +40,16 @@ export const setAttribute = (element, name, value) =>
40
40
  element.setAttribute(name, value)
41
41
 
42
42
  export const setStyle = (element, values, overwrite) => {
43
- // setAttribute(element, "style", value) -> Fail when violates CSP
43
+ // element.setAttribute("style", value) -> Fail when violates CSP
44
44
  const style = element.style
45
45
 
46
- if (overwrite) {
47
- if (typeof values === "string") {
48
- style.cssText = values
49
- return
50
- }
51
-
52
- style.cssText = ""
46
+ if (typeof values === "string") {
47
+ style.cssText = overwrite? values : style.cssText + ";" +values
48
+ return;
53
49
  }
54
50
 
55
- if (typeof values === "string") {
56
- values = toStyleKeyValues(values)
51
+ if (overwrite) {
52
+ style.cssText = ""
57
53
  }
58
54
 
59
55
  for (const key in values) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-utils",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Utilities for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",