browser-extension-settings 0.0.5 → 0.0.7
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 +33 -41
- package/package.json +1 -1
package/lib/common.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const besVersion =
|
|
1
|
+
export const besVersion = 13
|
|
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>`
|
package/lib/settings.ts
CHANGED
|
@@ -67,7 +67,7 @@ const settingsContainerId = prefix + "container_" + randomId
|
|
|
67
67
|
const settingsElementId = prefix + "main_" + randomId
|
|
68
68
|
const getSettingsElement = () => $("#" + settingsElementId)
|
|
69
69
|
const getSettingsStyle: () => string = () =>
|
|
70
|
-
styleText
|
|
70
|
+
(styleText as string)
|
|
71
71
|
.replace(/browser_extension_settings_container/gm, settingsContainerId)
|
|
72
72
|
.replace(/browser_extension_settings_main/gm, settingsElementId)
|
|
73
73
|
const storageKey = "settings"
|
|
@@ -103,45 +103,30 @@ const closeModal = () => {
|
|
|
103
103
|
settingsContainer.style.display = "none"
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
removeEventListener(document, "click", onDocumentClick)
|
|
107
|
-
removeEventListener(document, "keydown", onDocumentKeyDown)
|
|
106
|
+
removeEventListener(document, "click", onDocumentClick, true)
|
|
107
|
+
removeEventListener(document, "keydown", onDocumentKeyDown, true)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const onDocumentClick = (event) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
while (target !== settingsContainer && target) {
|
|
115
|
-
target = target.parentNode as HTMLElement
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (target === settingsContainer) {
|
|
119
|
-
return
|
|
120
|
-
}
|
|
110
|
+
const onDocumentClick = (event: Event) => {
|
|
111
|
+
const target = event.target as HTMLElement
|
|
112
|
+
if (target?.closest(`.${prefix}container`)) {
|
|
113
|
+
return
|
|
121
114
|
}
|
|
122
115
|
|
|
123
116
|
closeModal()
|
|
124
117
|
}
|
|
125
118
|
|
|
126
|
-
const onDocumentKeyDown = (event) => {
|
|
119
|
+
const onDocumentKeyDown = (event: KeyboardEvent) => {
|
|
127
120
|
if (event.defaultPrevented) {
|
|
128
121
|
return // 如果事件已经在进行中,则不做任何事。
|
|
129
122
|
}
|
|
130
123
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
default: {
|
|
139
|
-
return
|
|
140
|
-
} // 什么都没按就退出吧。
|
|
124
|
+
if (event.key === "Escape") {
|
|
125
|
+
// 按“ESC”键时要做的事。
|
|
126
|
+
closeModal()
|
|
127
|
+
// 取消默认动作,从而避免处理两次。
|
|
128
|
+
event.preventDefault()
|
|
141
129
|
}
|
|
142
|
-
|
|
143
|
-
// 取消默认动作,从而避免处理两次。
|
|
144
|
-
event.preventDefault()
|
|
145
130
|
}
|
|
146
131
|
|
|
147
132
|
async function updateOptions() {
|
|
@@ -192,13 +177,15 @@ function getSettingsContainer() {
|
|
|
192
177
|
id: settingsContainerId,
|
|
193
178
|
class: `${prefix}container`,
|
|
194
179
|
"data-bes-version": besVersion,
|
|
180
|
+
style: "display: none;",
|
|
195
181
|
})
|
|
196
182
|
}
|
|
197
183
|
|
|
198
184
|
function getSettingsWrapper() {
|
|
185
|
+
const container = getSettingsContainer()
|
|
199
186
|
return (
|
|
200
|
-
$(`.${prefix}container
|
|
201
|
-
addElement(
|
|
187
|
+
$(`.${prefix}wrapper`, container) ||
|
|
188
|
+
addElement(container, "div", {
|
|
202
189
|
class: `${prefix}wrapper`,
|
|
203
190
|
})
|
|
204
191
|
)
|
|
@@ -255,8 +242,10 @@ function createSettingsElement() {
|
|
|
255
242
|
const item = settingsTable[key]
|
|
256
243
|
if (!item.type || item.type === "switch") {
|
|
257
244
|
const switchOption = createSwitchOption(item.title, {
|
|
258
|
-
async onchange(event) {
|
|
259
|
-
|
|
245
|
+
async onchange(event: Event) {
|
|
246
|
+
if (event.target) {
|
|
247
|
+
await saveSattingsValue(key, event.target.checked)
|
|
248
|
+
}
|
|
260
249
|
},
|
|
261
250
|
})
|
|
262
251
|
|
|
@@ -270,21 +259,24 @@ function createSettingsElement() {
|
|
|
270
259
|
const options2 = addElement(settingsMain, "div", {
|
|
271
260
|
class: "option_groups",
|
|
272
261
|
})
|
|
273
|
-
let timeoutId
|
|
262
|
+
let timeoutId: number | undefined
|
|
274
263
|
addElement(options2, "textarea", {
|
|
275
264
|
placeholder: `/* Custom rules for internal URLs, matching URLs will be opened in new tabs */`,
|
|
276
|
-
onkeyup(event) {
|
|
265
|
+
onkeyup(event: Event) {
|
|
266
|
+
const textArea = event.target as HTMLTextAreaElement
|
|
277
267
|
if (timeoutId) {
|
|
278
268
|
clearTimeout(timeoutId)
|
|
279
|
-
timeoutId =
|
|
269
|
+
timeoutId = undefined
|
|
280
270
|
}
|
|
281
271
|
|
|
282
272
|
timeoutId = setTimeout(async () => {
|
|
283
273
|
const host = location.host
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
274
|
+
if (textArea) {
|
|
275
|
+
await saveSattingsValue(
|
|
276
|
+
`customRulesForCurrentSite_${host}`,
|
|
277
|
+
textArea.value.trim()
|
|
278
|
+
)
|
|
279
|
+
}
|
|
288
280
|
}, 100)
|
|
289
281
|
},
|
|
290
282
|
})
|
|
@@ -369,8 +361,8 @@ export async function showSettings() {
|
|
|
369
361
|
await updateOptions()
|
|
370
362
|
settingsContainer.style.display = "block"
|
|
371
363
|
|
|
372
|
-
addEventListener(document, "click", onDocumentClick)
|
|
373
|
-
addEventListener(document, "keydown", onDocumentKeyDown)
|
|
364
|
+
addEventListener(document, "click", onDocumentClick, true)
|
|
365
|
+
addEventListener(document, "keydown", onDocumentKeyDown, true)
|
|
374
366
|
activeExtension(settingsOptions.id)
|
|
375
367
|
deactiveExtensionList()
|
|
376
368
|
}
|