browser-extension-utils 0.1.1 → 0.1.3
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 +20 -4
- package/lib/index.js +40 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -7,22 +7,22 @@ export function toCamelCase(text: string): string
|
|
|
7
7
|
export function $(
|
|
8
8
|
selectors: string,
|
|
9
9
|
element?: HTMLElement | Document
|
|
10
|
-
):
|
|
10
|
+
): HTMLElement | undefined
|
|
11
11
|
|
|
12
12
|
export function querySelector(
|
|
13
13
|
selectors: string,
|
|
14
14
|
element?: HTMLElement | Document
|
|
15
|
-
):
|
|
15
|
+
): HTMLElement | undefined
|
|
16
16
|
|
|
17
17
|
export function $$(
|
|
18
18
|
selectors: string,
|
|
19
19
|
element?: HTMLElement | Document
|
|
20
|
-
):
|
|
20
|
+
): HTMLElement[]
|
|
21
21
|
|
|
22
22
|
export function querySelectorAll(
|
|
23
23
|
selectors: string,
|
|
24
24
|
element?: HTMLElement | Document
|
|
25
|
-
):
|
|
25
|
+
): HTMLElement[]
|
|
26
26
|
|
|
27
27
|
export function createElement(
|
|
28
28
|
tagName: string,
|
|
@@ -85,6 +85,12 @@ export function addAttribute(
|
|
|
85
85
|
value: string
|
|
86
86
|
): void
|
|
87
87
|
|
|
88
|
+
export function addClass(element: HTMLElement, className: string): void
|
|
89
|
+
|
|
90
|
+
export function removeClass(element: HTMLElement, className: string): void
|
|
91
|
+
|
|
92
|
+
export function hasClass(element: HTMLElement, className: string): boolean
|
|
93
|
+
|
|
88
94
|
export type SetStyle = (
|
|
89
95
|
element: HTMLElement,
|
|
90
96
|
style: string | Record<string, unknown>,
|
|
@@ -115,3 +121,13 @@ export function registerMenuCommand(
|
|
|
115
121
|
): void
|
|
116
122
|
|
|
117
123
|
export function extendHistoryApi(): void
|
|
124
|
+
|
|
125
|
+
export const actionHref: string
|
|
126
|
+
|
|
127
|
+
export function getOffsetPosition(
|
|
128
|
+
element: HTMLElement | undefined,
|
|
129
|
+
referElement?: HTMLElement | undefined
|
|
130
|
+
): {
|
|
131
|
+
top: number
|
|
132
|
+
left: number
|
|
133
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -121,6 +121,30 @@ export const addAttribute = (element, name, value) => {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
export const addClass = (element, className) => {
|
|
125
|
+
if (!element) {
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
element.classList.add(className)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const removeClass = (element, className) => {
|
|
133
|
+
if (!element) {
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
element.classList.remove(className)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const hasClass = (element, className) => {
|
|
141
|
+
if (!element) {
|
|
142
|
+
return false
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return element.classList.contains(className)
|
|
146
|
+
}
|
|
147
|
+
|
|
124
148
|
export const setStyle = (element, values, overwrite) => {
|
|
125
149
|
if (!element) {
|
|
126
150
|
return
|
|
@@ -254,3 +278,19 @@ export const extendHistoryApi = () => {
|
|
|
254
278
|
// console.log("onlocationchange event occurred!")
|
|
255
279
|
// })
|
|
256
280
|
}
|
|
281
|
+
|
|
282
|
+
// eslint-disable-next-line no-script-url
|
|
283
|
+
export const actionHref = "javascript:;"
|
|
284
|
+
|
|
285
|
+
export const getOffsetPosition = (element, referElement) => {
|
|
286
|
+
const position = { top: 0, left: 0 }
|
|
287
|
+
referElement = referElement || doc.body
|
|
288
|
+
|
|
289
|
+
while (element && element !== referElement) {
|
|
290
|
+
position.top += element.offsetTop
|
|
291
|
+
position.left += element.offsetLeft
|
|
292
|
+
element = element.offsetParent
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return position
|
|
296
|
+
}
|