browser-extension-settings 0.7.0 → 0.8.0
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 +2 -2
- package/lib/settings.ts +17 -12
- package/lib/style.scss +25 -11
- package/package.json +6 -6
package/lib/common.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Version 0.
|
|
2
|
-
export const besVersion =
|
|
1
|
+
// Version 0.8.0
|
|
2
|
+
export const besVersion = 80
|
|
3
3
|
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>`
|
|
4
4
|
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>`
|
|
5
5
|
export const settingButton = `<svg viewBox="0 0 16 16" version="1.1">
|
package/lib/settings.ts
CHANGED
|
@@ -168,7 +168,6 @@ export function getSettingsValue(key: string): boolean | string | undefined {
|
|
|
168
168
|
const closeModal = () => {
|
|
169
169
|
const settingsContainer = getSettingsContainer()
|
|
170
170
|
if (settingsContainer) {
|
|
171
|
-
settingsContainer.style.display = "none"
|
|
172
171
|
settingsContainer.remove()
|
|
173
172
|
}
|
|
174
173
|
|
|
@@ -188,11 +187,8 @@ export function hideSettings() {
|
|
|
188
187
|
|
|
189
188
|
function isSettingsShown() {
|
|
190
189
|
const settingsContainer = $(`.${prefix}container`)
|
|
191
|
-
if (settingsContainer) {
|
|
192
|
-
return settingsContainer.style.display === "block"
|
|
193
|
-
}
|
|
194
190
|
|
|
195
|
-
return
|
|
191
|
+
return Boolean(settingsContainer)
|
|
196
192
|
}
|
|
197
193
|
|
|
198
194
|
const onDocumentClick = (event: Event) => {
|
|
@@ -301,10 +297,9 @@ function getSettingsContainer(create = false) {
|
|
|
301
297
|
}
|
|
302
298
|
|
|
303
299
|
if (create) {
|
|
304
|
-
return addElement(doc.
|
|
300
|
+
return addElement(doc.documentElement, "div", {
|
|
305
301
|
class: `${prefix}container`,
|
|
306
302
|
"data-bes-version": besVersion,
|
|
307
|
-
style: "display: none;",
|
|
308
303
|
})
|
|
309
304
|
}
|
|
310
305
|
}
|
|
@@ -357,6 +352,18 @@ function createSettingsElement() {
|
|
|
357
352
|
class: `${prefix}main thin_scrollbar`,
|
|
358
353
|
})
|
|
359
354
|
|
|
355
|
+
const header = addElement(settingsMain, "header", {
|
|
356
|
+
style: "display: flex; justify-content: flex-end;",
|
|
357
|
+
})
|
|
358
|
+
addElement(header, "div", {
|
|
359
|
+
class: `close-button`,
|
|
360
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
361
|
+
innerHTML: createHTML(
|
|
362
|
+
`<svg viewBox="0 0 24 24" width="100%" height="100%" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>`
|
|
363
|
+
),
|
|
364
|
+
onclick: hideSettings,
|
|
365
|
+
})
|
|
366
|
+
|
|
360
367
|
if (settingsOptions.title) {
|
|
361
368
|
addElement(settingsMain, "h2", { textContent: settingsOptions.title })
|
|
362
369
|
}
|
|
@@ -587,16 +594,14 @@ export async function showSettings() {
|
|
|
587
594
|
closeModal()
|
|
588
595
|
|
|
589
596
|
const event = new CustomEvent("beforeShowSettings")
|
|
597
|
+
// Dispatch beforeShowSettings event to close other extension's settings
|
|
590
598
|
globalThis.dispatchEvent(event)
|
|
591
599
|
|
|
592
600
|
// Listen to beforeShowSettings event to close opened modal before showing settings from other extension
|
|
593
601
|
addEventListener(globalThis, "beforeShowSettings", onBeforeShowSettings, true)
|
|
594
602
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const settingsMain = createSettingsElement()
|
|
603
|
+
createSettingsElement()
|
|
598
604
|
await updateOptions()
|
|
599
|
-
settingsContainer.style.display = "block"
|
|
600
605
|
|
|
601
606
|
addEventListener(document, "click", onDocumentClick, true)
|
|
602
607
|
addEventListener(document, "keydown", onDocumentKeyDown, true)
|
|
@@ -648,7 +653,7 @@ export const initSettings = async (optionsProvider: () => SettingsOptions) => {
|
|
|
648
653
|
|
|
649
654
|
const newLocale =
|
|
650
655
|
(getSettingsValue("locale") as string | undefined) || getPrefferedLocale()
|
|
651
|
-
console.log("lastLocale:", lastLocale, "newLocale:", newLocale)
|
|
656
|
+
// console.log("lastLocale:", lastLocale, "newLocale:", newLocale)
|
|
652
657
|
if (lastLocale !== newLocale) {
|
|
653
658
|
const isShown = isSettingsShown()
|
|
654
659
|
closeModal()
|
package/lib/style.scss
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
:host {
|
|
2
|
+
all: initial;
|
|
2
3
|
--browser-extension-settings-background-color: #f2f2f7;
|
|
3
4
|
--browser-extension-settings-text-color: #444444;
|
|
4
5
|
--browser-extension-settings-link-color: #217dfc;
|
|
6
|
+
--browser-extension-settings-border-radius: 8px;
|
|
5
7
|
--sb-track-color: #00000000;
|
|
6
8
|
--sb-thumb-color: #33334480;
|
|
7
9
|
--sb-size: 2px;
|
|
8
10
|
--font-family: "helvetica neue", "microsoft yahei", arial, sans-serif;
|
|
9
11
|
|
|
10
|
-
position: fixed;
|
|
11
|
-
top: 10px;
|
|
12
|
-
right: 30px;
|
|
13
|
-
display: none;
|
|
14
|
-
|
|
15
|
-
z-index: 200000;
|
|
16
|
-
border-radius: 5px;
|
|
17
|
-
-webkit-box-shadow: 0px 10px 39px 10px rgba(62, 66, 66, 0.22);
|
|
18
|
-
-moz-box-shadow: 0px 10px 39px 10px rgba(62, 66, 66, 0.22);
|
|
19
|
-
box-shadow: 0px 10px 39px 10px rgba(62, 66, 66, 0.22) !important;
|
|
20
|
-
|
|
21
12
|
.browser_extension_settings_v2_wrapper {
|
|
13
|
+
position: fixed;
|
|
14
|
+
top: 10px;
|
|
15
|
+
right: 30px;
|
|
16
|
+
display: none;
|
|
17
|
+
z-index: 2147483647;
|
|
18
|
+
border-radius: var(--browser-extension-settings-border-radius);
|
|
19
|
+
-webkit-box-shadow: 0px 10px 39px 10px rgba(62, 66, 66, 0.22);
|
|
20
|
+
-moz-box-shadow: 0px 10px 39px 10px rgba(62, 66, 66, 0.22);
|
|
21
|
+
box-shadow: 0px 10px 39px 10px rgba(62, 66, 66, 0.22) !important;
|
|
22
22
|
display: flex;
|
|
23
23
|
background-color: var(--browser-extension-settings-background-color);
|
|
24
24
|
font-family: var(--font-family);
|
|
25
|
+
border-radius: var(--browser-extension-settings-border-radius);
|
|
25
26
|
|
|
26
27
|
h1,
|
|
27
28
|
h2 {
|
|
@@ -100,6 +101,7 @@
|
|
|
100
101
|
max-height: 90vh;
|
|
101
102
|
overflow-y: auto;
|
|
102
103
|
overflow-x: hidden;
|
|
104
|
+
border-radius: var(--browser-extension-settings-border-radius);
|
|
103
105
|
|
|
104
106
|
box-sizing: border-box;
|
|
105
107
|
padding: 10px 15px;
|
|
@@ -112,6 +114,18 @@
|
|
|
112
114
|
margin: 5px 0 0;
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
.close-button {
|
|
118
|
+
cursor: pointer;
|
|
119
|
+
width: 18px;
|
|
120
|
+
height: 18px;
|
|
121
|
+
opacity: 0.5;
|
|
122
|
+
transition: opacity 0.2s;
|
|
123
|
+
|
|
124
|
+
&:hover {
|
|
125
|
+
opacity: 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
115
129
|
.option_groups {
|
|
116
130
|
background-color: #fff;
|
|
117
131
|
padding: 6px 15px 6px 15px;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-extension-settings",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Settings module for developing browser extensions and userscripts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.ts",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"browser-extension-utils": "^0.2.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/chrome": "^0.1.
|
|
39
|
-
"@vitest/coverage-v8": "^4.0.
|
|
40
|
-
"jsdom": "^27.
|
|
38
|
+
"@types/chrome": "^0.1.32",
|
|
39
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
40
|
+
"jsdom": "^27.3.0",
|
|
41
41
|
"npm-run-all": "^4.1.5",
|
|
42
|
-
"prettier": "^3.
|
|
42
|
+
"prettier": "^3.7.4",
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
|
-
"vitest": "^4.0.
|
|
44
|
+
"vitest": "^4.0.16",
|
|
45
45
|
"xo": "^1.2.3"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|