browser-extension-settings 0.4.0 → 0.5.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 CHANGED
@@ -1,4 +1,4 @@
1
- export const besVersion = 40
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">
@@ -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: "🏷️ UTags - Add usertags to links",
30
- url: "https://greasyfork.org/zh-CN/scripts/460718-utags-add-usertags-to-links",
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: "https://greasyfork.org/zh-CN/scripts/464541-links-helper",
47
+ url: `https://greasyfork.org/${locale}/scripts/464541-links-helper`,
37
48
  },
38
49
  {
39
50
  id: "v2ex.rep",
40
- title: "V2EX.REP - 专注提升 V2EX 主题回复浏览体验",
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",
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 - V2EX 极简风格",
46
- url: "https://greasyfork.org/zh-CN/scripts/463552-v2ex-min-v2ex-%E6%9E%81%E7%AE%80%E9%A3%8E%E6%A0%BC",
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: "https://greasyfork.org/zh-CN/scripts/472616-replace-ugly-avatars",
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: "https://greasyfork.org/zh-CN/users/1030884-pipecraft",
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,8 @@
1
+ import { initI18n } from "browser-extension-i18n"
2
+ import messagesEn from "./en"
3
+ import messagesZh from "./zh-cn"
4
+
5
+ export const i = initI18n({
6
+ "en,en-US": messagesEn,
7
+ "zh,zh-CN": messagesZh,
8
+ })
@@ -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,6 +12,7 @@ import {
12
12
  createHTML,
13
13
  doc,
14
14
  parseInt10,
15
+ registerMenuCommand,
15
16
  removeEventListener,
16
17
  runWhenDomReady,
17
18
  runWhenHeadExists,
@@ -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
 
@@ -434,8 +436,7 @@ function createSettingsElement() {
434
436
 
435
437
  const select = addElement(div, "select", {
436
438
  class: "bes_select",
437
- onchange: async () => {
438
- console.log(select.value)
439
+ async onchange() {
439
440
  await saveSettingsValue(key, select.value)
440
441
  },
441
442
  }) as HTMLSelectElement
@@ -448,6 +449,7 @@ function createSettingsElement() {
448
449
  value: option[1],
449
450
  })
450
451
  }
452
+
451
453
  break
452
454
  }
453
455
 
@@ -513,7 +515,7 @@ function addSideMenu() {
513
515
  addElement(menu, "button", {
514
516
  type: "button",
515
517
  "data-bes-version": besVersion,
516
- title: "设置",
518
+ title: i("settings.menu.settings"),
517
519
  onclick() {
518
520
  setTimeout(showSettings, 1)
519
521
  },
@@ -535,7 +537,7 @@ function addCommonSettings(settingsTable: SettingsTable) {
535
537
  }
536
538
 
537
539
  settingsTable.displaySettingsButtonInSideMenu = {
538
- title: "Display Settings Button in Side Menu",
540
+ title: i("settings.displaySettingsButtonInSideMenu"),
539
541
  defaultValue: !(
540
542
  typeof GM === "object" && typeof GM.registerMenuCommand === "function"
541
543
  ),
@@ -585,5 +587,7 @@ export const initSettings = async (options: SettingsOptions) => {
585
587
  addSideMenu()
586
588
  })
587
589
 
590
+ registerMenuCommand(i("settings.menu.settings"), showSettings, "o")
591
+
588
592
  handleShowSettingsUrl()
589
593
  }
package/lib/style.scss CHANGED
@@ -296,8 +296,13 @@
296
296
  }
297
297
 
298
298
  pre {
299
- font-family: Consolas, panic sans, bitstream vera sans mono, Menlo,
300
- microsoft yahei, monospace;
299
+ font-family:
300
+ Consolas,
301
+ panic sans,
302
+ bitstream vera sans mono,
303
+ Menlo,
304
+ microsoft yahei,
305
+ monospace;
301
306
  font-size: 13px;
302
307
  letter-spacing: 0.015em;
303
308
  line-height: 120%;
@@ -360,7 +365,9 @@
360
365
  top: calc(50% - var(--toggle-diameter) / 2);
361
366
  border-radius: 50%;
362
367
  background: #ffffff;
363
- box-shadow: 0px 3px 8px rgba(0, 0, 0, 0.15), 0px 3px 1px rgba(0, 0, 0, 0.06);
368
+ box-shadow:
369
+ 0px 3px 8px rgba(0, 0, 0, 0.15),
370
+ 0px 3px 1px rgba(0, 0, 0, 0.06);
364
371
  transition: all 0.2s ease-out;
365
372
  cursor: pointer;
366
373
  }
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "browser-extension-settings",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Settings module for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.ts",
7
+ "exports": {
8
+ ".": "./lib/index.js"
9
+ },
7
10
  "scripts": {
8
11
  "p": "prettier --write .",
9
12
  "lint": "run-s lint:*",
@@ -27,15 +30,16 @@
27
30
  },
28
31
  "homepage": "https://github.com/utags/browser-extension-settings#readme",
29
32
  "dependencies": {
33
+ "browser-extension-i18n": "^0.0.5",
30
34
  "browser-extension-storage": "^0.1.2",
31
35
  "browser-extension-utils": "^0.1.17"
32
36
  },
33
37
  "devDependencies": {
34
38
  "@types/chrome": "^0.0.243",
35
39
  "npm-run-all": "^4.1.5",
36
- "prettier": "^2.8.8",
40
+ "prettier": "^3.0.2",
37
41
  "typescript": "^5.1.6",
38
- "xo": "^0.55.0"
42
+ "xo": "^0.56.0"
39
43
  },
40
44
  "files": [
41
45
  "lib/",
@@ -56,6 +60,14 @@
56
60
  "import/extensions": 0,
57
61
  "@typescript-eslint/prefer-nullish-coalescing": 0,
58
62
  "capitalized-comments": 0
59
- }
63
+ },
64
+ "overrides": [
65
+ {
66
+ "files": "lib/messages/*.ts",
67
+ "rules": {
68
+ "@typescript-eslint/naming-convention": 0
69
+ }
70
+ }
71
+ ]
60
72
  }
61
73
  }