mirror of
https://github.com/xiaorouji/openwrt-passwall2.git
synced 2025-05-01 21:40:08 +08:00
luci: add node generate QRCode func
This commit is contained in:
parent
bf7bca3b02
commit
146f38de23
1
luci-app-passwall2/htdocs/luci-static/resources/qrcode.min.js
vendored
Normal file
1
luci-app-passwall2/htdocs/luci-static/resources/qrcode.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -2,6 +2,7 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.passwall2.api"
|
local api = require "luci.passwall2.api"
|
||||||
-%>
|
-%>
|
||||||
|
<script src="<%=resource%>/qrcode.min.js"></script>
|
||||||
<script type="text/javascript">//<![CDATA[
|
<script type="text/javascript">//<![CDATA[
|
||||||
let has_singbox = "<%=api.finded_com("singbox")%>"
|
let has_singbox = "<%=api.finded_com("singbox")%>"
|
||||||
let has_xray = "<%=api.finded_com("xray")%>"
|
let has_xray = "<%=api.finded_com("xray")%>"
|
||||||
@ -73,6 +74,20 @@ local api = require "luci.passwall2.api"
|
|||||||
return r;
|
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) {
|
function buildUrl(btn, urlname, sid) {
|
||||||
var opt = {
|
var opt = {
|
||||||
base: "cbid.passwall2",
|
base: "cbid.passwall2",
|
||||||
@ -115,12 +130,6 @@ local api = require "luci.passwall2.api"
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var s = document.getElementById(urlname + "-status");
|
|
||||||
if (!s) {
|
|
||||||
alert("Never");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
opt.base = "cbid." + urlname + "." + sid;
|
opt.base = "cbid." + urlname + "." + sid;
|
||||||
opt.client = urlname.indexOf("server") === -1;
|
opt.client = urlname.indexOf("server") === -1;
|
||||||
var v_type = opt.get("type").value;
|
var v_type = opt.get("type").value;
|
||||||
@ -369,12 +378,27 @@ local api = require "luci.passwall2.api"
|
|||||||
}
|
}
|
||||||
if (url) {
|
if (url) {
|
||||||
url = protocol.toLowerCase() + "://" + 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");
|
var textarea = document.createElement("textarea");
|
||||||
textarea.textContent = url;
|
textarea.textContent = url;
|
||||||
textarea.style.position = "fixed";
|
textarea.style.position = "fixed";
|
||||||
document.body.appendChild(textarea);
|
document.body.appendChild(textarea);
|
||||||
textarea.select();
|
textarea.select();
|
||||||
try {
|
try {
|
||||||
|
var s = document.getElementById(urlname + "-status");
|
||||||
|
if (!s) {
|
||||||
|
alert("Never");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
document.execCommand("copy"); // Security exception may be thrown by some browsers.
|
document.execCommand("copy"); // Security exception may be thrown by some browsers.
|
||||||
s.innerHTML = "<font color='green'><%:Share URL to clipboard successfully.%></font>";
|
s.innerHTML = "<font color='green'><%:Share URL to clipboard successfully.%></font>";
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -382,11 +406,7 @@ local api = require "luci.passwall2.api"
|
|||||||
} finally {
|
} finally {
|
||||||
document.body.removeChild(textarea);
|
document.body.removeChild(textarea);
|
||||||
}
|
}
|
||||||
//alert(url);
|
|
||||||
} else {
|
|
||||||
alert("<%:Not a supported scheme:%> " + v_type);
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fromUrl(btn, urlname, sid) {
|
function fromUrl(btn, urlname, sid) {
|
||||||
@ -906,6 +926,10 @@ local api = require "luci.passwall2.api"
|
|||||||
|
|
||||||
//]]></script>
|
//]]></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='<%: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>
|
<span id="<%=self.option%>-status"></span>
|
||||||
<%+cbi/valuefooter%>
|
<%+cbi/valuefooter%>
|
||||||
|
@ -418,6 +418,9 @@ msgstr "导入分享URL"
|
|||||||
msgid "Build Share URL"
|
msgid "Build Share URL"
|
||||||
msgstr "导出分享URL"
|
msgstr "导出分享URL"
|
||||||
|
|
||||||
|
msgid "Generate QRCode"
|
||||||
|
msgstr "生成二维码"
|
||||||
|
|
||||||
msgid "Import Finished"
|
msgid "Import Finished"
|
||||||
msgstr "导入完成:"
|
msgstr "导入完成:"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user