This commit is contained in:
zhu
2026-05-06 10:22:38 +08:00
parent 350d4fc2e2
commit 53e4f0b2f4
10 changed files with 256 additions and 183 deletions

View File

@@ -1,7 +1,9 @@
const AUTH_TOKEN_KEY = 'token';
const AUTH_TOKEN_KEY = 'token';
const MOCK_TOKEN = 'mock-extension-token';
/** 获取当前登录 token。 */
/**
* 获取当前登录 token。
*/
export async function getToken(): Promise<string | null> {
const storage = getChromeStorage();
@@ -14,13 +16,17 @@ export async function getToken(): Promise<string | null> {
return window.localStorage.getItem(AUTH_TOKEN_KEY);
}
/** 模拟登录,写入一个临时 token方便后续替换真实登录逻辑。 */
/**
* 模拟登录,写入一个临时 token方便后续替换真实登录逻辑。
*/
export async function mockLogin(): Promise<string> {
await setToken(MOCK_TOKEN);
return MOCK_TOKEN;
}
/** 清除当前登录 token。 */
/**
* 清除当前登录 token。
*/
export async function logout(): Promise<void> {
const storage = getChromeStorage();
@@ -44,7 +50,7 @@ async function setToken(token: string): Promise<void> {
}
/**
* 获取谷歌缓存
* * 获取谷歌缓存
*/
function getChromeStorage(): chrome.storage.StorageArea | null {
if (typeof chrome === 'undefined' || !chrome.storage?.local) {