openwrt_helloworld/luci-app-passwall/luasrc/view/passwall/haproxy/js.htm
2025-05-08 18:30:21 +08:00

41 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script type="text/javascript">
//<![CDATA[
document.addEventListener("DOMContentLoaded", function () {
let monitorStartTime = Date.now();
const monitorInterval = setInterval(function () {
// 超过5秒后停止监控
if (Date.now() - monitorStartTime > 5000) {
clearInterval(monitorInterval);
return;
}
const rows = Array.from(document.querySelectorAll("tr.cbi-section-table-row"))
.filter(row => !row.classList.contains("placeholder")); // 排除无配置行
if (rows.length === 0) return;
const lastRow = rows[rows.length - 1];
const lastPortInput = lastRow.querySelector("input[name$='.haproxy_port']");
// 没找到最后一行的 port 输入框或 port 不是 65535跳过
if (!lastPortInput || lastPortInput.value !== "65535") return;
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;
}
}
}, 300); // 每 300ms 检查一次
});
//]]>
</script>