browser-extension-settings 0.3.1 → 0.5.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/extension-list.ts +23 -12
- package/lib/messages/en.ts +12 -0
- package/lib/messages/index.ts +8 -0
- package/lib/messages/zh-cn.ts +12 -0
- package/lib/settings.ts +67 -5
- package/lib/style.scss +26 -3
- package/lib/switch.ts +3 -3
- package/package.json +12 -3
package/lib/common.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const besVersion =
|
|
1
|
+
export const besVersion = 50
|
|
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/extension-list.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
removeClass,
|
|
9
9
|
} from "browser-extension-utils"
|
|
10
10
|
import { openButton, openInNewTabButton } from "./common"
|
|
11
|
+
import { i } from "./messages"
|
|
11
12
|
|
|
12
13
|
type InstalledExtension = {
|
|
13
14
|
id: string
|
|
@@ -23,37 +24,47 @@ type RelatedExtension = {
|
|
|
23
24
|
url: string
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
const lang = navigator.language
|
|
28
|
+
let locale: string
|
|
29
|
+
if (lang === "zh-TW" || lang === "zh-HK") {
|
|
30
|
+
locale = "zh-TW"
|
|
31
|
+
} else if (lang.includes("zh")) {
|
|
32
|
+
locale = "zh-CN"
|
|
33
|
+
} else {
|
|
34
|
+
locale = "en"
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
const relatedExtensions: RelatedExtension[] = [
|
|
27
38
|
{
|
|
28
39
|
id: "utags",
|
|
29
|
-
title: "
|
|
30
|
-
url:
|
|
40
|
+
title: i("settings.extensions.utags.title"),
|
|
41
|
+
url: `https://greasyfork.org/${locale}/scripts/460718-utags-add-usertags-to-links`,
|
|
31
42
|
},
|
|
32
43
|
{
|
|
33
44
|
id: "links-helper",
|
|
34
|
-
title: "
|
|
45
|
+
title: i("settings.extensions.links-helper.title"),
|
|
35
46
|
description: "在新标签页中打开第三方网站链接,图片链接转图片标签等",
|
|
36
|
-
url:
|
|
47
|
+
url: `https://greasyfork.org/${locale}/scripts/464541-links-helper`,
|
|
37
48
|
},
|
|
38
49
|
{
|
|
39
50
|
id: "v2ex.rep",
|
|
40
|
-
title: "
|
|
41
|
-
url:
|
|
51
|
+
title: i("settings.extensions.v2ex.rep.title"),
|
|
52
|
+
url: `https://greasyfork.org/${locale}/scripts/466589-v2ex-rep-%E4%B8%93%E6%B3%A8%E6%8F%90%E5%8D%87-v2ex-%E4%B8%BB%E9%A2%98%E5%9B%9E%E5%A4%8D%E6%B5%8F%E8%A7%88%E4%BD%93%E9%AA%8C`,
|
|
42
53
|
},
|
|
43
54
|
{
|
|
44
55
|
id: "v2ex.min",
|
|
45
|
-
title: "v2ex.min
|
|
46
|
-
url:
|
|
56
|
+
title: i("settings.extensions.v2ex.min.title"),
|
|
57
|
+
url: `https://greasyfork.org/${locale}/scripts/463552-v2ex-min-v2ex-%E6%9E%81%E7%AE%80%E9%A3%8E%E6%A0%BC`,
|
|
47
58
|
},
|
|
48
59
|
{
|
|
49
60
|
id: "replace-ugly-avatars",
|
|
50
|
-
title: "
|
|
51
|
-
url:
|
|
61
|
+
title: i("settings.extensions.replace-ugly-avatars.title"),
|
|
62
|
+
url: `https://greasyfork.org/${locale}/scripts/472616-replace-ugly-avatars`,
|
|
52
63
|
},
|
|
53
64
|
{
|
|
54
65
|
id: "more-by-pipecraft",
|
|
55
|
-
title: "
|
|
56
|
-
url:
|
|
66
|
+
title: i("settings.extensions.more-by-pipecraft.title"),
|
|
67
|
+
url: `https://greasyfork.org/${locale}/users/1030884-pipecraft`,
|
|
57
68
|
},
|
|
58
69
|
]
|
|
59
70
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
"settings.displaySettingsButtonInSideMenu": "Display Settings Button in Side Menu",
|
|
3
|
+
"settings.menu.settings": "⚙️ Settings",
|
|
4
|
+
"settings.extensions.utags.title": "🏷️ UTags - Add usertags to links",
|
|
5
|
+
"settings.extensions.links-helper.title": "🔗 Links Helper",
|
|
6
|
+
"settings.extensions.v2ex.rep.title": "V2EX.REP - 专注提升 V2EX 主题回复浏览体验",
|
|
7
|
+
"settings.extensions.v2ex.min.title": "v2ex.min - V2EX Minimalist (极简风格)",
|
|
8
|
+
"settings.extensions.replace-ugly-avatars.title": "Replace Ugly Avatars",
|
|
9
|
+
"settings.extensions.more-by-pipecraft.title": "Find more useful userscripts",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default messages
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const messages = {
|
|
2
|
+
"settings.displaySettingsButtonInSideMenu": "在侧边栏菜单中显示设置按钮",
|
|
3
|
+
"settings.menu.settings": "⚙️ 设置",
|
|
4
|
+
"settings.extensions.utags.title": "🏷️ 小鱼标签 (UTags) - 为链接添加用户标签",
|
|
5
|
+
"settings.extensions.links-helper.title": "🔗 链接助手",
|
|
6
|
+
"settings.extensions.v2ex.rep.title": "V2EX.REP - 专注提升 V2EX 主题回复浏览体验",
|
|
7
|
+
"settings.extensions.v2ex.min.title": "v2ex.min - V2EX 极简风格",
|
|
8
|
+
"settings.extensions.replace-ugly-avatars.title": "赐你个头像吧",
|
|
9
|
+
"settings.extensions.more-by-pipecraft.title": "更多有趣的脚本",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default messages
|
package/lib/settings.ts
CHANGED
|
@@ -12,8 +12,9 @@ import {
|
|
|
12
12
|
createHTML,
|
|
13
13
|
doc,
|
|
14
14
|
parseInt10,
|
|
15
|
+
registerMenuCommand,
|
|
15
16
|
removeEventListener,
|
|
16
|
-
|
|
17
|
+
runWhenDomReady,
|
|
17
18
|
runWhenHeadExists,
|
|
18
19
|
} from "browser-extension-utils"
|
|
19
20
|
import styleText from "data-text:./style.scss"
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
deactiveExtensionList,
|
|
27
28
|
} from "./extension-list"
|
|
28
29
|
import { besVersion, settingButton } from "./common"
|
|
30
|
+
import { i } from "./messages"
|
|
29
31
|
|
|
30
32
|
const prefix = "browser_extension_settings_"
|
|
31
33
|
|
|
@@ -41,7 +43,11 @@ type SettingsOptions = {
|
|
|
41
43
|
|
|
42
44
|
type SettingsTable = Record<
|
|
43
45
|
string,
|
|
44
|
-
|
|
46
|
+
| SettingsSwitchItem
|
|
47
|
+
| SettingsInputItem
|
|
48
|
+
| SettingsActionItem
|
|
49
|
+
| SettingsSelectItem
|
|
50
|
+
| SettingsTipItem
|
|
45
51
|
>
|
|
46
52
|
|
|
47
53
|
type SettingsSwitchItem = {
|
|
@@ -71,6 +77,15 @@ type SettingsActionItem = {
|
|
|
71
77
|
defaultValue?: any
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
type SettingsSelectItem = {
|
|
81
|
+
title: string
|
|
82
|
+
icon?: string
|
|
83
|
+
type: "select"
|
|
84
|
+
options: { string: { string: any } }
|
|
85
|
+
group?: number
|
|
86
|
+
defaultValue?: any
|
|
87
|
+
}
|
|
88
|
+
|
|
74
89
|
type SettingsTipItem = {
|
|
75
90
|
title: string
|
|
76
91
|
icon?: string
|
|
@@ -210,6 +225,18 @@ async function updateOptions() {
|
|
|
210
225
|
break
|
|
211
226
|
}
|
|
212
227
|
|
|
228
|
+
case "select": {
|
|
229
|
+
const options = $$(
|
|
230
|
+
`#${settingsElementId} .option_groups .select_option[data-key="${key}"] .bes_select option`
|
|
231
|
+
) as HTMLOptionElement[]
|
|
232
|
+
|
|
233
|
+
for (const option of options) {
|
|
234
|
+
option.selected = option.value === String(getSettingsValue(key))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
break
|
|
238
|
+
}
|
|
239
|
+
|
|
213
240
|
case "textarea": {
|
|
214
241
|
const textArea = $(
|
|
215
242
|
`#${settingsElementId} .option_groups textarea[data-key="${key}"]`
|
|
@@ -393,6 +420,39 @@ function createSettingsElement() {
|
|
|
393
420
|
break
|
|
394
421
|
}
|
|
395
422
|
|
|
423
|
+
case "select": {
|
|
424
|
+
const div = addElement(optionGroup, "div", {
|
|
425
|
+
class: "select_option bes_option",
|
|
426
|
+
"data-key": key,
|
|
427
|
+
})
|
|
428
|
+
if (item.icon) {
|
|
429
|
+
addElement(div, "img", { src: item.icon, class: "bes_icon" })
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
addElement(div, "span", {
|
|
433
|
+
textContent: item.title,
|
|
434
|
+
class: "bes_title",
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
const select = addElement(div, "select", {
|
|
438
|
+
class: "bes_select",
|
|
439
|
+
async onchange() {
|
|
440
|
+
await saveSettingsValue(key, select.value)
|
|
441
|
+
},
|
|
442
|
+
}) as HTMLSelectElement
|
|
443
|
+
|
|
444
|
+
for (const option of Object.entries(
|
|
445
|
+
(item as SettingsSelectItem).options
|
|
446
|
+
)) {
|
|
447
|
+
addElement(select, "option", {
|
|
448
|
+
textContent: option[0],
|
|
449
|
+
value: option[1],
|
|
450
|
+
})
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
break
|
|
454
|
+
}
|
|
455
|
+
|
|
396
456
|
case "tip": {
|
|
397
457
|
const tip = addElement(optionGroup, "div", {
|
|
398
458
|
class: "bes_tip",
|
|
@@ -455,7 +515,7 @@ function addSideMenu() {
|
|
|
455
515
|
addElement(menu, "button", {
|
|
456
516
|
type: "button",
|
|
457
517
|
"data-bes-version": besVersion,
|
|
458
|
-
title: "
|
|
518
|
+
title: i("settings.menu.settings"),
|
|
459
519
|
onclick() {
|
|
460
520
|
setTimeout(showSettings, 1)
|
|
461
521
|
},
|
|
@@ -477,7 +537,7 @@ function addCommonSettings(settingsTable: SettingsTable) {
|
|
|
477
537
|
}
|
|
478
538
|
|
|
479
539
|
settingsTable.displaySettingsButtonInSideMenu = {
|
|
480
|
-
title: "
|
|
540
|
+
title: i("settings.displaySettingsButtonInSideMenu"),
|
|
481
541
|
defaultValue: !(
|
|
482
542
|
typeof GM === "object" && typeof GM.registerMenuCommand === "function"
|
|
483
543
|
),
|
|
@@ -522,10 +582,12 @@ export const initSettings = async (options: SettingsOptions) => {
|
|
|
522
582
|
runWhenHeadExists(() => {
|
|
523
583
|
addStyle(getSettingsStyle())
|
|
524
584
|
})
|
|
525
|
-
|
|
585
|
+
runWhenDomReady(() => {
|
|
526
586
|
initExtensionList()
|
|
527
587
|
addSideMenu()
|
|
528
588
|
})
|
|
529
589
|
|
|
590
|
+
registerMenuCommand(i("settings.menu.settings"), showSettings, "o")
|
|
591
|
+
|
|
530
592
|
handleShowSettingsUrl()
|
|
531
593
|
}
|
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.5.0",
|
|
4
4
|
"description": "Settings module for developing browser extensions and userscripts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.ts",
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/utags/browser-extension-settings#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"browser-extension-i18n": "^0.0.4",
|
|
30
31
|
"browser-extension-storage": "^0.1.2",
|
|
31
|
-
"browser-extension-utils": "^0.1.
|
|
32
|
+
"browser-extension-utils": "^0.1.17"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/chrome": "^0.0.243",
|
|
@@ -56,6 +57,14 @@
|
|
|
56
57
|
"import/extensions": 0,
|
|
57
58
|
"@typescript-eslint/prefer-nullish-coalescing": 0,
|
|
58
59
|
"capitalized-comments": 0
|
|
59
|
-
}
|
|
60
|
+
},
|
|
61
|
+
"overrides": [
|
|
62
|
+
{
|
|
63
|
+
"files": "lib/messages/*.ts",
|
|
64
|
+
"rules": {
|
|
65
|
+
"@typescript-eslint/naming-convention": 0
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
]
|
|
60
69
|
}
|
|
61
70
|
}
|