Skip to content

Commit e36fda7

Browse files
committed
refactor settings menu
1 parent 7f0fac4 commit e36fda7

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

src/settings.ts

+4-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Store, { to, from } from './store'
2-
import type { IStore } from './store'
1+
import Store, { configFields } from './store'
2+
import type { ValuesStore } from './store'
33

44
GM_config.init({
55
id: 'Options',
@@ -12,41 +12,13 @@ GM_config.init({
1212
// @ts-ignore
1313
arr[id] = value
1414
return arr
15-
}, {} as IStore)
15+
}, {} as ValuesStore)
1616

1717
Store.write(options)
1818
},
1919
reset: () => Store.write()
2020
},
21-
fields: {
22-
enabled: {
23-
type: 'checkbox',
24-
default: true,
25-
label: 'Вкл/Выкл расширения'
26-
},
27-
clipboard: {
28-
type: 'checkbox',
29-
default: true,
30-
label: 'Копировать текст сообщения (оригинал/перевод)'
31-
},
32-
self: {
33-
type: 'checkbox',
34-
default: false,
35-
label: 'Переводить собственные сообщения'
36-
},
37-
from: {
38-
type: 'select',
39-
options: from,
40-
default: 'en',
41-
label: 'Переводить из'
42-
},
43-
to: {
44-
type: 'select',
45-
options: to,
46-
default: 'ru',
47-
label: 'Переводить в'
48-
}
49-
}
21+
fields: configFields
5022
})
5123

5224
GM_registerMenuCommand('Настройки', () => {

src/store.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,52 @@ export const from = ['en', 'ru', 'kk', 'uk', 'ja', 'auto'] as const
4343
type ToLangs = typeof to[number]
4444
type FromLangs = typeof from[number]
4545

46-
export interface IStore {
46+
export interface ValuesStore {
4747
to: ToLangs
4848
from: FromLangs
4949
self: boolean
5050
enabled: boolean
5151
clipboard: boolean
5252
}
5353

54-
const initialStore: IStore = {
54+
const initialStore: ValuesStore = {
5555
to: to[1],
5656
from: to[0],
5757
self: false,
5858
enabled: true,
5959
clipboard: true
6060
}
6161

62+
export const configFields: Record<string, Field> = {
63+
enabled: {
64+
type: 'checkbox',
65+
default: initialStore.enabled,
66+
label: 'Вкл/Выкл перевод'
67+
},
68+
clipboard: {
69+
type: 'checkbox',
70+
default: initialStore.clipboard,
71+
label: 'Копировать текст сообщения (оригинал/перевод)'
72+
},
73+
self: {
74+
type: 'checkbox',
75+
default: initialStore.self,
76+
label: 'Переводить собственные сообщения'
77+
},
78+
from: {
79+
type: 'select',
80+
options: from,
81+
default: 'en',
82+
label: 'Переводить из'
83+
},
84+
to: {
85+
type: 'select',
86+
options: to,
87+
default: 'ru',
88+
label: 'Переводить в'
89+
}
90+
}
91+
6292
export default new Store(
6393
'twitch-chat-translation',
6494
initialStore

0 commit comments

Comments
 (0)