browser-extension-settings 0.0.6 → 0.0.8
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 +17 -33
- package/package.json +2 -2
package/lib/common.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const besVersion =
|
|
1
|
+
export const besVersion = 14
|
|
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
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
$,
|
|
8
8
|
$$,
|
|
9
|
-
addClass,
|
|
10
9
|
addElement,
|
|
11
10
|
addEventListener,
|
|
12
11
|
addStyle,
|
|
13
|
-
createElement,
|
|
14
12
|
doc,
|
|
13
|
+
parseInt10,
|
|
15
14
|
removeEventListener,
|
|
15
|
+
runWhenBodyExists,
|
|
16
16
|
} from "browser-extension-utils"
|
|
17
17
|
import styleText from "data-text:./style.scss"
|
|
18
18
|
import { createSwitchOption } from "./switch"
|
|
@@ -103,8 +103,8 @@ 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
110
|
const onDocumentClick = (event: Event) => {
|
|
@@ -121,20 +121,12 @@ const onDocumentKeyDown = (event: KeyboardEvent) => {
|
|
|
121
121
|
return // 如果事件已经在进行中,则不做任何事。
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
default: {
|
|
132
|
-
return
|
|
133
|
-
} // 什么都没按就退出吧。
|
|
124
|
+
if (event.key === "Escape") {
|
|
125
|
+
// 按“ESC”键时要做的事。
|
|
126
|
+
closeModal()
|
|
127
|
+
// 取消默认动作,从而避免处理两次。
|
|
128
|
+
event.preventDefault()
|
|
134
129
|
}
|
|
135
|
-
|
|
136
|
-
// 取消默认动作,从而避免处理两次。
|
|
137
|
-
event.preventDefault()
|
|
138
130
|
}
|
|
139
131
|
|
|
140
132
|
async function updateOptions() {
|
|
@@ -172,7 +164,7 @@ async function updateOptions() {
|
|
|
172
164
|
function getSettingsContainer() {
|
|
173
165
|
const container = $(`.${prefix}container`)
|
|
174
166
|
if (container) {
|
|
175
|
-
const theVersion =
|
|
167
|
+
const theVersion = parseInt10(container.dataset.besVersion, 0)
|
|
176
168
|
if (theVersion < besVersion) {
|
|
177
169
|
container.id = settingsContainerId
|
|
178
170
|
container.dataset.besVersion = String(besVersion)
|
|
@@ -200,11 +192,6 @@ function getSettingsWrapper() {
|
|
|
200
192
|
}
|
|
201
193
|
|
|
202
194
|
function initExtensionList() {
|
|
203
|
-
if (!doc.body) {
|
|
204
|
-
setTimeout(initExtensionList, 100)
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
|
|
208
195
|
const wrapper = getSettingsWrapper()
|
|
209
196
|
if (!$(".extension_list_container", wrapper)) {
|
|
210
197
|
const list = createExtensionList([])
|
|
@@ -329,11 +316,6 @@ function createSettingsElement() {
|
|
|
329
316
|
}
|
|
330
317
|
|
|
331
318
|
function addSideMenu() {
|
|
332
|
-
if (!doc.body) {
|
|
333
|
-
setTimeout(addSideMenu, 100)
|
|
334
|
-
return
|
|
335
|
-
}
|
|
336
|
-
|
|
337
319
|
const menu =
|
|
338
320
|
$("#browser_extension_side_menu") ||
|
|
339
321
|
addElement(doc.body, "div", {
|
|
@@ -344,7 +326,7 @@ function addSideMenu() {
|
|
|
344
326
|
const button = $("button[data-bes-version]", menu)
|
|
345
327
|
|
|
346
328
|
if (button) {
|
|
347
|
-
const theVersion =
|
|
329
|
+
const theVersion = parseInt10(button.dataset.besVersion, 0)
|
|
348
330
|
if (theVersion >= besVersion) {
|
|
349
331
|
return
|
|
350
332
|
}
|
|
@@ -369,8 +351,8 @@ export async function showSettings() {
|
|
|
369
351
|
await updateOptions()
|
|
370
352
|
settingsContainer.style.display = "block"
|
|
371
353
|
|
|
372
|
-
addEventListener(document, "click", onDocumentClick)
|
|
373
|
-
addEventListener(document, "keydown", onDocumentKeyDown)
|
|
354
|
+
addEventListener(document, "click", onDocumentClick, true)
|
|
355
|
+
addEventListener(document, "keydown", onDocumentKeyDown, true)
|
|
374
356
|
activeExtension(settingsOptions.id)
|
|
375
357
|
deactiveExtensionList()
|
|
376
358
|
}
|
|
@@ -388,6 +370,8 @@ export const initSettings = async (options: SettingsOptions) => {
|
|
|
388
370
|
|
|
389
371
|
settings = await getSettings()
|
|
390
372
|
addStyle(getSettingsStyle())
|
|
391
|
-
|
|
392
|
-
|
|
373
|
+
runWhenBodyExists(() => {
|
|
374
|
+
initExtensionList()
|
|
375
|
+
addSideMenu()
|
|
376
|
+
})
|
|
393
377
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-extension-settings",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Settings module for developing browser extensions and userscripts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"homepage": "https://github.com/utags/browser-extension-settings#readme",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"browser-extension-storage": "^0.1.2",
|
|
29
|
-
"browser-extension-utils": "^0.1.
|
|
29
|
+
"browser-extension-utils": "^0.1.7"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/chrome": "^0.0.237",
|