u(t.family)===e));if(0===n.length)return;return n[0].address}const o=Object.keys(r).map((o=>{const i=r[o].filter((r=>(r.family=u(r.family),r.family===e&&!n.isLoopback(r.address)&&(!t||("public"===t?n.isPrivate(r.address):n.isPublic(r.address))))));return i.length?i[0].address:void 0})).filter(Boolean);return o.length?o[0]:n.loopback(e)},n.toLong=function(t){let e=0;return t.split(".").forEach((t=>{e<<=8,e+=parseInt(t)})),e>>>0},n.fromLong=function(t){return`${t>>>24}.${t>>16&255}.${t>>8&255}.${255&t}`},n.normalizeToLong=function(t){const e=t.split(".").map((t=>t.startsWith("0x")||t.startsWith("0X")?parseInt(t,16):t.startsWith("0")&&"0"!==t&&/^[0-7]+$/.test(t)?parseInt(t,8):/^[1-9]\d*$/.test(t)||"0"===t?parseInt(t,10):NaN));if(e.some(isNaN))return-1;let r=0;switch(e.length){case 1:r=e[0];break;case 2:if(e[0]>255||e[1]>16777215)return-1;r=e[0]<<24|16777215&e[1];break;case 3:if(e[0]>255||e[1]>255||e[2]>65535)return-1;r=e[0]<<24|e[1]<<16|65535&e[2];break;case 4:if(e.some((t=>t>255)))return-1;r=e[0]<<24|e[1]<<16|e[2]<<8|e[3];break;default:return-1}return r>>>0}},680:()=>{}},e={};const r=function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}(139),n="以下为示例路由表:\nIPv4 路由表\n===========================================================================\n活动路由:\n网络目标 网络掩码 网关 接口 跃点数\n 0.0.0.0 0.0.0.0 192.168.11.1 192.168.11.16 25\n 36.131.128.231 255.255.255.255 10.4.4.1 10.4.4.2 10\n 36.131.172.240 255.255.255.255 10.4.4.1 10.4.4.2 10\n 36.131.173.236 255.255.255.255 10.4.4.1 10.4.4.2 10\n 59.191.128.0 255.255.128.0 10.4.4.1 10.4.4.2 10\n 192.0.0.0 255.128.0.0 10.4.4.1 10.4.4.2 10\n 192.168.11.0 255.255.255.0 在链路上 192.168.11.16 281\n 192.168.11.255 255.255.255.255 在链路上 192.168.11.16 281\n 224.0.0.0 240.0.0.0 在链路上 10.4.4.2 261\n 255.255.255.255 255.255.255.255 在链路上 127.0.0.1 331\n===========================================================================\n",o=["0.0.0.0/0","0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.2.0/24","192.168.0.0/16","192.88.99.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","233.252.0.0/24","224.0.0.0/4","240.0.0.0/4","255.255.255.255/32"];function i(t,e,r=""){if(!Array.isArray(t))throw new Error("convertCIDRListToString: Invalid input cidrAddressList");if(0===t.length)return"";let n=r?r+"\n":"";return n+=t.map(e).join("\n"),n.trim()}function s(t){return i(t,(t=>`${t.networkAddress}/${t.subnetMaskLength}`))}function f(t){return i(t,(t=>` - ${t.networkAddress}/${t.subnetMaskLength}`),"payload:")}function u(t,e){return i(t,(t=>`${t.networkAddress}/${t.subnetMaskLength}`),e)}document.addEventListener("DOMContentLoaded",(()=>{const t=document.getElementById("input"),e=document.getElementById("output"),i=document.getElementById("config-container"),h=document.getElementById("sstapHeader"),c=document.getElementById("buttonToClash"),a=document.getElementById("buttonToSSTap"),l=document.getElementById("buttonToNetch"),p=document.getElementById("copyButton"),g=document.getElementById("downloadButton");function y(t){i.style.display=t?"block":"none"}function d(t){const e=document.getElementById("notification");e.textContent=t,e.classList.remove("opacity-0"),e.classList.add("opacity-100"),setTimeout((()=>{e.classList.add("opacity-0"),e.classList.remove("opacity-100")}),3e3)}function w(i,s=null){d("正在转换路由表至CIDR~ 转换速度取决于路由表长度");const f=function(t){const e=[];let n=[];return t.split("\n").forEach((t=>{const r=t.trim().split(/\s+/);5==r.length&&e.push(r)})),e.forEach((t=>{try{if(!r.isV4Format(t[0]))return;const e=r.subnet(t[0],t[1]),i=`${e.networkAddress}/${e.subnetMaskLength}`;!r.isPublic(e.networkAddress)||r.isLoopback(e.networkAddress)||r.isPrivate(e.networkAddress)||o.includes(i)||n.push(e)}catch(t){console.error("Error converting IP to CIDR:",t)}})),n=n.filter(((t,e,n)=>!n.some((e=>r.cidrSubnet(e.networkAddress+"/"+e.subnetMaskLength).contains(t.networkAddress)&&e!==t)))),n}(""===t.value.trim()?n:t.value),u=s?i(f,s):i(f);e.textContent=u,d("转换完成!")}t.placeholder=n,i.style.display="none",c.addEventListener("click",(()=>{w(f),y(!1)})),a.addEventListener("click",(()=>{w(u,h.value.trim()),y(!0)})),l.addEventListener("click",(()=>{w(s),y(!1)})),p.addEventListener("click",(()=>{const t=e.textContent.trim();t?navigator.clipboard.writeText(t).then((()=>{d("转换结果已复制到剪贴板!")})).catch((t=>{console.error("复制失败:",t)})):d("转换结果没有内容可供复制!")})),g.addEventListener("click",(()=>{const t=e.textContent.trim();if(t){const e=new Blob([t],{type:"text/plain"}),r=URL.createObjectURL(e),n=document.createElement("a");n.href=r,n.download="output.rules",n.click(),URL.revokeObjectURL(r),d("转换结果文件已下载!")}else d("转换结果没有内容可供下载!")}))}))})();
\ No newline at end of file
diff --git a/docs/images/homepage.png b/docs/images/homepage.png
new file mode 100644
index 0000000..efc90c1
Binary files /dev/null and b/docs/images/homepage.png differ
diff --git a/index.html b/index.html
index f17a094..0fa1e24 100644
--- a/index.html
+++ b/index.html
@@ -10,7 +10,7 @@
-
+
@@ -75,6 +75,7 @@ 转换结果:
class="bg-red-500 text-white px-4 py-2 rounded-lg hover:bg-green-600">下载
+ Note: 转换速度取决于输入路由表长度
diff --git a/src/index.js b/src/index.js
index dd12143..95d08ef 100644
--- a/src/index.js
+++ b/src/index.js
@@ -88,11 +88,11 @@ function routeToCIDR(routeRawStr) {
);
});
- cidrAddressList.forEach((network) => {
- console.log(`${network.networkAddress}/${network.subnetMaskLength}`);
- });
+ // cidrAddressList.forEach((network) => {
+ // console.log(`${network.networkAddress}/${network.subnetMaskLength}`);
+ // });
- return cidrAddressList; // 返回CIDR地址列表
+ return cidrAddressList; // 返回CIDR列表
}
function convertCIDRListToStr(cidrAddressList, formatFn, header = "") {
@@ -153,20 +153,6 @@ document.addEventListener("DOMContentLoaded", () => {
inputElement.placeholder = exampleRouteInput;
configContainer.style.display = "none";
- // 定义转换按钮点击事件通用处理函数
- function handleButtonClick(convertFunction, extraParam = null) {
- const routeInput =
- inputElement.value.trim() === ""
- ? exampleRouteInput
- : inputElement.value;
- const cidrAddressList = routeToCIDR(routeInput);
- const result = extraParam
- ? convertFunction(cidrAddressList, extraParam)
- : convertFunction(cidrAddressList);
- outputElement.textContent = result;
- showNotification("转换完成!");
- }
-
// 切换显示/隐藏额外设置
function toggleConfigContainer(show) {
configContainer.style.display = show ? "block" : "none";
@@ -185,14 +171,29 @@ document.addEventListener("DOMContentLoaded", () => {
}, 3000);
}
+ // 定义转换按钮点击事件通用处理函数
+ function handleButtonClick(convertFunction, extraParam = null) {
+ showNotification("正在转换路由表至CIDR~ 转换速度取决于路由表长度");
+
+ const routeInput =
+ inputElement.value.trim() === ""
+ ? exampleRouteInput
+ : inputElement.value;
+ const cidrAddressList = routeToCIDR(routeInput);
+ const result = extraParam
+ ? convertFunction(cidrAddressList, extraParam)
+ : convertFunction(cidrAddressList);
+ outputElement.textContent = result;
+
+ showNotification("转换完成!");
+ }
+
// 添加事件监听器
buttonToClash.addEventListener("click", () => {
- showNotification("正在转换路由至CIDR~ 转换速度取决于路由表长度");
handleButtonClick(convertCIDRListToClashStr);
toggleConfigContainer(false);
});
buttonToSSTap.addEventListener("click", () => {
- showNotification("正在转换路由至CIDR~ 转换速度取决于路由表长度");
handleButtonClick(
convertCIDRListToSSTapStr,
sstapHeaderElement.value.trim(),
@@ -200,7 +201,6 @@ document.addEventListener("DOMContentLoaded", () => {
toggleConfigContainer(true);
});
buttonToNetch.addEventListener("click", () => {
- showNotification("正在转换路由至CIDR~ 转换速度取决于路由表长度");
handleButtonClick(convertCIDRListToNetchStr);
toggleConfigContainer(false);
});