browser-extension-settings 0.3.0 → 0.3.1
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 +2 -2
- package/lib/settings.ts +10 -6
- package/lib/style.scss +6 -0
- package/lib/switch.ts +18 -0
- package/package.json +1 -1
package/lib/index.ts
CHANGED
package/lib/settings.ts
CHANGED
|
@@ -46,6 +46,7 @@ type SettingsTable = Record<
|
|
|
46
46
|
|
|
47
47
|
type SettingsSwitchItem = {
|
|
48
48
|
title: string
|
|
49
|
+
icon?: string
|
|
49
50
|
defaultValue: boolean
|
|
50
51
|
type?: "switch"
|
|
51
52
|
group?: number
|
|
@@ -53,6 +54,7 @@ type SettingsSwitchItem = {
|
|
|
53
54
|
|
|
54
55
|
type SettingsInputItem = {
|
|
55
56
|
title: string
|
|
57
|
+
icon?: string
|
|
56
58
|
defaultValue: string
|
|
57
59
|
placeholder?: string
|
|
58
60
|
type: string
|
|
@@ -61,6 +63,7 @@ type SettingsInputItem = {
|
|
|
61
63
|
|
|
62
64
|
type SettingsActionItem = {
|
|
63
65
|
title: string
|
|
66
|
+
icon?: string
|
|
64
67
|
type: string
|
|
65
68
|
onclick?: () => void
|
|
66
69
|
url?: string
|
|
@@ -70,6 +73,7 @@ type SettingsActionItem = {
|
|
|
70
73
|
|
|
71
74
|
type SettingsTipItem = {
|
|
72
75
|
title: string
|
|
76
|
+
icon?: string
|
|
73
77
|
type: string
|
|
74
78
|
tipContent: string
|
|
75
79
|
group?: number
|
|
@@ -108,7 +112,7 @@ async function getSettings() {
|
|
|
108
112
|
)
|
|
109
113
|
}
|
|
110
114
|
|
|
111
|
-
async function
|
|
115
|
+
async function saveSettingsValue(key: string, value: any) {
|
|
112
116
|
const settings = await getSettings()
|
|
113
117
|
settings[key] =
|
|
114
118
|
settingsTable[key] && settingsTable[key].defaultValue === value
|
|
@@ -118,11 +122,11 @@ async function saveSattingsValue(key: string, value: any) {
|
|
|
118
122
|
await setValue(storageKey, settings)
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
export async function
|
|
125
|
+
export async function resetSettingsValues() {
|
|
122
126
|
await setValue(storageKey, {})
|
|
123
127
|
}
|
|
124
128
|
|
|
125
|
-
export async function
|
|
129
|
+
export async function saveSettingsValues(
|
|
126
130
|
values: Record<string, boolean | string | undefined>
|
|
127
131
|
) {
|
|
128
132
|
const settings = await getSettings()
|
|
@@ -324,11 +328,11 @@ function createSettingsElement() {
|
|
|
324
328
|
// console.log(key, item, type, group)
|
|
325
329
|
switch (type) {
|
|
326
330
|
case "switch": {
|
|
327
|
-
const switchOption = createSwitchOption(item.title, {
|
|
331
|
+
const switchOption = createSwitchOption(item.icon, item.title, {
|
|
328
332
|
async onchange(event: Event) {
|
|
329
333
|
const checkbox = event.target as HTMLInputElement
|
|
330
334
|
if (checkbox) {
|
|
331
|
-
await
|
|
335
|
+
await saveSettingsValue(key, checkbox.checked)
|
|
332
336
|
}
|
|
333
337
|
},
|
|
334
338
|
})
|
|
@@ -357,7 +361,7 @@ function createSettingsElement() {
|
|
|
357
361
|
|
|
358
362
|
timeoutId = setTimeout(async () => {
|
|
359
363
|
if (textArea) {
|
|
360
|
-
await
|
|
364
|
+
await saveSettingsValue(key, textArea.value.trim())
|
|
361
365
|
}
|
|
362
366
|
}, 100)
|
|
363
367
|
},
|
package/lib/style.scss
CHANGED
package/lib/switch.ts
CHANGED
|
@@ -29,8 +29,26 @@ export function createSwitch(options = {} as SwichOptions): HTMLElement {
|
|
|
29
29
|
export function createSwitchOption(
|
|
30
30
|
text: string,
|
|
31
31
|
options: SwichOptions
|
|
32
|
+
): HTMLElement
|
|
33
|
+
export function createSwitchOption(
|
|
34
|
+
icon: string | undefined,
|
|
35
|
+
text: string,
|
|
36
|
+
options: SwichOptions
|
|
37
|
+
): HTMLElement
|
|
38
|
+
export function createSwitchOption(
|
|
39
|
+
icon: string,
|
|
40
|
+
text: string | SwichOptions,
|
|
41
|
+
options?: SwichOptions
|
|
32
42
|
): HTMLElement {
|
|
43
|
+
if (typeof text !== "string") {
|
|
44
|
+
return createSwitchOption(undefined, icon, text)
|
|
45
|
+
}
|
|
46
|
+
|
|
33
47
|
const div = createElement("div", { class: "switch_option" })
|
|
48
|
+
if (icon) {
|
|
49
|
+
addElement(div, "img", { src: icon })
|
|
50
|
+
}
|
|
51
|
+
|
|
34
52
|
addElement(div, "span", { textContent: text })
|
|
35
53
|
div.append(createSwitch(options))
|
|
36
54
|
return div
|