| 2687 | } |
| 2688 | |
| 2689 | function YAMLFix(cnt){ |
| 2690 | cnt = cnt.replace(/\[/g,"yaml@bug1").replace(/\\r/g,"").replace(/\*/g,"yaml@bug2") |
| 2691 | //2022-08-08 增加 .replace(/\*/g,"🌟@bug2") 以解决名字以 * 开始时引起的部分问题 |
| 2692 | if (cnt.indexOf("{") != -1 && /\{\s*\"*(name|type|server)/.test(cnt)){ |
| 2693 | cnt = cnt.replace(/(^|\n)- /g, "$1 - ").replace(/ - /g," - ").replace(/:(?!\s)/g,": ").replace(/\,\"/g,", \"").replace(/: {/g, ": {, ").replace(/, (Host|host|path|mux)/g,", $1") |
| 2694 | //2022-04-11 remove tls|skip from replace(/, (Host|host|path|mux)/g,", $1") |
| 2695 | console.log("1st:\n"+cnt) |
| 2696 | cnt = cnt.replace(/{\s*name: /g,"{name: \"").replace(/, server:/g,"\", server:") |
| 2697 | cnt = cnt.replace(/{|}/g,"").replace(/,/g,"\n ") |
| 2698 | } |
| 2699 | cnt = cnt.replace(/\n\s*\-\s*\n.*name/g,"\n - name").replace(/\$|\`/g,"").split("proxy-providers:")[0].split("proxy-groups:")[0].replace(/\"(name|type|server|port|cipher|password|uuid|alterId|udp)(\"*)/g,"$1") |
| 2700 | if(Pdbg == 1) { |
| 2701 | $notify("part-fix0:","","part-fix0:\nproxies:\n"+cnt.split("proxies:")[1])} |
| 2702 | // 2023-03-23 👇修正部分类型 |
| 2703 | cnt = cnt.replace(/\n\s{2}([a-zA-Z]+.*\:)/g,"\n $1").replace(/\n(\-.*)/g,"\n $1") |
| 2704 | if(Pdbg == 1) { |
| 2705 | $notify("part-fix1:","","part-fix1:\nproxies:\n"+cnt.split("proxies:")[1])} |
| 2706 | // cnt = cnt.indexOf("proxies:") == -1? "proxies:\n" + cnt :"proxies:"+cnt.split("proxies:")[1] |
| 2707 | cnt = cnt.replace(/name\:(.*?)\:(.*?)\n/gmi,"name:$1冒号$2\n").replace(/\s{6}Host\:/g," Host:")//.replace(/\{\s*(Host\:.*)\}/gmi,"$1") //罕见bug情况 修复 |
| 2708 | items=cnt.split("\n").map(yamlcheck) |
| 2709 | cnt=items.join("\n") |
| 2710 | //console.log(cnt.replace(/name\:(.*?)\:(.*?)\n/gmi,"name:$1冒号$2")) |
| 2711 | //2022-05-11 增加⬇️ |
| 2712 | //cnt = cnt.replace(/\n\s{4}headers/g,"\n headers").replace(/\n\s{6}(H|h)ost/g,"\n Host").replace(/\t/g,"") |
| 2713 | //2022-06-07 修改为👇,解决部分无 proxies 字段的 |
| 2714 | //2022-09-01 remove host in s{6}(H|h)ost |
| 2715 | //cnt = cnt.indexOf("proxies:") != -1?cnt.replace(/\n\s{4}headers/g,"\n headers").replace(/\n\s{6}Host/g,"\n Host").replace(/\t/g,""):cnt |
| 2716 | //2022-11-29 修改 |
| 2717 | cnt = cnt.indexOf("proxies:") != -1 && /\n\s{4}server/.test(cnt) ? cnt.replace(/\n\s{4}(headers|path)/g,"\n $1").replace(/\n\s{6}Host/g,"\n Host").replace(/\t/g,""):cnt |
| 2718 | //console.log("part-fix:\n"+cnt.split("proxies:")[1]) |
| 2719 | cnt = cnt.indexOf("proxies:") == -1? "proxies:\n" + cnt :"proxies:"+cnt.split("proxies:")[1] |
| 2720 | console.log("after-fix\n"+cnt) |
| 2721 | if(Pdbg == 1) { |
| 2722 | $notify("After-Fix","this is", "After-fix:\n"+cnt)} |
| 2723 | //$notify("After-Fix","this is", cnt) |
| 2724 | |
| 2725 | return cnt |
| 2726 | } |
| 2727 | |
| 2728 | |
| 2729 | function yamlcheck(cnt){ |