browser-extension-settings 0.2.10 → 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/common.ts +1 -1
- package/lib/extension-list.ts +37 -6
- 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/common.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const besVersion =
|
|
1
|
+
export const besVersion = 30
|
|
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
|
@@ -27,23 +27,33 @@ const relatedExtensions: RelatedExtension[] = [
|
|
|
27
27
|
{
|
|
28
28
|
id: "utags",
|
|
29
29
|
title: "🏷️ UTags - Add usertags to links",
|
|
30
|
-
url: "https://greasyfork.org/scripts/460718",
|
|
30
|
+
url: "https://greasyfork.org/zh-CN/scripts/460718-utags-add-usertags-to-links",
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
id: "links-helper",
|
|
34
34
|
title: "🔗 链接助手",
|
|
35
35
|
description: "在新标签页中打开第三方网站链接,图片链接转图片标签等",
|
|
36
|
-
url: "https://greasyfork.org/scripts/464541",
|
|
36
|
+
url: "https://greasyfork.org/zh-CN/scripts/464541-links-helper",
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
39
|
id: "v2ex.rep",
|
|
40
40
|
title: "V2EX.REP - 专注提升 V2EX 主题回复浏览体验",
|
|
41
|
-
url: "https://greasyfork.org/scripts/466589",
|
|
41
|
+
url: "https://greasyfork.org/zh-CN/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
42
|
},
|
|
43
43
|
{
|
|
44
44
|
id: "v2ex.min",
|
|
45
45
|
title: "v2ex.min - V2EX 极简风格",
|
|
46
|
-
url: "https://greasyfork.org/scripts/463552",
|
|
46
|
+
url: "https://greasyfork.org/zh-CN/scripts/463552-v2ex-min-v2ex-%E6%9E%81%E7%AE%80%E9%A3%8E%E6%A0%BC",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "replace-ugly-avatars",
|
|
50
|
+
title: "赐你个头像吧",
|
|
51
|
+
url: "https://greasyfork.org/zh-CN/scripts/472616-replace-ugly-avatars",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "more-by-pipecraft",
|
|
55
|
+
title: "更多有趣的脚本",
|
|
56
|
+
url: "https://greasyfork.org/zh-CN/users/1030884-pipecraft",
|
|
47
57
|
},
|
|
48
58
|
]
|
|
49
59
|
|
|
@@ -132,17 +142,38 @@ const createInstalledExtension = (installedExtension: InstalledExtension) => {
|
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
const updateRelatedExtensions = (container: HTMLElement) => {
|
|
135
|
-
|
|
145
|
+
const relatedExtensionElements = $$("[data-extension-id]", container)
|
|
146
|
+
if (relatedExtensionElements.length > 0) {
|
|
147
|
+
for (const relatedExtensionElement of relatedExtensionElements) {
|
|
148
|
+
if (
|
|
149
|
+
isInstalledExtension(
|
|
150
|
+
relatedExtensionElement.dataset.extensionId || "noid"
|
|
151
|
+
)
|
|
152
|
+
) {
|
|
153
|
+
relatedExtensionElement.remove()
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
container.innerHTML = createHTML("")
|
|
158
|
+
}
|
|
136
159
|
|
|
137
160
|
for (const relatedExtension of relatedExtensions) {
|
|
138
161
|
// console.log(relatedExtension)
|
|
139
162
|
|
|
140
|
-
if (
|
|
163
|
+
if (
|
|
164
|
+
isInstalledExtension(relatedExtension.id) ||
|
|
165
|
+
$(`[data-extension-id="${relatedExtension.id}"]`, container)
|
|
166
|
+
) {
|
|
141
167
|
continue
|
|
142
168
|
}
|
|
143
169
|
|
|
170
|
+
if ($$("[data-extension-id]", container).length >= 4) {
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
|
|
144
174
|
const div4 = addElement(container, "div", {
|
|
145
175
|
class: "related_extension",
|
|
176
|
+
"data-extension-id": relatedExtension.id,
|
|
146
177
|
})
|
|
147
178
|
|
|
148
179
|
const a = addElement(div4, "a", {
|
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
|