no message
This commit is contained in:
@@ -135,6 +135,51 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
break;
|
||||
}
|
||||
|
||||
case "loadAllConfigs": {
|
||||
if (!(await CryptoStore.hasVault())) await ensurePlainEnvironments();
|
||||
const data = await chrome.storage.session.get("environments");
|
||||
const environments = data.environments || [];
|
||||
const all = [];
|
||||
environments.forEach((env) => {
|
||||
(env.configs || []).forEach((cfg) => all.push({ ...cfg, envId: env.id, envName: env.name }));
|
||||
});
|
||||
sendResponse({ configs: all });
|
||||
break;
|
||||
}
|
||||
|
||||
case "getDomainAttempts": {
|
||||
const key = `${message.envId}::${message.domain}`;
|
||||
const data = await chrome.storage.local.get("loginAttempts");
|
||||
const attempts = data.loginAttempts || {};
|
||||
sendResponse({ attempts: attempts[key] || { count: 0, lastAttempt: 0 } });
|
||||
break;
|
||||
}
|
||||
|
||||
case "incrementDomainAttempts": {
|
||||
const key = `${message.envId}::${message.domain}`;
|
||||
const data = await chrome.storage.local.get("loginAttempts");
|
||||
const attempts = data.loginAttempts || {};
|
||||
const cur = attempts[key] || { count: 0, lastAttempt: 0 };
|
||||
cur.count += 1;
|
||||
cur.lastAttempt = Date.now();
|
||||
attempts[key] = cur;
|
||||
await chrome.storage.local.set({ loginAttempts: attempts });
|
||||
sendResponse({ attempts: cur });
|
||||
break;
|
||||
}
|
||||
|
||||
case "resetDomainAttempts": {
|
||||
const key = `${message.envId}::${message.domain}`;
|
||||
const data = await chrome.storage.local.get("loginAttempts");
|
||||
const attempts = data.loginAttempts || {};
|
||||
if (attempts[key]) {
|
||||
delete attempts[key];
|
||||
await chrome.storage.local.set({ loginAttempts: attempts });
|
||||
}
|
||||
sendResponse({ success: true });
|
||||
break;
|
||||
}
|
||||
|
||||
case "setupVault": {
|
||||
// 设置口令:若已有明文 environments 则加密它,否则创建预设
|
||||
const localData = await chrome.storage.local.get("environments");
|
||||
|
||||
+7
-40
@@ -1,29 +1,6 @@
|
||||
|
||||
const t = (key, ...args) => chrome.i18n.getMessage(key, args) || key;
|
||||
|
||||
function showDiag(msg) {
|
||||
try {
|
||||
const el = document.createElement("div");
|
||||
el.textContent = "[AutoLogin] " + msg;
|
||||
el.style.cssText = "position:fixed;top:10px;right:10px;z-index:2147483647;background:#1a1a2e;color:#e94560;padding:8px 12px;border-radius:6px;font-size:12px;font-family:monospace;max-width:90vw;word-break:break-all;box-shadow:0 2px 8px rgba(0,0,0,.4)";
|
||||
(document.body || document.documentElement).appendChild(el);
|
||||
setTimeout(() => el.remove(), 10000);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async function safeStorageGet(area, keys) {
|
||||
try {
|
||||
return await chrome.storage[area].get(keys);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function safeStorageSet(area, items) {
|
||||
try {
|
||||
await chrome.storage[area].set(items);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
// 2FA / 验证码检测:检测到则不自动提交,仅填充
|
||||
function detectCaptcha() {
|
||||
@@ -39,7 +16,7 @@ function detectCaptcha() {
|
||||
const sliderSelectors = [
|
||||
"#slider", ".slider", ".nc_wrapper", ".nc_iconfont",
|
||||
"#captcha", ".captcha", ".geetest", "#geetest",
|
||||
"[class*='slider']", "[id*='slider']", "[id*='captcha']", "[class*='captcha']",
|
||||
"[id*='captcha']", "[class*='captcha']",
|
||||
"canvas[id*='captcha']", "canvas[id*='verify']"
|
||||
];
|
||||
for (const sel of sliderSelectors) {
|
||||
@@ -407,32 +384,22 @@ async function autoFillOnLoad() {
|
||||
let allConfigs = await loadAllConfigs();
|
||||
if (allConfigs.length === 0) {
|
||||
// session 可能为空(明文模式 SW 重启后未初始化),触发 background 加载后重试
|
||||
let resp = null;
|
||||
try {
|
||||
resp = await chrome.runtime.sendMessage({ action: "getVaultStatus" });
|
||||
await chrome.runtime.sendMessage({ action: "getVaultStatus" });
|
||||
allConfigs = await loadAllConfigs();
|
||||
} catch (e) {
|
||||
showDiag("初始化失败: " + (e.message || e));
|
||||
return;
|
||||
}
|
||||
if (allConfigs.length === 0) {
|
||||
showDiag("无配置 | local: envs=" + (resp?.localEnvs) + " cfgs=" + (resp?.localCfgs) + " | session: envs=" + (resp?.sessEnvs) + " cfgs=" + (resp?.sessCfgs));
|
||||
console.warn("[AutoLogin] 初始化失败:", e.message || e);
|
||||
return;
|
||||
}
|
||||
if (allConfigs.length === 0) return;
|
||||
}
|
||||
|
||||
// 每个配置有独立开关 enabled
|
||||
const enabledConfigs = allConfigs.filter((c) => c.enabled !== false);
|
||||
if (enabledConfigs.length === 0) {
|
||||
showDiag("所有配置已禁用");
|
||||
return;
|
||||
}
|
||||
if (enabledConfigs.length === 0) return;
|
||||
|
||||
const matched = enabledConfigs.filter((c) => isDomainMatch(window.location.href, c.domain));
|
||||
if (matched.length === 0) {
|
||||
showDiag("未匹配: " + window.location.href + " | 配置: " + enabledConfigs.map((c) => c.domain).join(", "));
|
||||
return;
|
||||
}
|
||||
if (matched.length === 0) return;
|
||||
|
||||
if (matched.length === 1) {
|
||||
await fillSingleConfig(matched[0]);
|
||||
@@ -483,7 +450,7 @@ async function fillSingleConfig(config) {
|
||||
if (elapsed > SPA_FILL_TIMEOUT_MS) {
|
||||
const inputs = deepQuerySelectorAll("input");
|
||||
const pwd = deepQuerySelectorAll("input[type='password']");
|
||||
showDiag("填充超时: input=" + inputs.length + " pwd=" + pwd.length + " form=" + document.querySelectorAll("form").length + " | " + inputs.slice(0, 6).map((i) => "type=" + (i.type || "?") + "/name=" + (i.name || i.id || "?")).join(", "));
|
||||
console.warn("[AutoLogin] 填充超时: input=" + inputs.length + " pwd=" + pwd.length + " form=" + document.querySelectorAll("form").length + " | " + inputs.slice(0, 6).map((i) => "type=" + (i.type || "?") + "/name=" + (i.name || i.id || "?")).join(", "));
|
||||
return;
|
||||
}
|
||||
const filled = fillForm(config, canSubmit);
|
||||
|
||||
Reference in New Issue
Block a user