feat: 新增浏览器插件

This commit is contained in:
2026-08-16 16:45:24 +08:00
parent 2f32d955eb
commit f209d93733
38 changed files with 4727 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
export interface ExtensionSettings {
/** 例:https://host/api (不要末尾斜杠) */
apiBaseUrl: string;
/** Open API Key(非 JWT) */
apiKey: string;
/** 记住的渠道店铺 */
channelShopId?: number;
channelShopName?: string;
}
const STORAGE_KEY = 'ecbi.extension.settings';
const DEFAULT_SETTINGS: ExtensionSettings = {
apiBaseUrl: '',
apiKey: '',
};
export async function getSettings(): Promise<ExtensionSettings> {
const result = await chrome.storage.local.get(STORAGE_KEY);
const raw = result[STORAGE_KEY] as Partial<ExtensionSettings> | undefined;
return {
...DEFAULT_SETTINGS,
...raw,
apiBaseUrl: (raw?.apiBaseUrl ?? '').replace(/\/+$/, ''),
apiKey: raw?.apiKey ?? '',
};
}
export async function saveSettings(
patch: Partial<ExtensionSettings>,
): Promise<ExtensionSettings> {
const current = await getSettings();
const next: ExtensionSettings = {
...current,
...patch,
apiBaseUrl: (patch.apiBaseUrl ?? current.apiBaseUrl).replace(/\/+$/, ''),
};
await chrome.storage.local.set({ [STORAGE_KEY]: next });
return next;
}
+1
View File
@@ -0,0 +1 @@
export type { ExtensionSettings } from './settings';