browser-extension-settings 0.0.4 → 0.0.5

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 CHANGED
@@ -1,3 +1,3 @@
1
- export const version = 11
1
+ export const besVersion = 12
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>`
@@ -99,6 +99,20 @@ export const activeExtension = (id: string) => {
99
99
  }
100
100
  }
101
101
 
102
+ export const activeExtensionList = () => {
103
+ const extensionListContainer = $(".extension_list_container")
104
+ if (extensionListContainer) {
105
+ addClass(extensionListContainer, "bes_active")
106
+ }
107
+ }
108
+
109
+ export const deactiveExtensionList = () => {
110
+ const extensionListContainer = $(".extension_list_container")
111
+ if (extensionListContainer) {
112
+ removeClass(extensionListContainer, "bes_active")
113
+ }
114
+ }
115
+
102
116
  const createInstalledExtension = (installedExtension: InstalledExtension) => {
103
117
  const div = createElement("div", {
104
118
  class: "installed_extension",
@@ -120,7 +134,7 @@ const updateRelatedExtensions = (container: HTMLElement) => {
120
134
  container.innerHTML = ""
121
135
 
122
136
  for (const relatedExtension of relatedExtensions) {
123
- console.log(relatedExtension)
137
+ // console.log(relatedExtension)
124
138
 
125
139
  if (isInstalledExtension(relatedExtension.id)) {
126
140
  continue
@@ -154,7 +168,7 @@ export function createExtensionList(installedExtensions: InstalledExtension[]) {
154
168
  class: "installed_extension_list",
155
169
  })
156
170
  for (const installedExtension of installedExtensions) {
157
- console.log(installedExtension)
171
+ // console.log(installedExtension)
158
172
 
159
173
  if (isInstalledExtension(installedExtension.id)) {
160
174
  continue
package/lib/settings.ts CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  import {
7
7
  $,
8
8
  $$,
9
+ addClass,
9
10
  addElement,
10
11
  addEventListener,
11
12
  addStyle,
@@ -19,8 +20,10 @@ import {
19
20
  createExtensionList,
20
21
  addCurrentExtension,
21
22
  activeExtension,
23
+ activeExtensionList,
24
+ deactiveExtensionList,
22
25
  } from "./extension-list"
23
- import { version } from "./common"
26
+ import { besVersion } from "./common"
24
27
 
25
28
  const prefix = "browser_extension_settings_"
26
29
 
@@ -94,7 +97,17 @@ export function getSettingsValue(key: string): boolean | string | undefined {
94
97
  : settingsTable[key]?.defaultValue
95
98
  }
96
99
 
97
- const modalHandler = (event) => {
100
+ const closeModal = () => {
101
+ const settingsContainer = getSettingsContainer()
102
+ if (settingsContainer) {
103
+ settingsContainer.style.display = "none"
104
+ }
105
+
106
+ removeEventListener(document, "click", onDocumentClick)
107
+ removeEventListener(document, "keydown", onDocumentKeyDown)
108
+ }
109
+
110
+ const onDocumentClick = (event) => {
98
111
  let target = event.target as HTMLElement
99
112
  const settingsContainer = getSettingsContainer()
100
113
  if (settingsContainer) {
@@ -105,11 +118,30 @@ const modalHandler = (event) => {
105
118
  if (target === settingsContainer) {
106
119
  return
107
120
  }
121
+ }
122
+
123
+ closeModal()
124
+ }
125
+
126
+ const onDocumentKeyDown = (event) => {
127
+ if (event.defaultPrevented) {
128
+ return // 如果事件已经在进行中,则不做任何事。
129
+ }
130
+
131
+ switch (event.key) {
132
+ case "Escape": {
133
+ // 按“ESC”键时要做的事。
134
+ closeModal()
135
+ break
136
+ }
108
137
 
109
- settingsContainer.style.display = "none"
138
+ default: {
139
+ return
140
+ } // 什么都没按就退出吧。
110
141
  }
111
142
 
112
- removeEventListener(document, "click", modalHandler)
143
+ // 取消默认动作,从而避免处理两次。
144
+ event.preventDefault()
113
145
  }
114
146
 
115
147
  async function updateOptions() {
@@ -148,9 +180,9 @@ function getSettingsContainer() {
148
180
  const container = $(`.${prefix}container`)
149
181
  if (container) {
150
182
  const theVersion = Number.parseInt(container.dataset.besVersion || "0", 10)
151
- if (theVersion < version) {
183
+ if (theVersion < besVersion) {
152
184
  container.id = settingsContainerId
153
- container.dataset.besVersion = String(version)
185
+ container.dataset.besVersion = String(besVersion)
154
186
  }
155
187
 
156
188
  return container
@@ -159,7 +191,7 @@ function getSettingsContainer() {
159
191
  return addElement(doc.body, "div", {
160
192
  id: settingsContainerId,
161
193
  class: `${prefix}container`,
162
- "data-bes-version": version,
194
+ "data-bes-version": besVersion,
163
195
  })
164
196
  }
165
197
 
@@ -209,7 +241,7 @@ function createSettingsElement() {
209
241
  textContent: "Settings",
210
242
  class: "navigation_go_previous",
211
243
  onclick() {
212
- console.log(1)
244
+ activeExtensionList()
213
245
  },
214
246
  })
215
247
 
@@ -306,14 +338,14 @@ function addSideMenu() {
306
338
  $("#browser_extension_side_menu") ||
307
339
  addElement(doc.body, "div", {
308
340
  id: "browser_extension_side_menu",
309
- "data-bes-version": version,
341
+ "data-bes-version": besVersion,
310
342
  })
311
343
 
312
344
  const button = $("button[data-bes-version]", menu)
313
345
 
314
346
  if (button) {
315
347
  const theVersion = Number.parseInt(button.dataset.besVersion || "0", 10)
316
- if (theVersion >= version) {
348
+ if (theVersion >= besVersion) {
317
349
  return
318
350
  }
319
351
 
@@ -322,7 +354,7 @@ function addSideMenu() {
322
354
 
323
355
  addElement(menu, "button", {
324
356
  type: "button",
325
- "data-bes-version": version,
357
+ "data-bes-version": besVersion,
326
358
  title: "设置",
327
359
  onclick() {
328
360
  setTimeout(showSettings, 1)
@@ -337,8 +369,10 @@ export async function showSettings() {
337
369
  await updateOptions()
338
370
  settingsContainer.style.display = "block"
339
371
 
340
- addEventListener(document, "click", modalHandler)
372
+ addEventListener(document, "click", onDocumentClick)
373
+ addEventListener(document, "keydown", onDocumentKeyDown)
341
374
  activeExtension(settingsOptions.id)
375
+ deactiveExtensionList()
342
376
  }
343
377
 
344
378
  export const initSettings = async (options: SettingsOptions) => {
package/lib/style.scss CHANGED
@@ -187,6 +187,7 @@
187
187
  }
188
188
 
189
189
  .option_groups textarea {
190
+ font-size: 12px;
190
191
  margin: 10px 0 10px 0;
191
192
  height: 100px;
192
193
  width: 100%;
@@ -359,3 +360,25 @@
359
360
  #browser_extension_side_menu button:active {
360
361
  opacity: 100%;
361
362
  }
363
+
364
+ @media (max-width: 500px) {
365
+ #browser_extension_settings_container {
366
+ right: 10px;
367
+
368
+ .extension_list_container {
369
+ display: none;
370
+ }
371
+ .extension_list_container.bes_active {
372
+ display: block;
373
+ }
374
+ .extension_list_container.bes_active + div {
375
+ display: none;
376
+ }
377
+ }
378
+
379
+ #browser_extension_settings_main {
380
+ a.navigation_go_previous {
381
+ display: block;
382
+ }
383
+ }
384
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-settings",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Settings module for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.ts",