no message
This commit is contained in:
+10
-32
@@ -72,16 +72,12 @@ 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;
|
||||
|
||||
const form = passwordField.closest("form");
|
||||
const searchScope = form || document;
|
||||
searchScope = passwordField.closest("form") || document;
|
||||
}
|
||||
|
||||
const selectors = [
|
||||
"input[type='text']",
|
||||
@@ -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,25 +137,11 @@ 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;
|
||||
const searchScope = form || document;
|
||||
searchScope = form || document;
|
||||
}
|
||||
|
||||
const submitSelectors = [
|
||||
"button[type='submit']",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"));
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user