From 2c8a29068433d69b369083b1670063793acdc5a8 Mon Sep 17 00:00:00 2001 From: Shawn <45581750+KOP-XIAO@users.noreply.github.com> Date: Wed, 27 Apr 2022 11:58:37 +0800 Subject: [PATCH] wss --- Scripts/resource-parser.js | 47 +++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/Scripts/resource-parser.js b/Scripts/resource-parser.js index bca5847..8c3716c 100644 --- a/Scripts/resource-parser.js +++ b/Scripts/resource-parser.js @@ -1,5 +1,5 @@ /** -☑️ 资源解析器 ©𝐒𝐡𝐚𝐰𝐧 ⟦2022-04-26 22:30⟧ +☑️ 资源解析器 ©𝐒𝐡𝐚𝐰𝐧 ⟦2022-04-27 11:30⟧ ---------------------------------------------------------- 🛠 发现 𝐁𝐔𝐆 请反馈: @ShawnKOP_bot ⛳️ 关注 🆃🅶 相关频道: https://t.me/QuanX_API @@ -2345,22 +2345,42 @@ function LoonSSR2QX(cnt) { // fix yaml parse mistakes +// function YAMLFix(cnt){ +// cnt = cnt.replace(/\[/g,"yaml@bug1") +// if (cnt.indexOf("{") != -1 && /\{\s*name/.test(cnt)){ +// cnt = cnt.replace(/(^|\n)- /g, "$1 - ").replace(/ - /g," - ").replace(/:(?!\s)/g,": ").replace(/\,\"/g,", \"").replace(/: {/g, ": {, ").replace(/, (Host|host|path|mux)/g,", $1") //2022-04-11 remove tls|skip from replace(/, (Host|host|path|mux)/g,", $1") +// //console.log(cnt) +// cnt = cnt.replace(/{\s*name: /g,"{name: \"").replace(/, server:/g,"\", server:") +// cnt = cnt.replace(/{|}/g,"").replace(/,/g,"\n ") +// } +// cnt = cnt.replace(/ -\n.*name/g," - name").replace(/\$|\`/g,"").split("proxy-providers:")[0].split("proxy-groups:")[0].replace(/\"(name|type|server|port|cipher|password|)(\"*)/g,"$1") +// console.log(cnt) +// cnt = cnt.indexOf("proxies:") == -1? "proxies:\n" + cnt :"proxies:"+cnt.split("proxies:")[1] +// cnt = cnt.replace(/name\:(.*?)\:(.*?)\n/gmi,"name:$1冒号$2\n").replace(/\s{6}Host\:/g," Host:") //罕见bug情况 修复 +// items=cnt.split("\n").map(yamlcheck) +// cnt=items.join("\n") +// //console.log(cnt.replace(/name\:(.*?)\:(.*?)\n/gmi,"name:$1冒号$2")) +// console.log("after-fix"+cnt) +// return cnt +// } + function YAMLFix(cnt){ cnt = cnt.replace(/\[/g,"yaml@bug1") if (cnt.indexOf("{") != -1 && /\{\s*name/.test(cnt)){ - cnt = cnt.replace(/(^|\n)- /g, "$1 - ").replace(/ - /g," - ").replace(/:(?!\s)/g,": ").replace(/\,\"/g,", \"").replace(/: {/g, ": {, ").replace(/, (Host|host|path|mux)/g,", $1") //2022-04-11 remove tls|skip from replace(/, (Host|host|path|mux)/g,", $1") - //console.log(cnt) + cnt = cnt.replace(/(^|\n)- /g, "$1 - ").replace(/ - /g," - ").replace(/:(?!\s)/g,": ").replace(/\,\"/g,", \"").replace(/: {/g, ": {, ").replace(/, (Host|host|path|mux)/g,", $1") + //2022-04-11 remove tls|skip from replace(/, (Host|host|path|mux)/g,", $1") + console.log("1st:\n"+cnt) cnt = cnt.replace(/{\s*name: /g,"{name: \"").replace(/, server:/g,"\", server:") cnt = cnt.replace(/{|}/g,"").replace(/,/g,"\n ") } cnt = cnt.replace(/ -\n.*name/g," - name").replace(/\$|\`/g,"").split("proxy-providers:")[0].split("proxy-groups:")[0].replace(/\"(name|type|server|port|cipher|password|)(\"*)/g,"$1") - console.log(cnt) + console.log("part-fix:\n"+cnt.split("proxies:")[1]) cnt = cnt.indexOf("proxies:") == -1? "proxies:\n" + cnt :"proxies:"+cnt.split("proxies:")[1] - cnt = cnt.replace(/name\:(.*?)\:(.*?)\n/gmi,"name:$1冒号$2\n").replace(/\s{6}Host\:/g," Host:") //罕见bug情况 修复 + cnt = cnt.replace(/name\:(.*?)\:(.*?)\n/gmi,"name:$1冒号$2\n").replace(/\s{6}Host\:/g," Host:")//.replace(/\{\s*(Host\:.*)\}/gmi,"$1") //罕见bug情况 修复 items=cnt.split("\n").map(yamlcheck) cnt=items.join("\n") //console.log(cnt.replace(/name\:(.*?)\:(.*?)\n/gmi,"name:$1冒号$2")) - console.log("after-fix"+cnt) + console.log("after-fix\n"+cnt) return cnt } @@ -2385,7 +2405,7 @@ function Clash2QX(cnt) { aa = aa.replace(new RegExp(patn[4][i], "gmi"),patn[0][i]) } var bb = JSON.parse(aa).proxies - //$notify("YAML Parse", "content", JSON.stringify(bb)) + $notify("YAML Parse", "content", JSON.stringify(bb)) //console.log(bb) var nl = bb.length var nodelist=[] @@ -2509,12 +2529,23 @@ function CT2QX(cnt) { ipt = cnt.server+":"+cnt.port pwd = "password=" + cnt.password otls = "over-tls=true" + opath="" + ohost="" cert = cnt["skip-cert-verify"] ? "tls-verification=false" : "tls-verification=true" cert = Pcert0 == 1 ? "tls-verification=true" : "tls-verification=false" tls13 = PTls13 == 1 ? "tls13=true" : "tls13=false" udp = cnt.udp ? "udp-relay=false" : "udp-relay=false" tfo = cnt.tfo ? "fast-open=true" : "fast-open=false" - node = "trojan="+[ipt, pwd, otls, cert, tls13, udp, tfo, tag].filter(Boolean).join(", ") + if (cnt.network=="ws") { //wss类型 + otls = "obfs=wss" + //$notify("trojan","WS",JSON.stringify(cnt)) + if (cnt["ws-opts"]){ + opath = cnt["ws-opts"]["path"]? "obfs-uri="+cnt["ws-opts"]["path"] : "" + ohost = cnt["ws-opts"]["headers"]? "obfs-host="+cnt["ws-opts"]["headers"]["Host"] : "" + } + //$notify("trojan","WS",opath+":"+ohost) + } + node = "trojan="+[ipt, pwd, otls, opath, ohost, cert, tls13, udp, tfo, tag].filter(Boolean).join(", ") //console.log(node) return node