Skip to content

Commit 55bcbf4

Browse files
committed
refactor: ♻️ 将站点无关的存储数据名改成 @ 开头
1 parent 0e35c97 commit 55bcbf4

5 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/helper/languages.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const getBrowserLang = () => {
1616

1717
const getSaveLang = () =>
1818
typeof GM === 'undefined'
19-
? localStorage.getItem('Languages')
20-
: GM.getValue<string>('Languages');
19+
? localStorage.getItem('@Languages')
20+
: GM.getValue<string>('@Languages');
2121

2222
export const setSaveLang = (val: string) =>
2323
typeof GM === 'undefined'
24-
? localStorage.setItem('Languages', val)
25-
: GM.setValue('Languages', val);
24+
? localStorage.setItem('@Languages', val)
25+
: GM.setValue('@Languages', val);
2626

2727
export const getInitLang = async () => {
2828
const saveLang = await getSaveLang();

src/userscript/main/migration.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const migration = async (version: string) => {
151151
switch (key) {
152152
case 'Version':
153153
case 'Languages':
154-
case 'HotKeys':
154+
case 'Hotkeys':
155155
continue;
156156

157157
default:
@@ -165,21 +165,24 @@ export const migration = async (version: string) => {
165165
switch (key) {
166166
case 'Version':
167167
case 'Languages':
168-
case 'HotKeys':
168+
case 'Hotkeys':
169169
continue;
170170

171171
default:
172172
await renameOption(key, ['associate_nhentai => cross_site_link']);
173173
}
174174
}
175175

176-
if (versionLt(version, '11.13'))
176+
if (versionLt(version, '12'))
177177
for (const key of values) {
178178
switch (key) {
179179
case 'Version':
180180
case 'Languages':
181-
case 'HotKeys':
181+
case 'Hotkeys': {
182+
await GM.setValue(`@${key}`, await GM.getValue(key));
183+
await GM.deleteValue(key);
182184
continue;
185+
}
183186

184187
default:
185188
await renameOption(key, ['hotkeys => add_hotkeys_actions']);

src/userscript/main/useInit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const useInit = async <T extends Record<string, any>>(
5252
const { store, setState } = useStore<MainStore<T>>({
5353
fab: { tip: t('other.read_mode'), show: false },
5454
manga: { imgList: [] },
55-
hotkeys: await GM.getValue<Record<string, string[]>>('Hotkeys', {}),
55+
hotkeys: await GM.getValue<Record<string, string[]>>('@Hotkeys', {}),
5656
name,
5757
options: {
5858
...structuredClone(defaultOptions),

src/userscript/main/useManga.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const useManga = <T extends Record<string, any>>({
6969

7070
hotkeys: store.hotkeys,
7171
onHotkeysChange(newValue: Record<string, string[]>) {
72-
GM.setValue('Hotkeys', newValue);
72+
GM.setValue('@Hotkeys', newValue);
7373
setState('hotkeys', newValue);
7474
},
7575
});

src/userscript/main/version.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { migration, versionLt } from './migration';
77

88
/** 处理版本更新相关 */
99
export const handleVersionUpdate = async () => {
10-
const version = await GM.getValue<string>('Version');
11-
if (!version) return GM.setValue('Version', GM.info.script.version);
10+
const version = await GM.getValue<string>('@Version');
11+
if (!version) return GM.setValue('@Version', GM.info.script.version);
1212
if (version === GM.info.script.version) return;
1313

1414
await migration(version); // 每次版本更新都执行一遍迁移
@@ -39,19 +39,19 @@ export const handleVersionUpdate = async () => {
3939
type: 'custom',
4040
duration: Number.POSITIVE_INFINITY,
4141
// 手动点击关掉通知后才不会再次弹出
42-
onDismiss: () => GM.setValue('Version', GM.info.script.version),
42+
onDismiss: () => GM.setValue('@Version', GM.info.script.version),
4343
},
4444
);
4545

4646
// 监听储存的版本数据的变动,如果和当前版本一致就关掉弹窗
4747
// 防止在更新版本后一次性打开多个页面,不得不一个一个关过去
4848
const listenerId = await GM.addValueChangeListener(
49-
'Version',
49+
'@Version',
5050
async (_, __, newVersion) => {
5151
if (newVersion !== GM.info.script.version) return;
5252
toast.dismiss('Version Tip');
5353
await GM.removeValueChangeListener(listenerId);
5454
},
5555
);
56-
} else await GM.setValue('Version', GM.info.script.version);
56+
} else await GM.setValue('@Version', GM.info.script.version);
5757
};

0 commit comments

Comments
 (0)