luci: optimize add the node via the link

This commit is contained in:
lwb1978 2025-04-09 20:31:06 +08:00 committed by xiaorouji
parent fa4439262b
commit 8999da1d5d
3 changed files with 66 additions and 37 deletions

View File

@ -2,22 +2,6 @@
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
-%> -%>
<style>
#add_link_div{
display: none;
width: auto;
position: absolute;
left:50%;
top:50%;
transform: translate(-50%, -50%);
z-index: 99;
text-align: center;
background: white;
box-shadow: darkgrey 10px 10px 30px 5px;
padding: 30px 15px;
}
</style>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
function ajax_add_node(link) { function ajax_add_node(link) {
@ -47,7 +31,8 @@ local api = require "luci.passwall2.api"
function add_node() { function add_node() {
var nodes_link = document.getElementById("nodes_link").value; var nodes_link = document.getElementById("nodes_link").value;
if (nodes_link.trim() != "") { nodes_link = nodes_link.replace(/\t/g, "").replace(/\r\n|\r/g, "\n").trim();
if (nodes_link != "") {
var s = nodes_link.split('://'); var s = nodes_link.split('://');
if (s.length > 1) { if (s.length > 1) {
ajax_add_node(nodes_link); ajax_add_node(nodes_link);
@ -79,15 +64,13 @@ local api = require "luci.passwall2.api"
</script> </script>
<div id="add_link_div"> <div id="add_link_div">
<div class="cbi-value"> <div id="add_link_modal_container">
<label class="cbi-value-title"><%:Share Link%></label> <h3><%:Add the node via the link%></h3>
<div class="cbi-value-field"> <div class="cbi-value">
<p><textarea id="nodes_link" rows="5" cols="50"></textarea></p> <textarea id="nodes_link" rows="10"></textarea>
<font color="red"><%:Not a subscription link!!!%></font> <p id="nodes_link_text"><%:Enter share links, one per line. Subscription links are not supported!%></p>
</div> </div>
</div> <div id="add_link_button_container">
<div class="cbi-value">
<div class="cbi-value-field" style="display: unset">
<input class="btn cbi-button cbi-button-add" type="button" onclick="add_node()" value="<%:Add%>" /> <input class="btn cbi-button cbi-button-add" type="button" onclick="add_node()" value="<%:Add%>" />
<input class="btn cbi-button cbi-button-remove" type="button" onclick="close_add_link_div()" value="<%:Close%>" /> <input class="btn cbi-button cbi-button-remove" type="button" onclick="close_add_link_div()" value="<%:Close%>" />
</div> </div>
@ -107,4 +90,56 @@ local api = require "luci.passwall2.api"
<input class="btn cbi-button cbi-button-reset" type="button" value="<%:Reset%>" onclick="location.href='<%=REQUEST_URI%>'" /> <input class="btn cbi-button cbi-button-reset" type="button" value="<%:Reset%>" onclick="location.href='<%=REQUEST_URI%>'" />
<div id="div_node_count"></div> <div id="div_node_count"></div>
</div> </div>
</div> </div>
<style>
#add_link_div {
display: none;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 20px;
border: 2px solid #ccc;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
z-index: 1000;
width: 90%;
max-width: 500px;
}
#add_link_modal_container {
width: 100%;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
padding-bottom: 20px;
}
#nodes_link {
width: 100%;
height: 180px;
resize: vertical;
font-family: monospace;
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}
#nodes_link_text {
color: red;
font-size: 14px;
margin-top: 5px;
text-align: center;
width: 100%;
}
#add_link_button_container {
display: flex;
justify-content: space-between;
width: 100%;
max-width: 300px;
margin-top: 10px;
}
</style>

View File

@ -265,11 +265,8 @@ msgstr "添加节点"
msgid "Add the node via the link" msgid "Add the node via the link"
msgstr "通过链接添加节点" msgstr "通过链接添加节点"
msgid "Share Link" msgid "Enter share links, one per line. Subscription links are not supported!"
msgstr "分享链接" msgstr "输入分享链接,支持多个节点,每行一个。请勿输入订阅链接!"
msgid "Not a subscription link!!!"
msgstr "不是订阅链接!!!"
msgid "Please enter the correct link." msgid "Please enter the correct link."
msgstr "请输入正确的链接。" msgstr "请输入正确的链接。"

View File

@ -1593,7 +1593,7 @@ local function parse_link(raw, add_mode, add_from, cfgid)
end end
for _, v in ipairs(nodes) do for _, v in ipairs(nodes) do
if v then if v and not string.match(v, "^%s*$") then
xpcall(function () xpcall(function ()
local result local result
if szType == 'ssd' then if szType == 'ssd' then
@ -1771,12 +1771,9 @@ if arg[1] then
log('订阅完毕...') log('订阅完毕...')
elseif arg[1] == "add" then elseif arg[1] == "add" then
local f = assert(io.open("/tmp/links.conf", 'r')) local f = assert(io.open("/tmp/links.conf", 'r'))
local content = f:read('*all') local raw = f:read('*all')
f:close() f:close()
local nodes = split(content:gsub(" ", "\n"), "\n") parse_link(raw, "1", "导入")
for _, raw in ipairs(nodes) do
parse_link(raw, "1", "导入")
end
update_node(1) update_node(1)
luci.sys.call("rm -f /tmp/links.conf") luci.sys.call("rm -f /tmp/links.conf")
elseif arg[1] == "truncate" then elseif arg[1] == "truncate" then