mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-07-31 20:11:29 +08:00
81 lines
2.0 KiB
HTML
81 lines
2.0 KiB
HTML
<%
|
|
local api = self.api
|
|
-%>
|
|
<script type="text/javascript">
|
|
//<![CDATA[
|
|
let node_id = "<%=self.section%>";
|
|
let node_config_url = '<%=api.url("node_config")%>/' + node_id;
|
|
|
|
function waitForElement(selector, callback) {
|
|
const el = document.querySelector(selector);
|
|
if (el) return callback(el);
|
|
const observer = new MutationObserver(() => {
|
|
const el = document.querySelector(selector);
|
|
if (el) {
|
|
observer.disconnect();
|
|
callback(el);
|
|
}
|
|
});
|
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
}
|
|
|
|
function getOption(opt) {
|
|
var obj;
|
|
var id = 'cbid.<%=api.appname%>.' + node_id + '.' + opt;
|
|
obj = document.getElementsByName(id)[0] || document.getElementById(id);
|
|
if (obj) {
|
|
var combobox = document.getElementById('cbi.combobox.' + id);
|
|
if (combobox) {
|
|
obj.combobox = combobox;
|
|
}
|
|
var div = document.getElementById(id);
|
|
if (div && div.getElementsByTagName("li").length > 0) {
|
|
obj = div;
|
|
}
|
|
return obj;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function update_node(data) {
|
|
XHR.get('<%=api.url("update_node")%>', {
|
|
id: node_id,
|
|
data: JSON.stringify(data)
|
|
},
|
|
function(x, data) {
|
|
if (x && x.status == 200 && data.code == 1) {
|
|
window.location.href = node_config_url;
|
|
}
|
|
else {
|
|
alert("<%:Error%>");
|
|
}
|
|
});
|
|
}
|
|
|
|
function fetchCertSha256(el) {
|
|
if (el.getAttribute("data-loading") === "1") return;
|
|
el.setAttribute("data-loading", "1");
|
|
el.style.pointerEvents = "none";
|
|
el.style.color = "red";
|
|
XHR.get('<%=api.url("fetch_certsha256")%>', { id: node_id }, function(x, res) {
|
|
el.setAttribute("data-loading", "0");
|
|
el.style.pointerEvents = "";
|
|
el.style.color = "";
|
|
if (!x || x.status !== 200) {
|
|
alert("<%:Error%>");
|
|
return;
|
|
}
|
|
if (!res || res.code !== 1 || !res.data) {
|
|
alert(res && res.msg ? res.msg : "<%:Fetch Failed%> !");
|
|
return;
|
|
}
|
|
const inputs = document.querySelectorAll('input[id$=".xray_tls_pinSHA256"]');
|
|
inputs.forEach(function(input) {
|
|
input.value = res.data;
|
|
});
|
|
});
|
|
}
|
|
//]]>
|
|
</script>
|