browser-extension-settings 0.3.1 → 0.4.0
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/common.ts +1 -1
- package/lib/settings.ts +61 -3
- package/lib/style.scss +26 -3
- package/lib/switch.ts +3 -3
- package/package.json +2 -2
package/lib/common.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const besVersion =
|
|
1
|
+
export const besVersion = 40
|
|
2
2
|
export const openButton = `<svg viewBox="0 0 60.2601318359375 84.8134765625" version="1.1" xmlns="http://www.w3.org/2000/svg" class=" glyph-box" style="height: 9.62969px; width: 6.84191px;"><g transform="matrix(1 0 0 1 -6.194965820312518 77.63671875)"><path d="M66.4551-35.2539C66.4551-36.4746 65.9668-37.5977 65.0391-38.4766L26.3672-76.3672C25.4883-77.1973 24.4141-77.6367 23.1445-77.6367C20.6543-77.6367 18.7012-75.7324 18.7012-73.1934C18.7012-71.9727 19.1895-70.8496 19.9707-70.0195L55.5176-35.2539L19.9707-0.488281C19.1895 0.341797 18.7012 1.41602 18.7012 2.68555C18.7012 5.22461 20.6543 7.12891 23.1445 7.12891C24.4141 7.12891 25.4883 6.68945 26.3672 5.81055L65.0391-32.0312C65.9668-32.959 66.4551-34.0332 66.4551-35.2539Z"></path></g></svg>`
|
|
3
3
|
export const openInNewTabButton = `<svg viewBox="0 0 72.127685546875 72.2177734375" version="1.1" xmlns="http://www.w3.org/2000/svg" class=" glyph-box" style="height: 8.19958px; width: 8.18935px;"><g transform="matrix(1 0 0 1 -12.451127929687573 71.3388671875)"><path d="M84.5703-17.334L84.5215-66.4551C84.5215-69.2383 82.7148-71.1914 79.7852-71.1914L30.6641-71.1914C27.9297-71.1914 26.0742-69.0918 26.0742-66.748C26.0742-64.4043 28.1738-62.4023 30.4688-62.4023L47.4609-62.4023L71.2891-63.1836L62.207-55.2246L13.8184-6.73828C12.9395-5.85938 12.4512-4.73633 12.4512-3.66211C12.4512-1.31836 14.5508 0.878906 16.9922 0.878906C18.1152 0.878906 19.1895 0.488281 20.0684-0.439453L68.5547-48.877L76.6113-58.0078L75.7324-35.2051L75.7324-17.1387C75.7324-14.8438 77.7344-12.6953 80.127-12.6953C82.4707-12.6953 84.5703-14.6973 84.5703-17.334Z"></path></g></svg>`
|
|
4
4
|
export const settingButton = `<svg viewBox="0 0 16 16" version="1.1">
|
package/lib/settings.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
doc,
|
|
14
14
|
parseInt10,
|
|
15
15
|
removeEventListener,
|
|
16
|
-
|
|
16
|
+
runWhenDomReady,
|
|
17
17
|
runWhenHeadExists,
|
|
18
18
|
} from "browser-extension-utils"
|
|
19
19
|
import styleText from "data-text:./style.scss"
|
|
@@ -41,7 +41,11 @@ type SettingsOptions = {
|
|
|
41
41
|
|
|
42
42
|
type SettingsTable = Record<
|
|
43
43
|
string,
|
|
44
|
-
|
|
44
|
+
| SettingsSwitchItem
|
|
45
|
+
| SettingsInputItem
|
|
46
|
+
| SettingsActionItem
|
|
47
|
+
| SettingsSelectItem
|
|
48
|
+
| SettingsTipItem
|
|
45
49
|
>
|
|
46
50
|
|
|
47
51
|
type SettingsSwitchItem = {
|
|
@@ -71,6 +75,15 @@ type SettingsActionItem = {
|
|
|
71
75
|
defaultValue?: any
|
|
72
76
|
}
|
|
73
77
|
|
|
78
|
+
type SettingsSelectItem = {
|
|
79
|
+
title: string
|
|
80
|
+
icon?: string
|
|
81
|
+
type: "select"
|
|
82
|
+
options: { string: { string: any } }
|
|
83
|
+
group?: number
|
|
84
|
+
defaultValue?: any
|
|
85
|
+
}
|
|
86
|
+
|
|
74
87
|
type SettingsTipItem = {
|
|
75
88
|
title: string
|
|
76
89
|
icon?: string
|
|
@@ -210,6 +223,18 @@ async function updateOptions() {
|
|
|
210
223
|
break
|
|
211
224
|
}
|
|
212
225
|
|
|
226
|
+
case "select": {
|
|
227
|
+
const options = $$(
|
|
228
|
+
`#${settingsElementId} .option_groups .select_option[data-key="${key}"] .bes_select option`
|
|
229
|
+
) as HTMLOptionElement[]
|
|
230
|
+
|
|
231
|
+
for (const option of options) {
|
|
232
|
+
option.selected = option.value === String(getSettingsValue(key))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
break
|
|
236
|
+
}
|
|
237
|
+
|
|
213
238
|
case "textarea": {
|
|
214
239
|
const textArea = $(
|
|
215
240
|
`#${settingsElementId} .option_groups textarea[data-key="${key}"]`
|
|
@@ -393,6 +418,39 @@ function createSettingsElement() {
|
|
|
393
418
|
break
|
|
394
419
|
}
|
|
395
420
|
|
|
421
|
+
case "select": {
|
|
422
|
+
const div = addElement(optionGroup, "div", {
|
|
423
|
+
class: "select_option bes_option",
|
|
424
|
+
"data-key": key,
|
|
425
|
+
})
|
|
426
|
+
if (item.icon) {
|
|
427
|
+
addElement(div, "img", { src: item.icon, class: "bes_icon" })
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
addElement(div, "span", {
|
|
431
|
+
textContent: item.title,
|
|
432
|
+
class: "bes_title",
|
|
433
|
+
})
|
|
434
|
+
|
|
435
|
+
const select = addElement(div, "select", {
|
|
436
|
+
class: "bes_select",
|
|
437
|
+
onchange: async () => {
|
|
438
|
+
console.log(select.value)
|
|
439
|
+
await saveSettingsValue(key, select.value)
|
|
440
|
+
},
|
|
441
|
+
}) as HTMLSelectElement
|
|
442
|
+
|
|
443
|
+
for (const option of Object.entries(
|
|
444
|
+
(item as SettingsSelectItem).options
|
|
445
|
+
)) {
|
|
446
|
+
addElement(select, "option", {
|
|
447
|
+
textContent: option[0],
|
|
448
|
+
value: option[1],
|
|
449
|
+
})
|
|
450
|
+
}
|
|
451
|
+
break
|
|
452
|
+
}
|
|
453
|
+
|
|
396
454
|
case "tip": {
|
|
397
455
|
const tip = addElement(optionGroup, "div", {
|
|
398
456
|
class: "bes_tip",
|
|
@@ -522,7 +580,7 @@ export const initSettings = async (options: SettingsOptions) => {
|
|
|
522
580
|
runWhenHeadExists(() => {
|
|
523
581
|
addStyle(getSettingsStyle())
|
|
524
582
|
})
|
|
525
|
-
|
|
583
|
+
runWhenDomReady(() => {
|
|
526
584
|
initExtensionList()
|
|
527
585
|
addSideMenu()
|
|
528
586
|
})
|
package/lib/style.scss
CHANGED
|
@@ -30,12 +30,18 @@
|
|
|
30
30
|
font-size: 26px;
|
|
31
31
|
font-weight: 800;
|
|
32
32
|
border: none;
|
|
33
|
+
color: var(--browser-extension-settings-text-color);
|
|
34
|
+
margin: 18px 0;
|
|
35
|
+
padding: 0;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
h2 {
|
|
36
39
|
font-size: 18px;
|
|
37
40
|
font-weight: 600;
|
|
38
41
|
border: none;
|
|
42
|
+
color: var(--browser-extension-settings-text-color);
|
|
43
|
+
margin: 14px 0;
|
|
44
|
+
padding: 0;
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
.extension_list_container {
|
|
@@ -134,6 +140,7 @@
|
|
|
134
140
|
font-size: 18px;
|
|
135
141
|
font-weight: 600;
|
|
136
142
|
border: none;
|
|
143
|
+
color: var(--browser-extension-settings-text-color);
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
footer {
|
|
@@ -208,7 +215,8 @@
|
|
|
208
215
|
box-sizing: border-box;
|
|
209
216
|
}
|
|
210
217
|
|
|
211
|
-
.switch_option
|
|
218
|
+
.switch_option,
|
|
219
|
+
.select_option {
|
|
212
220
|
display: flex;
|
|
213
221
|
justify-content: space-between;
|
|
214
222
|
align-items: center;
|
|
@@ -224,16 +232,31 @@
|
|
|
224
232
|
border-top: none;
|
|
225
233
|
}
|
|
226
234
|
|
|
227
|
-
.
|
|
235
|
+
.bes_option > .bes_icon {
|
|
228
236
|
width: 24px;
|
|
229
237
|
height: 24px;
|
|
230
238
|
margin-right: 10px;
|
|
231
239
|
}
|
|
232
|
-
.
|
|
240
|
+
.bes_option > .bes_title {
|
|
233
241
|
margin-right: 10px;
|
|
234
242
|
flex-grow: 1;
|
|
235
243
|
}
|
|
236
244
|
|
|
245
|
+
.bes_option > .bes_select {
|
|
246
|
+
box-sizing: border-box;
|
|
247
|
+
background-color: #fff;
|
|
248
|
+
height: 24px;
|
|
249
|
+
padding: 0 2px 0 2px;
|
|
250
|
+
margin: 0;
|
|
251
|
+
border-radius: 6px;
|
|
252
|
+
border: 1px solid #ccc;
|
|
253
|
+
/*
|
|
254
|
+
-webkit-appearance: none;
|
|
255
|
+
-moz-appearance: none;
|
|
256
|
+
appearance: none;
|
|
257
|
+
*/
|
|
258
|
+
}
|
|
259
|
+
|
|
237
260
|
.option_groups .bes_tip {
|
|
238
261
|
position: relative;
|
|
239
262
|
margin: 0;
|
package/lib/switch.ts
CHANGED
|
@@ -44,12 +44,12 @@ export function createSwitchOption(
|
|
|
44
44
|
return createSwitchOption(undefined, icon, text)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const div = createElement("div", { class: "switch_option" })
|
|
47
|
+
const div = createElement("div", { class: "switch_option bes_option" })
|
|
48
48
|
if (icon) {
|
|
49
|
-
addElement(div, "img", { src: icon })
|
|
49
|
+
addElement(div, "img", { src: icon, class: "bes_icon" })
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
addElement(div, "span", { textContent: text })
|
|
52
|
+
addElement(div, "span", { textContent: text, class: "bes_title" })
|
|
53
53
|
div.append(createSwitch(options))
|
|
54
54
|
return div
|
|
55
55
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-extension-settings",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Settings module for developing browser extensions and userscripts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"homepage": "https://github.com/utags/browser-extension-settings#readme",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"browser-extension-storage": "^0.1.2",
|
|
31
|
-
"browser-extension-utils": "^0.1.
|
|
31
|
+
"browser-extension-utils": "^0.1.17"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/chrome": "^0.0.243",
|