(subs, Pout, Pin)
| 1184 | |
| 1185 | //分流规则转换及过滤(in&out),可用于 surge 及 quanx 的 rule-list |
| 1186 | function Rule_Handle(subs, Pout, Pin) { |
| 1187 | cnt = subs //.split("\n"); |
| 1188 | Tin = Pin; //保留参数 |
| 1189 | Tout = Pout; //过滤参数 |
| 1190 | ply = Ppolicy; //策略组 |
| 1191 | var nlist = [] |
| 1192 | var RuleK = ["//", "#", ";","[","^"]; //排除项目 |
| 1193 | var RuleK2 = ["host,", "-suffix,", "domain,", "-keyword,", "ip-cidr,", "ip-cidr6,", "geoip,", "user-agent,", "ip6-cidr,", "ip-asn"]; |
| 1194 | if (Tout != "" && Tout != null) { // 有 out 参数时 |
| 1195 | var dlist = []; |
| 1196 | for (var i = 0; i < cnt.length; i++) { |
| 1197 | cc = cnt[i].replace(/^\s*\-\s/g,"").replace(/\"|\'/g,"").trim() |
| 1198 | //$notify("out ing", Tout, cc) |
| 1199 | const exclude = (item) => cc.indexOf(item) != -1; // 删除项 |
| 1200 | const RuleCheck = (item) => cc.toLowerCase().indexOf(item) != -1; //规则检查 |
| 1201 | const CommentCheck = (item) => cc.toLowerCase().indexOf(item) == 0; //无视注释行 |
| 1202 | if (Tout.some(exclude) && !RuleK.some(CommentCheck) ) { |
| 1203 | // 2022-12-15 删除 && RuleK2.some(RuleCheck) 判断条件,以免 list/provider 中参数上生效 |
| 1204 | dlist.push("-" + Rule_Policy(cc)) // 注释掉条目 |
| 1205 | } else if (!RuleK.some(CommentCheck) && cc ) { //if Pout.some, 不操作注释项,不操作不识别规则项目 |
| 1206 | // 2022-12-15 删除 && RuleK2.some(RuleCheck) 判断条件,以免 list/provider 中参数上生效 |
| 1207 | dd = Rule_Policy(cc); |
| 1208 | if (Tin != "" && Tin != null) { |
| 1209 | const include = (item) => dd.indexOf(item) != -1; // 保留项 |
| 1210 | if (Tin.some(include)) { |
| 1211 | nlist.push(dd); |
| 1212 | } |
| 1213 | } else { |
| 1214 | nlist.push(dd); |
| 1215 | } |
| 1216 | } //else if cc |
| 1217 | }//for cnt |
| 1218 | var no = dlist.length <= 10 ? emojino[dlist.length] : dlist.length |
| 1219 | if (dlist.length > 0) { |
| 1220 | if (Pntf0 != 0) { $notify("🤖 " + "分流引用 ➟ " + "⟦" + subtag + "⟧", "⛔️ 禁用: " + Tout, "☠️ 已禁用以下" + no + "条匹配规则:" + "\n ⨷ " + dlist.join("\n ⨷ "), rule_link) } |
| 1221 | } else { $notify("🤖 " + "分流引用 ➟ " + "⟦" + subtag + "⟧", "⛔️ 禁用: " + Tout, "⚠️ 未发现任何匹配项, 请检查参数或原始链接", nan_link) } |
| 1222 | if (Tin != "" && Tin != null) { //有 in 跟 out 参数时 |
| 1223 | if (nlist.length > 0) { |
| 1224 | var noin0 = nlist.length <= 10 ? emojino[nlist.length] : nlist.length |
| 1225 | if (Pntf0 != 0) { |
| 1226 | $notify("🤖 " + "分流引用 ➟ " + "⟦" + subtag + "⟧", "✅ 保留:" + Tin, "🎯 已保留以下 " + noin0 + "条匹配规则:" + "\n ⨁ " + nlist.join("\n ⨁ "), rule_link) |
| 1227 | } |
| 1228 | } else { |
| 1229 | $notify("🤖 " + "分流引用 ➟ " + "⟦" + subtag + "⟧", "✅ 保留:" + Tin + ",⛔️ 禁用: " + Tout, "⚠️ 筛选后剩余规则数为 0️⃣ 条, 请检查参数及原始链接", nan_link) |
| 1230 | } |
| 1231 | } else {// if Tin (No Tin) |
| 1232 | if (nlist.length == 0) { |
| 1233 | $notify("🤖 " + "分流引用 ➟ " + "⟦" + subtag + "⟧", "⛔️ 禁用: " + Tout, "⚠️ 筛选后剩余规则数为 0️⃣ 条, 请检查参数及原始链接", nan_link) |
| 1234 | } |
| 1235 | } |
| 1236 | nlist =Phide ==1? nlist : [...dlist,...nlist] |
| 1237 | //return nlist; |
| 1238 | } else if (Tin != "" && Tin != null) { //if Tout |
| 1239 | var dlist = []; |
| 1240 | for (var i = 0; i < cnt.length; i++) { |
| 1241 | cc = cnt[i].replace(/^\s*\-\s/g,"").trim() |
| 1242 | const RuleCheck = (item) => cc.indexOf(item) != -1; //无视注释行 |
| 1243 | const CommentCheck = (item) => cc.toLowerCase().indexOf(item) == 0; //无视注释行 |
no test coverage detected