From d83dfa27b175e15741a8f93e14d077b1f8d91592 Mon Sep 17 00:00:00 2001 From: gitea-action Date: Thu, 8 May 2025 20:00:24 +0800 Subject: [PATCH] luci-app-passwall: sync upstream last commit: https://github.com/xiaorouji/openwrt-passwall/commit/475c93c00de9e85de1c2deb539acbcd5c5ef5e86 --- .../model/cbi/passwall/client/haproxy.lua | 2 +- .../luasrc/view/passwall/haproxy/js.htm | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua index f631c562d..8be9f2717 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua @@ -135,7 +135,7 @@ end ---- Haproxy Port o = s:option(Value, "haproxy_port", translate("Haproxy Port")) o.datatype = "port" -o.default = 65535 +o.default = 1181 o.rmempty = false ---- Node Weight diff --git a/luci-app-passwall/luasrc/view/passwall/haproxy/js.htm b/luci-app-passwall/luasrc/view/passwall/haproxy/js.htm index 508842764..872b819f2 100644 --- a/luci-app-passwall/luasrc/view/passwall/haproxy/js.htm +++ b/luci-app-passwall/luasrc/view/passwall/haproxy/js.htm @@ -5,8 +5,7 @@ let monitorStartTime = Date.now(); const monitorInterval = setInterval(function () { - // 超过5秒后停止监控 - if (Date.now() - monitorStartTime > 5000) { + if (Date.now() - monitorStartTime > 3000) { clearInterval(monitorInterval); return; } @@ -14,27 +13,34 @@ const rows = Array.from(document.querySelectorAll("tr.cbi-section-table-row")) .filter(row => !row.classList.contains("placeholder")); // 排除无配置行 - if (rows.length === 0) return; + if (rows.length <= 1) return; const lastRow = rows[rows.length - 1]; - const lastPortInput = lastRow.querySelector("input[name$='.haproxy_port']"); + const secondLastRow = rows[rows.length - 2]; - // 没找到最后一行的 port 输入框或 port 不是 65535,跳过 - if (!lastPortInput || lastPortInput.value !== "65535") return; + const lastInput = lastRow.querySelector("input[name$='.haproxy_port']"); + const secondLastInput = secondLastRow.querySelector("input[name$='.haproxy_port']"); - if (rows.length === 1) { - lastPortInput.value = "1181"; - } else { - const prevRow = rows[rows.length - 2]; - const prevPortInput = prevRow.querySelector("input[name$='.haproxy_port']"); - const prevValue = prevPortInput ? prevPortInput.value.trim() : ""; - if (prevValue === "" || prevValue === "0") { - lastPortInput.value = "1181"; - } else { - lastPortInput.value = prevValue; - } + if (!lastInput || !secondLastInput) return; + + // 如果还没绑定 change 事件,绑定一次 + if (!lastInput.dataset.bindChange) { + lastInput.dataset.bindChange = "1"; + lastInput.addEventListener("input", () => { + lastInput.dataset.userModified = "1"; + }); } - }, 300); // 每 300ms 检查一次 + + // 如果用户手动修改过,就不再自动设置 + if (lastInput.dataset.userModified === "1") return; + + const lastVal = lastInput.value.trim(); + const secondLastVal = secondLastInput.value.trim(); + + if (lastVal !== secondLastVal && secondLastVal !== "" && secondLastVal !== "0") { + lastInput.value = secondLastVal; + } + }, 300); }); //]]>