browser-extension-utils 0.0.6 → 0.0.8
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 +7 -5
- package/lib/index.js +10 -8
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -3,33 +3,35 @@ 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
|
|
32
32
|
|
|
33
|
+
export function getAttribute(element: HTMLElement, name: string): string
|
|
34
|
+
|
|
33
35
|
export function setAttribute(
|
|
34
36
|
element: HTMLElement,
|
|
35
37
|
name: string,
|
package/lib/index.js
CHANGED
|
@@ -35,6 +35,7 @@ export const addEventListener = (element, type, listener) => {
|
|
|
35
35
|
// TODO: return remover function
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
export const getAttribute = (element, name) => element.getAttribute(name)
|
|
38
39
|
export const setAttribute = (element, name, value) =>
|
|
39
40
|
element.setAttribute(name, value)
|
|
40
41
|
|
|
@@ -57,7 +58,7 @@ export const setStyle = (element, values, overwrite) => {
|
|
|
57
58
|
|
|
58
59
|
for (const key in values) {
|
|
59
60
|
if (Object.hasOwn(values, key)) {
|
|
60
|
-
style[key] = values[key]
|
|
61
|
+
style[key] = values[key].replace("!important", "")
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
}
|
|
@@ -68,6 +69,7 @@ const toStyleKeyValues = (styleText) => {
|
|
|
68
69
|
const keyValues = styleText.split(/\s*;\s*/)
|
|
69
70
|
for (const keyValue of keyValues) {
|
|
70
71
|
const kv = keyValue.split(/\s*:\s*/)
|
|
72
|
+
// TODO: fix when key is such as -webkit-xxx
|
|
71
73
|
const key = toCamelCase(kv[0])
|
|
72
74
|
if (key) {
|
|
73
75
|
result[key] = kv[1]
|
|
@@ -95,13 +97,13 @@ export const noStyleSpace = (text) => text.replace(/\s*([^\w-!])\s*/gm, "$1")
|
|
|
95
97
|
|
|
96
98
|
export const createSetStyle = (styleText) => {
|
|
97
99
|
const styleMap = toStyleMap(styleText)
|
|
98
|
-
return (element,
|
|
99
|
-
if (typeof
|
|
100
|
-
setStyle(element,
|
|
101
|
-
} else if (typeof
|
|
102
|
-
key = noStyleSpace(
|
|
103
|
-
const
|
|
104
|
-
setStyle(element,
|
|
100
|
+
return (element, value, overwrite) => {
|
|
101
|
+
if (typeof value === "object") {
|
|
102
|
+
setStyle(element, value, overwrite)
|
|
103
|
+
} else if (typeof value === "string") {
|
|
104
|
+
const key = noStyleSpace(value)
|
|
105
|
+
const value2 = styleMap[key]
|
|
106
|
+
setStyle(element, value2 || value, overwrite)
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
}
|