From c26e834982da7298837491d922c8ab400e21bcee Mon Sep 17 00:00:00 2001 From: Furrium Network Date: Tue, 22 Sep 2026 22:03:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=98=B2=E6=AD=A2=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=99=A8=E6=8A=8A=E9=A6=96=E9=A1=B5=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86=E5=BD=93=E6=88=90=E8=B4=A6=E5=8F=B7=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=A1=AB=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现象:搜索框被自动填入保存的邮箱或密码。 根因是页面此前完全没有
标签——登录、注册、重置密码三处的 输入框与按钮都裸放在 div 中。密码管理器找不到表单边界,只能靠启发式 猜测,于是把页面上的其他文本框(首页搜索框)也纳入填充范围。 修复分两部分: 一、为三个认证模态框补上真正的 - loginForm:邮箱用 autocomplete="username",密码用 current-password - registerForm:密码用 new-password,验证码用 one-time-code, 验证码与图形验证码标 off - forgotPasswordForm:新密码用 new-password 有了明确的表单边界,密码管理器的填充范围被限定在正确的表单内。 注意随之而来的副作用:按钮改为 type="submit" 后,回车或点击会触发 浏览器原生表单提交导致页面刷新。已在 auth.js 中统一拦截三个表单的 submit 事件。 二、为搜索框叠加多重忽略标识 Chrome 等对 autocomplete="off" 经常忽略,因此同时加上: - type="search" 与 role="searchbox",语义明确 - name="post-search-query",不易被判定为账号字段 - autocorrect / autocapitalize / spellcheck 关闭 - data-form-type="other"(1Password 识别) - data-1p-ignore(1Password)与 data-lpignore="true"(LastPass) 实测(Puppeteer,1280×900): - 页面含 loginForm / registerForm / forgotPasswordForm 三个表单, 登录表单内邮箱与密码字段齐备 - 搜索框 type=search、name=post-search-query、role=searchbox, 两个密码管理器的忽略属性均存在 - 在登录框内按回车:未发生页面导航(framenavigated 为 false), 登录成功且弹窗正常关闭——确认 submit 拦截生效 - 搜索框未受影响,仍可正常使用 完整测试套件 25/25 通过。 --- index.html | 69 ++++++++++++++++++++++++++++++++++-------------------- js/auth.js | 10 ++++++++ 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index 59067cc..7af302d 100644 --- a/index.html +++ b/index.html @@ -102,7 +102,16 @@
@@ -400,19 +415,21 @@

注册

- - - - -
- - -
-
- 3 + 5 = ? - -
- +
+ + + + + +
+ 3 + 5 = ? + +
+ +
@@ -446,11 +463,13 @@

🔑 重置密码

输入你的邮箱和一个未使用的恢复码

- - - - -
+
+ + + + +
+
diff --git a/js/auth.js b/js/auth.js index 85c915a..51e4e39 100644 --- a/js/auth.js +++ b/js/auth.js @@ -2,6 +2,16 @@ // 🔐 认证 // ============================================================ +// 三个认证表单的提交拦截。 +// 输入框与按钮原本裸放在 div 中(页面没有 form 标签),密码管理器因此 +// 找不到表单边界,会靠启发式猜测把首页搜索框也当成账号字段填入。 +// 现改用真正的
包裹,需要拦下默认提交行为——否则按回车或点按钮 +// 会触发浏览器原生提交导致页面刷新。 +['loginForm', 'registerForm', 'forgotPasswordForm'].forEach(id => { + const form = document.getElementById(id); + if (form) form.addEventListener('submit', e => e.preventDefault()); +}); + // 登录事件绑定 document.getElementById('loginBtn').addEventListener('click', () => { document.getElementById('loginModal').classList.add('active');