性能优化
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// ===================== 伪节点过滤 =====================
|
||||
// 单点定义:托盘菜单、自动切换、前端显示过滤(ProxyModule.vue 的 PSEUDO_NODE_KEYWORDS
|
||||
// 与之对应)统一引用此处,避免多份关键词列表漂移。
|
||||
|
||||
/// 订阅节点名中常见的营销/占位关键词(订阅页插入的非真实节点)
|
||||
const PSEUDO_KEYWORDS: &[&str] = &[
|
||||
"DIRECT",
|
||||
"REJECT",
|
||||
"PASS",
|
||||
"COMPATIBLE",
|
||||
"流量",
|
||||
"套餐",
|
||||
"到期",
|
||||
"续费",
|
||||
"官网",
|
||||
"网站",
|
||||
"刷新",
|
||||
"更新",
|
||||
"⭐",
|
||||
"★",
|
||||
"☆",
|
||||
"✕",
|
||||
"✖",
|
||||
"×",
|
||||
];
|
||||
|
||||
/// 判断节点名是否为伪节点(DIRECT/REJECT 等内置策略或订阅营销占位)
|
||||
pub fn is_pseudo_node(name: &str) -> bool {
|
||||
let upper = name.trim().to_uppercase();
|
||||
if upper == "DIRECT" || upper == "REJECT" || upper == "PASS" || upper == "GLOBAL" {
|
||||
return true;
|
||||
}
|
||||
PSEUDO_KEYWORDS.iter().any(|kw| name.contains(kw))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod pseudo_node_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn builtin_policies_are_pseudo() {
|
||||
assert!(is_pseudo_node("DIRECT"));
|
||||
assert!(is_pseudo_node("REJECT"));
|
||||
assert!(is_pseudo_node("PASS"));
|
||||
assert!(is_pseudo_node("GLOBAL"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn case_insensitive_and_trims_whitespace() {
|
||||
assert!(is_pseudo_node("direct"));
|
||||
assert!(is_pseudo_node(" Reject "));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marketing_keywords_are_pseudo() {
|
||||
assert!(is_pseudo_node("香港流量套餐"));
|
||||
assert!(is_pseudo_node("官网专线"));
|
||||
assert!(is_pseudo_node("VIP到期续费"));
|
||||
assert!(is_pseudo_node("每月更新"));
|
||||
assert!(is_pseudo_node("★香港节点"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_nodes_are_not_pseudo() {
|
||||
assert!(!is_pseudo_node("HK-01"));
|
||||
assert!(!is_pseudo_node("美国洛杉矶 01"));
|
||||
assert!(!is_pseudo_node("JP Tokyo 2G"));
|
||||
assert!(!is_pseudo_node(""));
|
||||
assert!(!is_pseudo_node("Node-2024"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user