From 8043d75e933e8b2c718c6cff4d8e047a9d7d2fc1 Mon Sep 17 00:00:00 2001 From: "yinjun.chen1" Date: Wed, 16 Sep 2026 14:56:29 +0800 Subject: [PATCH] no message --- content.js | 44 +++++++++++--------------------------------- popup.css | 4 ++++ popup.js | 40 +++++++++++++++++++++++++++------------- 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/content.js b/content.js index cd114e0..239948a 100644 --- a/content.js +++ b/content.js @@ -72,17 +72,13 @@ function setNativeValue(el, value) { } function findUsernameField(config) { - if (config.usernameSelector) { - const el = document.querySelector(config.usernameSelector); - if (el) return el; + let searchScope = config.usernameSelector ? document.querySelector(config.usernameSelector) : null; + if (!searchScope) { + const passwordField = findPasswordField(config); + if (!passwordField) return null; + searchScope = passwordField.closest("form") || document; } - const passwordField = findPasswordField(config); - if (!passwordField) return null; - - const form = passwordField.closest("form"); - const searchScope = form || document; - const selectors = [ "input[type='text']", "input[type='email']", @@ -129,12 +125,8 @@ function findUsernameField(config) { } function findPasswordField(config) { - if (config.passwordSelector) { - const el = document.querySelector(config.passwordSelector); - if (el) return el; - } - - const passwordInputs = document.querySelectorAll("input[type='password']"); + const scope = config.passwordSelector ? (document.querySelector(config.passwordSelector) || document) : document; + const passwordInputs = scope.querySelectorAll("input[type='password']"); for (const input of passwordInputs) { if (input.offsetParent !== null || input.offsetWidth > 0) { return input; @@ -145,26 +137,12 @@ function findPasswordField(config) { } function findSubmitButton(config, passwordField) { - if (config.submitSelector) { - const els = document.querySelectorAll(config.submitSelector); - if (els.length === 1) return els[0]; - if (els.length > 1) { - for (const el of els) { - if (el.offsetParent === null && el.offsetWidth === 0) continue; - const compact = (el.textContent || el.value || "").toLowerCase().replace(/\s/g, ""); - if (compact.includes("登录") || compact.includes("login") || compact.includes("signin")) { - return el; - } - } - for (const el of els) { - if (el.offsetParent !== null || el.offsetWidth > 0) return el; - } - } + let searchScope = config.submitSelector ? document.querySelector(config.submitSelector) : null; + if (!searchScope) { + const form = passwordField ? passwordField.closest("form") : null; + searchScope = form || document; } - const form = passwordField ? passwordField.closest("form") : null; - const searchScope = form || document; - const submitSelectors = [ "button[type='submit']", "input[type='submit']", diff --git a/popup.css b/popup.css index 2941c92..c1b7bf9 100644 --- a/popup.css +++ b/popup.css @@ -876,6 +876,10 @@ h2 { transition: all 0.3s; z-index: 9999; pointer-events: none; + max-width: 90vw; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; } .toast.show { diff --git a/popup.js b/popup.js index c99a51b..60b6153 100644 --- a/popup.js +++ b/popup.js @@ -1044,14 +1044,16 @@ document.addEventListener("DOMContentLoaded", () => { return; } try { - const hostname = new URL(tab.url).hostname; - if (!hostname) { + const u = new URL(tab.url); + const host = u.host; + if (!host) { showToast(t("toastNoDomain")); return; } - domainInput.value = hostname; + const value = u.pathname && u.pathname !== "/" ? host + u.pathname : host; + domainInput.value = value; saveDraft(); - showToast(t("toastDomainFilled", hostname)); + showToast(t("toastDomainFilled", value)); } catch { showToast(t("toastUrlParseFail")); } @@ -1312,6 +1314,7 @@ document.addEventListener("DOMContentLoaded", () => { // 锁定 / 解锁 let lockMode = "setup"; // "setup" | "unlock" + let lockAfterSetup = false; function showLockScreen(mode) { lockMode = mode; @@ -1344,18 +1347,16 @@ document.addEventListener("DOMContentLoaded", () => { async function initLockState() { try { const resp = await sendMessage({ action: "getVaultStatus" }); + lockBtn.hidden = false; if (!resp.hasVault) { // 无 vault:明文模式,直接进入,不锁定 - lockBtn.hidden = true; showMainUI(); loadDraft(); renderEnvSelect(); renderConfigList(); } else if (!resp.unlocked) { - lockBtn.hidden = false; showLockScreen("unlock"); } else { - lockBtn.hidden = false; showMainUI(); loadDraft(); renderEnvSelect(); @@ -1363,8 +1364,7 @@ document.addEventListener("DOMContentLoaded", () => { } } catch (err) { console.warn("[AutoLogin]", t("logGetLockStatusFail"), err); - // background 不可用时不阻塞用户,直接进入主界面 - lockBtn.hidden = true; + lockBtn.hidden = false; showMainUI(); loadDraft(); renderEnvSelect(); @@ -1393,10 +1393,17 @@ document.addEventListener("DOMContentLoaded", () => { try { await sendMessage({ action: "setupVault", password: pwd }); showToast(t("toastPasswordSet")); - showMainUI(); - loadDraft(); - renderEnvSelect(); - renderConfigList(); + if (lockAfterSetup) { + lockAfterSetup = false; + await sendMessage({ action: "lock" }); + showLockScreen("unlock"); + showToast(t("toastLocked")); + } else { + showMainUI(); + loadDraft(); + renderEnvSelect(); + renderConfigList(); + } } catch (err) { lockWarn.textContent = t("lockWarnSetupFail", err.message || String(err)); lockWarn.style.display = "block"; @@ -1429,6 +1436,13 @@ document.addEventListener("DOMContentLoaded", () => { }); lockBtn.addEventListener("click", async () => { + const resp = await sendMessage({ action: "getVaultStatus" }).catch(() => null); + if (resp && !resp.hasVault) { + // 明文模式:先设密码再锁定 + lockAfterSetup = true; + showLockScreen("setup"); + return; + } if (!confirm(t("lockConfirmPrompt"))) return; await sendMessage({ action: "lock" }); showLockScreen("unlock");