no message
This commit is contained in:
+11
-33
@@ -72,17 +72,13 @@ function setNativeValue(el, value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findUsernameField(config) {
|
function findUsernameField(config) {
|
||||||
if (config.usernameSelector) {
|
let searchScope = config.usernameSelector ? document.querySelector(config.usernameSelector) : null;
|
||||||
const el = document.querySelector(config.usernameSelector);
|
if (!searchScope) {
|
||||||
if (el) return el;
|
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 = [
|
const selectors = [
|
||||||
"input[type='text']",
|
"input[type='text']",
|
||||||
"input[type='email']",
|
"input[type='email']",
|
||||||
@@ -129,12 +125,8 @@ function findUsernameField(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findPasswordField(config) {
|
function findPasswordField(config) {
|
||||||
if (config.passwordSelector) {
|
const scope = config.passwordSelector ? (document.querySelector(config.passwordSelector) || document) : document;
|
||||||
const el = document.querySelector(config.passwordSelector);
|
const passwordInputs = scope.querySelectorAll("input[type='password']");
|
||||||
if (el) return el;
|
|
||||||
}
|
|
||||||
|
|
||||||
const passwordInputs = document.querySelectorAll("input[type='password']");
|
|
||||||
for (const input of passwordInputs) {
|
for (const input of passwordInputs) {
|
||||||
if (input.offsetParent !== null || input.offsetWidth > 0) {
|
if (input.offsetParent !== null || input.offsetWidth > 0) {
|
||||||
return input;
|
return input;
|
||||||
@@ -145,26 +137,12 @@ function findPasswordField(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findSubmitButton(config, passwordField) {
|
function findSubmitButton(config, passwordField) {
|
||||||
if (config.submitSelector) {
|
let searchScope = config.submitSelector ? document.querySelector(config.submitSelector) : null;
|
||||||
const els = document.querySelectorAll(config.submitSelector);
|
if (!searchScope) {
|
||||||
if (els.length === 1) return els[0];
|
const form = passwordField ? passwordField.closest("form") : null;
|
||||||
if (els.length > 1) {
|
searchScope = form || document;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const form = passwordField ? passwordField.closest("form") : null;
|
|
||||||
const searchScope = form || document;
|
|
||||||
|
|
||||||
const submitSelectors = [
|
const submitSelectors = [
|
||||||
"button[type='submit']",
|
"button[type='submit']",
|
||||||
"input[type='submit']",
|
"input[type='submit']",
|
||||||
|
|||||||
@@ -876,6 +876,10 @@ h2 {
|
|||||||
transition: all 0.3s;
|
transition: all 0.3s;
|
||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
max-width: 90vw;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toast.show {
|
.toast.show {
|
||||||
|
|||||||
@@ -1044,14 +1044,16 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const hostname = new URL(tab.url).hostname;
|
const u = new URL(tab.url);
|
||||||
if (!hostname) {
|
const host = u.host;
|
||||||
|
if (!host) {
|
||||||
showToast(t("toastNoDomain"));
|
showToast(t("toastNoDomain"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
domainInput.value = hostname;
|
const value = u.pathname && u.pathname !== "/" ? host + u.pathname : host;
|
||||||
|
domainInput.value = value;
|
||||||
saveDraft();
|
saveDraft();
|
||||||
showToast(t("toastDomainFilled", hostname));
|
showToast(t("toastDomainFilled", value));
|
||||||
} catch {
|
} catch {
|
||||||
showToast(t("toastUrlParseFail"));
|
showToast(t("toastUrlParseFail"));
|
||||||
}
|
}
|
||||||
@@ -1312,6 +1314,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
|
|
||||||
// 锁定 / 解锁
|
// 锁定 / 解锁
|
||||||
let lockMode = "setup"; // "setup" | "unlock"
|
let lockMode = "setup"; // "setup" | "unlock"
|
||||||
|
let lockAfterSetup = false;
|
||||||
|
|
||||||
function showLockScreen(mode) {
|
function showLockScreen(mode) {
|
||||||
lockMode = mode;
|
lockMode = mode;
|
||||||
@@ -1344,18 +1347,16 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
async function initLockState() {
|
async function initLockState() {
|
||||||
try {
|
try {
|
||||||
const resp = await sendMessage({ action: "getVaultStatus" });
|
const resp = await sendMessage({ action: "getVaultStatus" });
|
||||||
|
lockBtn.hidden = false;
|
||||||
if (!resp.hasVault) {
|
if (!resp.hasVault) {
|
||||||
// 无 vault:明文模式,直接进入,不锁定
|
// 无 vault:明文模式,直接进入,不锁定
|
||||||
lockBtn.hidden = true;
|
|
||||||
showMainUI();
|
showMainUI();
|
||||||
loadDraft();
|
loadDraft();
|
||||||
renderEnvSelect();
|
renderEnvSelect();
|
||||||
renderConfigList();
|
renderConfigList();
|
||||||
} else if (!resp.unlocked) {
|
} else if (!resp.unlocked) {
|
||||||
lockBtn.hidden = false;
|
|
||||||
showLockScreen("unlock");
|
showLockScreen("unlock");
|
||||||
} else {
|
} else {
|
||||||
lockBtn.hidden = false;
|
|
||||||
showMainUI();
|
showMainUI();
|
||||||
loadDraft();
|
loadDraft();
|
||||||
renderEnvSelect();
|
renderEnvSelect();
|
||||||
@@ -1363,8 +1364,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("[AutoLogin]", t("logGetLockStatusFail"), err);
|
console.warn("[AutoLogin]", t("logGetLockStatusFail"), err);
|
||||||
// background 不可用时不阻塞用户,直接进入主界面
|
lockBtn.hidden = false;
|
||||||
lockBtn.hidden = true;
|
|
||||||
showMainUI();
|
showMainUI();
|
||||||
loadDraft();
|
loadDraft();
|
||||||
renderEnvSelect();
|
renderEnvSelect();
|
||||||
@@ -1393,10 +1393,17 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
try {
|
try {
|
||||||
await sendMessage({ action: "setupVault", password: pwd });
|
await sendMessage({ action: "setupVault", password: pwd });
|
||||||
showToast(t("toastPasswordSet"));
|
showToast(t("toastPasswordSet"));
|
||||||
showMainUI();
|
if (lockAfterSetup) {
|
||||||
loadDraft();
|
lockAfterSetup = false;
|
||||||
renderEnvSelect();
|
await sendMessage({ action: "lock" });
|
||||||
renderConfigList();
|
showLockScreen("unlock");
|
||||||
|
showToast(t("toastLocked"));
|
||||||
|
} else {
|
||||||
|
showMainUI();
|
||||||
|
loadDraft();
|
||||||
|
renderEnvSelect();
|
||||||
|
renderConfigList();
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
lockWarn.textContent = t("lockWarnSetupFail", err.message || String(err));
|
lockWarn.textContent = t("lockWarnSetupFail", err.message || String(err));
|
||||||
lockWarn.style.display = "block";
|
lockWarn.style.display = "block";
|
||||||
@@ -1429,6 +1436,13 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
lockBtn.addEventListener("click", async () => {
|
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;
|
if (!confirm(t("lockConfirmPrompt"))) return;
|
||||||
await sendMessage({ action: "lock" });
|
await sendMessage({ action: "lock" });
|
||||||
showLockScreen("unlock");
|
showLockScreen("unlock");
|
||||||
|
|||||||
Reference in New Issue
Block a user