22 lines
837 B
JavaScript
22 lines
837 B
JavaScript
function handleLogout() {
|
|
chrome.storage.local.remove(["token", "loginAt", "username"], () => {
|
|
window.location.href = chrome.runtime.getURL("pages/login.html");
|
|
});
|
|
}
|
|
|
|
async function loadToken() {
|
|
return new Promise((resolve) => {
|
|
chrome.storage.local.get(["token", "username", "loginAt"], async (res) => {
|
|
const mergedConfig = await loadMergedConfig();
|
|
const expireMs = mergedConfig.tokenExpireHours * 60 * 60 * 1000;
|
|
const now = Date.now();
|
|
if (res.token && res.loginAt && now - res.loginAt < expireMs) {
|
|
log("token 加载成功");
|
|
resolve({ token: res.token, username: res.username });
|
|
} else {
|
|
log("token 不存在或已过期");
|
|
resolve(null);
|
|
}
|
|
});
|
|
});
|
|
} |