From 00d76ba20fc8579d6a8c953403324aef469507df Mon Sep 17 00:00:00 2001 From: dekun Date: Mon, 20 Jul 2026 10:14:14 +0800 Subject: [PATCH] Stop browser autofill stuffing login username into transfer amount fields. Co-authored-by: Cursor --- lib/common/static/hedge_plan.js | 42 +++++++++++++++++- lib/common/static/options_panel.js | 40 +++++++++++------ lib/common/static/options_settings.js | 43 +++++++++++++++++++ .../templates/hedge_plan_panel.html | 30 +++++++------ lib/options/templates/options_panel.html | 5 ++- .../templates/options_review_panel.html | 19 +++++--- .../templates/options_settings_panel.html | 2 +- .../templates/options_settings_swap.html | 7 ++- .../templates/options_settings_transfer.html | 14 ++++-- 9 files changed, 158 insertions(+), 44 deletions(-) diff --git a/lib/common/static/hedge_plan.js b/lib/common/static/hedge_plan.js index 9f794a2..cd36dff 100644 --- a/lib/common/static/hedge_plan.js +++ b/lib/common/static/hedge_plan.js @@ -1084,6 +1084,32 @@ } } + function hardenAmountAutofill(ids) { + (ids || []).forEach(function (id) { + const el = $(id); + if (!el) return; + function wipe() { + const v = String(el.value || "").trim(); + // 浏览器常把登录用户名(如 dekun)灌进数量框 + if (/^[a-z][a-z0-9._-]{1,31}$/i.test(v)) el.value = ""; + } + wipe(); + const lockRo = id.indexOf("xfer") >= 0 || el.hasAttribute("readonly"); + if (lockRo) { + el.setAttribute("readonly", "readonly"); + el.addEventListener("focus", function () { + el.removeAttribute("readonly"); + }); + el.addEventListener("blur", function () { + if (!el.value) el.setAttribute("readonly", "readonly"); + }); + } + setTimeout(wipe, 200); + setTimeout(wipe, 800); + setTimeout(wipe, 2000); + }); + } + function bind() { document.querySelectorAll(".hp-tab").forEach(function (b) { b.addEventListener("click", function () { @@ -1185,10 +1211,24 @@ const amt = Math.floor(max * 100) / 100; const label = dir === "trading_to_funding" ? "交易 → 资金" : "资金 → 交易"; if (!window.confirm("确认全部划转?\n方向:" + label + "\n数量:" + amt + " USDC")) return; - if ($("hp-oo-xfer-amount")) $("hp-oo-xfer-amount").value = String(amt); + const amtEl = $("hp-oo-xfer-amount"); + if (amtEl) { + amtEl.removeAttribute("readonly"); + amtEl.value = String(amt); + } void submitOoUsdcTransfer(amt); }); } + hardenAmountAutofill([ + "hp-oo-xfer-amount", + "hp-entry", + "hp-contracts", + "hp-tp", + "hp-sl", + "hp-sheets", + "hp-target-up", + "hp-target-down", + ]); if ($("hp-preview-btn")) $("hp-preview-btn").addEventListener("click", function () { state.mode = "perp_options"; diff --git a/lib/common/static/options_panel.js b/lib/common/static/options_panel.js index ca7d080..2b408f2 100644 --- a/lib/common/static/options_panel.js +++ b/lib/common/static/options_panel.js @@ -285,22 +285,34 @@ } function hardenOrderAutofill() { - const note = document.getElementById("opt-signal-note"); - if (!note) return; - function wipeNote() { - if (/^[a-z][a-z0-9._-]{1,31}$/i.test(String(note.value || "").trim())) { - note.value = ""; - } + function looksLikeUsername(v) { + return /^[a-z][a-z0-9._-]{1,31}$/i.test(String(v || "").trim()); } - wipeNote(); - note.addEventListener("focus", function () { - note.removeAttribute("readonly"); + function harden(el) { + if (!el) return; + function wipe() { + if (looksLikeUsername(el.value)) el.value = ""; + } + wipe(); + el.addEventListener("focus", function () { + el.removeAttribute("readonly"); + }); + el.addEventListener("blur", function () { + if (!el.value) el.setAttribute("readonly", "readonly"); + }); + setTimeout(wipe, 200); + setTimeout(wipe, 800); + setTimeout(wipe, 2000); + } + const note = document.getElementById("opt-signal-note"); + harden(note); + [ + "opt-sheets-amount", + "opt-eth-amount", + "opt-target-idx", + ].forEach(function (id) { + harden(document.getElementById(id)); }); - note.addEventListener("blur", function () { - if (!note.value) note.setAttribute("readonly", "readonly"); - }); - setTimeout(wipeNote, 200); - setTimeout(wipeNote, 800); } function quoteUrl(instId) { diff --git a/lib/common/static/options_settings.js b/lib/common/static/options_settings.js index 71bb615..d051473 100644 --- a/lib/common/static/options_settings.js +++ b/lib/common/static/options_settings.js @@ -342,4 +342,47 @@ } }); } + + function hardenAmountAutofill(ids) { + ids.forEach(function (id) { + const el = document.getElementById(id); + if (!el) return; + function wipe() { + const v = String(el.value || "").trim(); + if (/^[a-z][a-z0-9._-]{1,31}$/i.test(v)) el.value = ""; + } + wipe(); + el.setAttribute("readonly", "readonly"); + el.addEventListener("focus", function () { + el.removeAttribute("readonly"); + }); + el.addEventListener("blur", function () { + if (!el.value) el.setAttribute("readonly", "readonly"); + }); + setTimeout(wipe, 200); + setTimeout(wipe, 800); + setTimeout(wipe, 2000); + }); + } + + // 全部划转/兑换前去掉 readonly,避免写不进数量 + ["opt-set-swap-all-btn", "opt-set-int-all-btn", "opt-set-cross-all-btn"].forEach(function (btnId) { + const btn = document.getElementById(btnId); + if (!btn) return; + btn.addEventListener( + "click", + function () { + const map = { + "opt-set-swap-all-btn": "opt-set-swap-amount", + "opt-set-int-all-btn": "opt-set-int-amount", + "opt-set-cross-all-btn": "opt-set-cross-amount", + }; + const input = document.getElementById(map[btnId]); + if (input) input.removeAttribute("readonly"); + }, + true + ); + }); + + hardenAmountAutofill(["opt-set-swap-amount", "opt-set-int-amount", "opt-set-cross-amount"]); })(); diff --git a/lib/hedge_plan/templates/hedge_plan_panel.html b/lib/hedge_plan/templates/hedge_plan_panel.html index c974940..7020132 100644 --- a/lib/hedge_plan/templates/hedge_plan_panel.html +++ b/lib/hedge_plan/templates/hedge_plan_panel.html @@ -58,19 +58,19 @@
@@ -106,7 +106,7 @@
- +
@@ -126,8 +126,8 @@
- - + + 指数 —
@@ -152,13 +152,13 @@
腿A: 尚未选用
腿B: 尚未选用

@@ -197,12 +197,16 @@ USDC
-
- + - +
@@ -301,4 +305,4 @@ - + diff --git a/lib/options/templates/options_panel.html b/lib/options/templates/options_panel.html index c1fa0ad..84e6da3 100644 --- a/lib/options/templates/options_panel.html +++ b/lib/options/templates/options_panel.html @@ -101,7 +101,8 @@
- + 预计价值 盈利 @@ -313,4 +314,4 @@
- + diff --git a/lib/options/templates/options_review_panel.html b/lib/options/templates/options_review_panel.html index 6558dfc..8d6f71e 100644 --- a/lib/options/templates/options_review_panel.html +++ b/lib/options/templates/options_review_panel.html @@ -257,12 +257,17 @@
- - - - - - + + + + + +
+ + - +
diff --git a/lib/options/templates/options_settings_transfer.html b/lib/options/templates/options_settings_transfer.html index 9d00a27..1d1a398 100644 --- a/lib/options/templates/options_settings_transfer.html +++ b/lib/options/templates/options_settings_transfer.html @@ -1,7 +1,9 @@
主账户内
- + @@ -13,7 +15,8 @@ - +
@@ -26,7 +29,9 @@ ({{ instance_settings.options_sub_account or '未配置' }})
- + @@ -42,7 +47,8 @@ - +