// Define the `main` function
// function main(params) {
// return params;
// }
// Define the `main` function
function main(params) {
// Hong Kong Region
const hongKongRegex = /Hong Kong|HK|Hong|🇭🇰/;
const hongKongProxies = params.proxies
.filter((e) => hongKongRegex.test(e.name))
.map((e) => e.name);
// Taiwan Region
const taiwanRegex = /Taiwan|TW|Taiwan|Wan|🇨🇳|🇹🇼/;
const taiwanProxies = params.proxies
.filter((e) => taiwanRegex.test(e.name))
.map((e) => e.name);
// Lion City Region
const singaporeRegex = /Singapore|Lion City|SG|Singapore|🇸🇬/;
const singaporeProxies = params.proxies
.filter((e) => singaporeRegex.test(e.name))
.map((e) => e.name);
// Japan Region
const japanRegex = /Japan|JP|Japan|🇯🇵/;
const japanProxies = params.proxies
.filter((e) => japanRegex.test(e.name))
.map((e) => e.name);
// United States Region
const americaRegex = /United States|US|United States|America|🇺🇸/;
const americaProxies = params.proxies
.filter((e) => americaRegex.test(e.name))
.map((e) => e.name);
// Other Regions
const othersRegex = /Hong Kong|HK|Hong|🇭🇰|Taiwan|TW|Taiwan|Wan|🇨🇳|🇹🇼|Singapore|SG|Singapore|Lion City|🇸🇬|Japan|JP|Japan|🇯🇵|United States|US|States|America|🇺🇸|automatic|failure|traffic|official website|package|airport|subscription/;
const othersProxies = params.proxies
.filter((e) => !othersRegex.test(e.name))
.map((e) => e.name);
// All Regions
const allRegex = /automatic|failure|traffic|official website|package|airport|subscription/;
const allProxies = params.proxies
.filter((e) => !allRegex.test(e.name))
.map((e) => e.name);
// Hong Kong
const HongKong = {
name: "HongKong",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: hongKongProxies.length > 0 ? hongKongProxies : ["DIRECT"]
};
// Taiwan
const TaiWan = {
name: "TaiWan",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: taiwanProxies.length > 0 ? taiwanProxies : ["DIRECT"]
};
// Lion City
const Singapore = {
name: "Singapore",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: singaporeProxies.length > 0 ? singaporeProxies : ["DIRECT"]
};
// Japan
const Japan = {
name: "Japan",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: japanProxies.length > 0 ? japanProxies : ["DIRECT"]
};
// United States
const America = {
name: "America",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: americaProxies.length > 0 ? americaProxies : ["DIRECT"]
};
// Others
const Others = {
name: "Others",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: othersProxies.length > 0 ? othersProxies : ["DIRECT"]
};
// Automatic
const Auto = {
name: "Auto",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
};
// Load Balancing
const Balance = {
name: "Balance",
type: "load-balance",
url: "http://www.gstatic.com/generate_204",
interval: 300,
strategy: "consistent-hashing",
lazy: true,
proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
};
// Failover
const Fallback = {
name: "Fallback",
type: "fallback",
url: "http://www.gstatic.com/generate_204",
interval: 300,
lazy: true,
proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
};
// Foreign Groups
const G = ["Proxy", "Auto", "Balance", "Fallback", "HongKong", "TaiWan", "Singapore", "Japan", "America", "Others"];
// Domestic Groups
const M = ["DIRECT", "Proxy", "Auto", "Balance", "Fallback", "HongKong", "TaiWan", "Singapore", "Japan", "America", "Others"];
// AI Groups
const AI = ["Proxy", "America", "Japan", "Singapore", "TaiWan", "HongKong", "Others"];
// Last Resort
const Final = { name: "Final", type: "select", proxies: ["DIRECT", "Global", "Proxy"] };
// Manual Selection
const Proxy = { name: "Proxy", type: "select", proxies: allProxies.length > 0 ? allProxies : ["DIRECT"] };
// Foreign Websites
const Global = { name: "Global", type: "select", proxies: G };
// Domestic Websites
const Mainland = { name: "Mainland", type: "select", proxies: M };
// Artificial Intelligence
const ArtIntel = { name: "ArtIntel", type: "select", proxies: AI };
// YouTube Videos
const YouTube = { name: "YouTube", type: "select", proxies: G };
// Bilibili
const BiliBili = { name: "BiliBili", type: "select", proxies: ["DIRECT", "HongKong", "TaiWan"] };
// International Media
const Streaming = { name: "Streaming", type: "select", proxies: G };
// Telegram Information
const Telegram = { name: "Telegram", type: "select", proxies: G };
// Google Services
const Google = { name: "Google", type: "select", proxies: G };
// Gaming Platforms
const Games = { name: "Games", type: "select", proxies: G };
const groups = params["proxy-groups"] = [];
// Rules
const rules = [
"AND,(AND,(DST-PORT,443),(NETWORK,UDP)),(NOT,((GEOIP,CN))),REJECT",// quic
// "GEOSITE,Category-ads-all,REJECT", // May cause some websites to be inaccessible
"GEOSITE,Private,DIRECT",
"GEOSITE,Category-games@cn,Mainland",
"GEOSITE,Microsoft@cn,Mainland",
"GEOSITE,Apple@cn,Mainland",
"GEOSITE,Bing,ArtIntel",
"GEOSITE,Openai,ArtIntel",
"GEOSITE,Category-games,Games",
"GEOSITE,Github,Global",
"GEOSITE,Telegram,Telegram",
"GEOSITE,Youtube,YouTube",
"GEOSITE,Disney,Streaming",
"GEOSITE,Netflix,Streaming",
"GEOSITE,HBO,Streaming",
"GEOSITE,Primevideo,Streaming",
"GEOSITE,Bilibili,BiliBili",
"GEOSITE,Google,Google",
"GEOSITE,Geolocation-!cn,Global",
"GEOIP,CN,Mainland,no-resolve",
"MATCH,Final"
];
// Insert Groups
groups.unshift(HongKong, TaiWan, Japan, Singapore, America, Others, Auto, Balance, Fallback);
groups.unshift(Final, Proxy, Global, Mainland, ArtIntel, YouTube, BiliBili, Streaming, Telegram, Google, Games);
// Insert Rules
params.rules = rules;
return params;
}