Răsfoiți Sursa

luci-app-ssr-plus: Make sure to always display `Move up` and `Move down`. (#1789)

Co-authored-by: zxlhhyccc <[email protected]>
zxl hhyccc 4 luni în urmă
părinte
comite
5cd8cbc0dd

+ 31 - 0
luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua

@@ -14,6 +14,31 @@ local function is_finded(e)
     return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= ""
 end
 
+-- 优化 CBI UI(新版 LuCI 专用)
+local function optimize_cbi_ui()
+	luci.http.write([[
+		<script type="text/javascript">
+			// 修正上移、下移按钮名称
+			document.querySelectorAll("input.btn.cbi-button.cbi-button-up").forEach(function(btn) {
+				btn.value = "]] .. translate("Move up") .. [[";
+			});
+			document.querySelectorAll("input.btn.cbi-button.cbi-button-down").forEach(function(btn) {
+				btn.value = "]] .. translate("Move down") .. [[";
+			});
+			// 删除控件和说明之间的多余换行
+			document.querySelectorAll("div.cbi-value-description").forEach(function(descDiv) {
+				var prev = descDiv.previousSibling;
+				while (prev && prev.nodeType === Node.TEXT_NODE && prev.textContent.trim() === "") {
+					prev = prev.previousSibling;
+				}
+				if (prev && prev.nodeType === Node.ELEMENT_NODE && prev.tagName === "BR") {
+					prev.remove();
+				}
+			});
+		</script>
+	]])
+end
+
 local has_ss_rust = is_finded("sslocal") or is_finded("ssserver")
 local has_ss_libev = is_finded("ss-redir") or is_finded("ss-local")
 
@@ -181,6 +206,12 @@ function s.create(...)
 		return
 	end
 end
+s.render = function(self, ...)
+	Map.render(self, ...)
+	if type(optimize_cbi_ui) == "function" then
+		optimize_cbi_ui()
+	end
+end
 
 o = s:option(DummyValue, "type", translate("Type"))
 function o.cfgvalue(self, section)