mirror of
https://github.com/KOP-XIAO/QuantumultX.git
synced 2026-01-25 17:15:09 +00:00
Merge pull request #97 from 1nC0deWeTrust/master
Update resource-parser.js
This commit is contained in:
@@ -1413,44 +1413,47 @@ function Rule_Policy(content) { //增加、替换 policy
|
||||
|
||||
// 处理纯列表, 包含 clash-provider
|
||||
function rule_list_handle(cnt) {
|
||||
var RuleK = ["//", "#", ";","[", "!","/"]
|
||||
var RuleK = ["//", "#", ";", "[", "!", "/"]
|
||||
const RuleCheck = (item) => cnt.trim().indexOf(item) == 0; //无视注释行
|
||||
const nocheck = (item) => /^\d+$/.test(item) //检查数字项
|
||||
cnt = cnt.split("#")[0].trim() // 去除注释部分
|
||||
if(cnt.trim().indexOf(" ")==-1 && cnt.trim()!= "" && !RuleK.some(RuleCheck)){
|
||||
if(cnt.indexOf("::")!=-1 && cnt.indexOf("/")!=-1) { // ip-v6?
|
||||
if (cnt.trim().indexOf(" ") == -1 && cnt.trim() != "" && !RuleK.some(RuleCheck)) {
|
||||
if (cnt.indexOf("::") != -1 && cnt.indexOf("/") != -1) { // ip-v6?
|
||||
cnt = "ip6-cidr, " + cnt
|
||||
cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy
|
||||
cnt = Ppolicy == "Shawn" ? cnt + ", Shawn" : cnt + ", " + Ppolicy
|
||||
} else if (cnt.split("/").length == 2) {//ip-cidr
|
||||
cnt = "ip-cidr, " + cnt
|
||||
cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy
|
||||
cnt = Ppolicy == "Shawn" ? cnt + ", Shawn" : cnt + ", " + Ppolicy
|
||||
} else if (cnt.split(".").length == 4 && cnt.split(".").every(nocheck)) { // ip 类规则
|
||||
cnt = "ip-cidr, " + cnt+ "/32"
|
||||
cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy
|
||||
} else if (cnt.indexOf("payload:")==-1) { //host - suffix, not clash rule list
|
||||
cnt = "ip-cidr, " + cnt + "/32"
|
||||
cnt = Ppolicy == "Shawn" ? cnt + ", Shawn" : cnt + ", " + Ppolicy
|
||||
} else if (cnt.indexOf("payload:") == -1) { //host - suffix, not clash rule list
|
||||
//$notify("xxx","xxxx",cnt)
|
||||
//cnt=cnt.replace(/'|"/g,"").trim()//replace(/'|"|\+\.|\*\.|\*\.\*/g,"") 2023-04-10
|
||||
if(!/^('|")/.test(cnt)) { // not clash-provider
|
||||
if(!/\*|\+/.test(cnt[0])) {
|
||||
cnt = cnt[0]=="." ? cnt.replace(".",""): cnt
|
||||
|
||||
if (!/^('|")/.test(cnt)) { // not clash-provider
|
||||
if (!/\*|\+/.test(cnt[0])) {
|
||||
cnt = cnt[0] == "." ? cnt.replace(".", "") : cnt
|
||||
cnt = "host-suffix, " + cnt
|
||||
} else {
|
||||
cnt = "host-wildcard, " + cnt
|
||||
}
|
||||
} else { // clash provider
|
||||
cnt=cnt.replace(/'|"/g,"").trim()
|
||||
if ( /^(\*\.|\.)/.test(cnt) || cnt.indexOf("*")!=-1) {
|
||||
cnt = "host-wildcard, " + cnt
|
||||
} else {
|
||||
cnt = "host-suffix, " + cnt.replace(/\+\./,"")
|
||||
}
|
||||
}
|
||||
cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy
|
||||
}
|
||||
cnt = cnt.replace(/'|"/g, "").trim()
|
||||
|
||||
if (/^\.|\*\./.test(cnt) || cnt.indexOf("*") != -1) {
|
||||
//1.以.或*.开头 -> 匹配子域名,wildcard,*.domain
|
||||
//2.直接替换开头,正则未匹配 -> 不以*.开头的字符串但包含*的情况(wildcard,a.*.domain...)
|
||||
cnt = "host-wildcard, " + cnt.replace(/^\.|\*\./, "*.")
|
||||
} else {
|
||||
cnt = "host-suffix, " + cnt.replace(/^(\+\.)/, "")//如果以+.开头 = 匹配当前域名及其子域名,采用 suffix,domain。
|
||||
}
|
||||
}
|
||||
cnt = Ppolicy == "Shawn" ? cnt + ", Shawn" : cnt + ", " + Ppolicy
|
||||
}
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
}
|
||||
|
||||
// Domain-Set
|
||||
function Domain2Rule(content) {
|
||||
|
||||
Reference in New Issue
Block a user