luci: add node generate QRCode func

This commit is contained in:
xiaorouji 2024-03-19 18:06:51 +08:00
parent bf7bca3b02
commit 146f38de23
3 changed files with 39 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@
<%
local api = require "luci.passwall2.api"
-%>
<script src="<%=resource%>/qrcode.min.js"></script>
<script type="text/javascript">//<![CDATA[
let has_singbox = "<%=api.finded_com("singbox")%>"
let has_xray = "<%=api.finded_com("xray")%>"
@ -73,6 +74,20 @@ local api = require "luci.passwall2.api"
return r;
}
function genQrcode(btn, urlname, sid) {
var qrcode_div = document.getElementById("qrcode_div");
qrcode_div.style.display = null;
document.getElementById("qrcode").innerHTML = "";
var url = buildUrl(btn, urlname, sid);
if (url) {
var qrcode = new QRCode(document.getElementById("qrcode"), {
width: 150,
height: 150
});
qrcode.makeCode(url);
}
}
function buildUrl(btn, urlname, sid) {
var opt = {
base: "cbid.passwall2",
@ -115,12 +130,6 @@ local api = require "luci.passwall2.api"
return ""
}
}
var s = document.getElementById(urlname + "-status");
if (!s) {
alert("Never");
return false;
}
opt.base = "cbid." + urlname + "." + sid;
opt.client = urlname.indexOf("server") === -1;
var v_type = opt.get("type").value;
@ -369,12 +378,27 @@ local api = require "luci.passwall2.api"
}
if (url) {
url = protocol.toLowerCase() + "://" + url;
return url;
} else {
alert("<%:Not a supported scheme:%> " + v_type);
}
return false;
}
function exportUrl(btn, urlname, sid) {
var url = buildUrl(btn, urlname, sid);
if (url) {
var textarea = document.createElement("textarea");
textarea.textContent = url;
textarea.style.position = "fixed";
document.body.appendChild(textarea);
textarea.select();
try {
var s = document.getElementById(urlname + "-status");
if (!s) {
alert("Never");
return false;
}
document.execCommand("copy"); // Security exception may be thrown by some browsers.
s.innerHTML = "<font color='green'><%:Share URL to clipboard successfully.%></font>";
} catch (ex) {
@ -382,11 +406,7 @@ local api = require "luci.passwall2.api"
} finally {
document.body.removeChild(textarea);
}
//alert(url);
} else {
alert("<%:Not a supported scheme:%> " + v_type);
}
return false;
}
function fromUrl(btn, urlname, sid) {
@ -906,6 +926,10 @@ local api = require "luci.passwall2.api"
//]]></script>
<input type="button" class="btn cbi-button cbi-button-apply" value='<%:From Share URL%>' onclick="return fromUrl(this, '<%=self.option%>', '<%=self.value%>')" />
<input type="button" class="btn cbi-button cbi-button-apply" value='<%:Build Share URL%>' onclick="return buildUrl(this, '<%=self.option%>', '<%=self.value%>')" />
<input type="button" class="btn cbi-button cbi-button-apply" value='<%:Build Share URL%>' onclick="return exportUrl(this, '<%=self.option%>', '<%=self.value%>')" />
<input type="button" class="btn cbi-button cbi-button-apply" value='<%:Generate QRCode%>' onclick="return genQrcode(this, '<%=self.option%>', '<%=self.value%>')" />
<div id="qrcode_div" style="margin-top: 1rem;display:none">
<div id="qrcode"></div>
</div>
<span id="<%=self.option%>-status"></span>
<%+cbi/valuefooter%>

View File

@ -418,6 +418,9 @@ msgstr "导入分享URL"
msgid "Build Share URL"
msgstr "导出分享URL"
msgid "Generate QRCode"
msgstr "生成二维码"
msgid "Import Finished"
msgstr "导入完成:"