1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
. /usr/share/openclash/log.sh
. /lib/functions.sh
# This script is called by /etc/init.d/openclash
# Add your custom firewall rules here, they will be added after the end of the OpenClash iptables rules
LOG_OUT "Tip: Start Add Custom Firewall Rules..."

# ==========================================
# 删除已存在的 AdBlock DNSMasq 规则文件
rm /tmp/dnsmasq.d/anti-ad-for-dnsmasq.conf
rm /tmp/dnsmasq.d/adblockdnsmasq.txt
# 以下是广告过滤规则拉取脚本
LOG_OUT "拉取 AdBlock DNSMasq 广告过滤规则…"
curl -s https://raw.githubusercontent.com/Aethersailor/adblockfilters/main/rules/adblockdnsmasq.txt -o /tmp/dnsmasq.d/adblockdnsmasq.txt
# 广告过滤规则拉取脚本结束

# 以下是 GitHub520 加速规则拉取脚本
LOG_OUT "拉取 GitHub520 加速规则…"
sed -i '/# GitHub520 Host Start/,/# GitHub520 Host End/d' /etc/hosts
curl https://raw.hellogithub.com/hosts >> /etc/hosts
sed -i '/^$/d' /etc/hosts
sed -i '/!/d' /etc/hosts
# GitHub520 加速规则拉取脚本结束

# 清理 DNS 缓存
LOG_OUT "清理 DNS 缓存…"
/etc/init.d/dnsmasq restart
/etc/init.d/dnsmasq reload
/etc/init.d/dnsmasq restart
# ==========================================

exit 0
exit 0

2025-03-08

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
. /usr/share/openclash/log.sh
. /lib/functions.sh
# This script is called by /etc/init.d/openclash
# Add your custom firewall rules here, they will be added after the end of the OpenClash iptables rules
LOG_OUT "Tip: Start Add Custom Firewall Rules..."

# ==========================================
# 删除已存在的 AdBlock DNSMasq 规则文件
rm -f /tmp/dnsmasq.d/anti-ad-for-dnsmasq.conf
rm -f /tmp/dnsmasq.d/adblockdnsmasq.txt
rm -rf /tmp/dnsmasq.cfg01411c.d
# 以下是广告过滤规则拉取脚本
LOG_OUT "拉取 AdBlock DNSMasq 广告过滤规则…"
curl -s https://github.boki.moe/https://raw.githubusercontent.com/Aethersailor/adblockfilters-modified/main/rules/adblockdnsmasq.txt -o /tmp/dnsmasq.d/adblockdnsmasq.txt
# 广告过滤规则拉取脚本结束

# 以下是 GitHub520 加速规则拉取脚本
LOG_OUT "拉取 GitHub520 加速规则…"
sed -i '/# GitHub520 Host Start/,/# GitHub520 Host End/d' /etc/hosts
curl https://raw.hellogithub.com/hosts >> /etc/hosts
sed -i '/^$/d' /etc/hosts
sed -i '/!/d' /etc/hosts
# GitHub520 加速规则拉取脚本结束

# 清理 DNS 缓存
LOG_OUT "清理 DNS 缓存…"
/etc/init.d/dnsmasq restart
/etc/init.d/dnsmasq reload
/etc/init.d/dnsmasq restart
/etc/init.d/dnsmasq reload
# ==========================================

exit 0
exit 0
origin
1
2
3
4
5
6
7
8
9
10
#!/bin/sh
. /usr/share/openclash/log.sh
. /lib/functions.sh

# This script is called by /etc/init.d/openclash
# Add your custom firewall rules here, they will be added after the end of the OpenClash iptables rules

LOG_OUT "Tip: Start Add Custom Firewall Rules..."

exit 0

Grok3优化版(2025-03-09)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
. /usr/share/openclash/log.sh
. /lib/functions.sh

# This script is called by /etc/init.d/openclash
# Add custom firewall rules here; they will be appended after OpenClash iptables rules

LOG_OUT "Tip: Start Add Custom Firewall Rules..."

# ============= Ad Filtering Rules Fetching Script =============
(
# Configuration for waiting on OpenClash
MAX_WAIT_TIME=30
WAIT_INTERVAL=2
elapsed_time=0

# Wait for OpenClash to start
if /etc/init.d/openclash status | grep -q "Syntax:"; then
LOG_OUT "[Ad Filter Script] Waiting 10 seconds to ensure OpenClash has started..."
sleep 10
else
while ! /etc/init.d/openclash status | grep -q "running"; do
if [ $elapsed_time -ge $MAX_WAIT_TIME ]; then
LOG_OUT "[Ad Filter Script] OpenClash not detected within 30 seconds, stopping script..."
exit 1
fi
LOG_OUT "[Ad Filter Script] Checking OpenClash status, please wait..."
sleep $WAIT_INTERVAL
elapsed_time=$((elapsed_time + WAIT_INTERVAL))
done
LOG_OUT "[Ad Filter Script] OpenClash is running, starting rule fetch in 10 seconds..."
sleep 10
fi

# Clear existing ad filtering rules
LOG_OUT "[Ad Filter Script] Clearing existing ad filtering rules..."
rm -f /tmp/dnsmasq.d/*ad*.conf
rm -f /tmp/dnsmasq.cfg01411c.d/*ad*.conf
sed -i '/# AWAvenue-Ads-Rule Start/,/# AWAvenue-Ads-Rule End/d' /etc/hosts

# Fetch adblockfilters-modified rules with timeouts and retries
LOG_OUT "[Ad Filter Script] Fetching latest adblockfilters-modified rules (large file, please wait)..."
mkdir -p /tmp/dnsmasq.d
curl -sSL -4 \
--connect-timeout 30 \
--max-time 600 \
--retry 50 \
--retry-delay 2 \
--retry-all-errors \
"https://github.boki.moe/https://raw.githubusercontent.com/Aethersailor/adblockfilters-modified/main/rules/adblockdnsmasq.txt" \
-o /tmp/dnsmasq.d/adblockfilters-for-dnsmasq.conf \
2> /tmp/adblockfilters-modified-curl.log

if [ $? -ne 0 ]; then
rm -f /tmp/dnsmasq.d/adblockfilters-for-dnsmasq.conf
LOG_OUT "[Ad Filter Script] Failed to fetch adblockfilters-modified rules, see /tmp/adblockfilters-modified-curl.log for details."
else
LOG_OUT "[Ad Filter Script] Successfully fetched adblockfilters-modified rules!"
fi

# Clear existing GitHub520 rules
LOG_OUT "[Ad Filter Script] Clearing existing GitHub520 acceleration rules..."
sed -i '/# GitHub520 Host Start/,/# GitHub520 Host End/d' /etc/hosts

# Fetch GitHub520 rules with timeouts and retries to a temporary file
LOG_OUT "[Ad Filter Script] Fetching latest GitHub520 acceleration rules..."
temp_file=$(mktemp)
curl -sSL -4 \
--connect-timeout 30 \
--max-time 600 \
--retry 50 \
--retry-delay 2 \
--retry-all-errors \
"https://raw.hellogithub.com/hosts" \
> "$temp_file" 2> /tmp/github520-curl.log

# Validate and append GitHub520 rules
if [ $? -eq 0 ] && grep -q "# GitHub520 Host Start" "$temp_file" && grep -q "# GitHub520 Host End" "$temp_file"; then
cat "$temp_file" >> /etc/hosts
LOG_OUT "[Ad Filter Script] Successfully fetched GitHub520 acceleration rules!"
else
LOG_OUT "[Ad Filter Script] Failed to fetch GitHub520 rules or content invalid, see /tmp/github520-curl.log for details."
fi
rm -f "$temp_file"

# Clean up /etc/hosts
sed -i '/^$/d' /etc/hosts # Remove empty lines
sed -i '/!/d' /etc/hosts # Remove lines with '!'

# Reload dnsmasq to apply changes
LOG_OUT "[Ad Filter Script] Reloading DNS cache..."
/etc/init.d/dnsmasq reload
/etc/init.d/dnsmasq restart
LOG_OUT "[Ad Filter Script] Script execution completed!"

) &
# ============= End of Ad Filtering Rules Fetching Script =============

exit 0
exit 0
SuperGrok-Think思考优化版(2025-03-26)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# ==============以下是广告过滤规则拉取脚本=================
(
VERSION="1.4"
MAX_WAIT_TIME=30
WAIT_INTERVAL=2
elapsed_time=0

LOG_OUT "[广告过滤规则拉取脚本] 当前版本 $VERSION,正在检测 OpenClash 运行状态..."

if /etc/init.d/openclash status | grep -q "Syntax:"; then
LOG_OUT "[广告过滤规则拉取脚本] 检测到 OpenClash 语法错误,等待 10 秒以确保 OpenClash 已启动..."
sleep 10
else
while ! /etc/init.d/openclash status | grep -q "running"; do
if [ $elapsed_time -ge $MAX_WAIT_TIME ]; then
LOG_OUT "[广告过滤规则拉取脚本] 未能在 30 秒内检测到 OpenClash 运行状态,脚本已停止运行..."
exit 1
fi
LOG_OUT "[广告过滤规则拉取脚本] 正在检查 OpenClash 状态,请稍候..."
sleep $WAIT_INTERVAL
elapsed_time=$((elapsed_time + WAIT_INTERVAL))
done
LOG_OUT "[广告过滤规则拉取脚本] 检测到 OpenClash 正在运行,10 秒后开始拉取规则..."
sleep 10
fi

LOG_OUT "[广告过滤规则拉取脚本] 开始检测 dnsmasq 规则目录..."
UCI_OUTPUT=$(uci show dhcp.@dnsmasq[0] 2>/dev/null)

if echo "$UCI_OUTPUT" | grep -qE 'cfg[0-9a-f]{6}'; then
HASH_ID=$(echo "$UCI_OUTPUT" | grep -oE 'cfg[0-9a-f]{6}' | head -1)
TARGET_DIR="/tmp/dnsmasq.${HASH_ID}.d"
LOG_OUT "[广告过滤规则拉取脚本] 当前 dnsmasq 规则目录: $TARGET_DIR"
elif echo "$UCI_OUTPUT" | grep -qE '@dnsmasq\[[0-9]+\]'; then
TARGET_DIR="/tmp/dnsmasq.d"
LOG_OUT "[广告过滤规则拉取脚本] 当前 dnsmasq 规则目录: $TARGET_DIR"
else
TARGET_DIR=$(find /tmp -maxdepth 1 -type d -name "dnsmasq.*.d" | head -n 1)
if [ -z "$TARGET_DIR" ]; then
LOG_OUT "[广告过滤规则拉取脚本] 错误:未找到有效的 dnsmasq 规则目录,脚本已停止!"
exit 1
fi
LOG_OUT "[广告过滤规则拉取脚本] 检测失败,使用已存在的 dnsmasq 规则目录: $TARGET_DIR"
fi

if [ ! -d "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
fi

LOG_OUT "[广告过滤规则拉取脚本] 清除已有规则…"
rm -f "$TARGET_DIR"/*ad*.conf
sed -i '/# AWAvenue-Ads-Rule Start/,/# AWAvenue-Ads-Rule End/d' /etc/hosts
sed -i '/# GitHub520 Host Start/,/# GitHub520 Host End/d' /etc/hosts

LOG_OUT "[广告过滤规则拉取脚本] 拉取最新的 adblockfilters-modified 广告过滤规则,规则体积较大,请耐心等候…"
curl -sSL -4 \
--connect-timeout 30 \
--max-time 600 \
--retry 50 \
--retry-delay 2 \
--retry-all-errors \
"https://github.boki.moe/https://raw.githubusercontent.com/Aethersailor/adblockfilters-modified/refs/heads/main/rules/adblockdnsmasq.txt" \
-o "$TARGET_DIR/adblockfilters-modified-for-dnsmasq.conf" \
2> /tmp/adblockfilters-modified-curl.log

if [ $? -ne 0 ]; then
rm -f "$TARGET_DIR/adblockfilters-modified-for-dnsmasq.conf"
LOG_OUT "[广告过滤规则拉取脚本] adblockfilters-modified 规则拉取失败,查看 /tmp/adblockfilters-modified-curl.log 获取详细信息。"
else
LOG_OUT "[广告过滤规则拉取脚本] adblockfilters-modified 规则拉取成功!保存路径:${TARGET_DIR}/adblockfilters-modified-for-dnsmasq.conf"
fi

LOG_OUT "[广告过滤规则拉取脚本] 拉取最新的 GitHub520 加速规则…"
temp_file=$(mktemp)
curl -sSL -4 \
--connect-timeout 30 \
--max-time 600 \
--retry 50 \
--retry-delay 2 \
--retry-all-errors \
"https://raw.hellogithub.com/hosts" \
> "$temp_file" 2> /tmp/github520-curl.log

if [ $? -eq 0 ] && grep -q "# GitHub520 Host Start" "$temp_file" && grep -q "# GitHub520 Host End" "$temp_file"; then
cat "$temp_file" >> /etc/hosts
LOG_OUT "[广告过滤规则拉取脚本] GitHub520 加速规则拉取成功!已追加到 /etc/hosts 文件中。"
else
LOG_OUT "[广告过滤规则拉取脚本] GitHub520 加速规则拉取失败或内容无效,查看 /tmp/github520-curl.log 获取详细信息。"
fi
rm -f "$temp_file"

sed -i '/^$/d' /etc/hosts
sed -i '/!/d' /etc/hosts

LOG_OUT "[广告过滤规则拉取脚本] 重新加载 dnsmasq 服务以应用规则…"
/etc/init.d/dnsmasq stop
/etc/init.d/dnsmasq start
LOG_OUT "[广告过滤规则拉取脚本] 脚本运行完毕!"

) &
# ==============广告过滤规则拉取脚本结束==============

1. 订阅转换技巧

1
https://api.asailor.org/sub?target=clash&new_name=true&url=https%3A%2F%2Fxzsajo-github-io.vercel.app%2Fv2&config=https%3A%2F%2Fraw.githubusercontent.com%2FAethersailor%2FCustom_OpenClash_Rules%2Fmain%2Fcfg%2FCustom_Clash.ini&include=&exclude=&emoji=true&list=false&sort=false&udp=true&scv=true&append_type=false&fdn=true&expand=false&classic=true

订阅转换服务地址: https://api.asailor.org/sub
订阅地址: https://xzsajo-github-io.vercel.app/v2
自定义模板地址: https://raw.githubusercontent.com/Aethersailor/Custom_OpenClash_Rules/main/cfg/Custom_Clash.ini
添加Emoji: true
UDP支持: true
跳过证书验证: true
使用规则集: true

encodeURIComponent编码方式,会对特殊符号编码(除【=】【%3D】和【&】【%26】)(仅仅[]):

1
2
3
[订阅转换服务地址]?target=clash&new_name=true&url=[订阅地址]&config=[自定义模板地址]&include=&exclude=&emoji=true&list=false&sort=false&udp=true&scv=true&append_type=false&fdn=true&expand=false&classic=true

https://api.asailor.org/sub?target=clash&new_name=true&url=[订阅地址]&config=[自定义模板地址]&include=&exclude=&emoji=true&list=false&sort=false&udp=true&scv=true&append_type=false&fdn=true&expand=false&classic=true

2. 自定义订阅转换规则(COR/CCR/CSR)

1. OpenClash

COR
DEPOT: https://github.com/xzsajo/Custom_OpenClash_Rules/tree/main/cfg

https://raw.githubusercontent.com/xzsajo/Custom_OpenClash_Rules/main/cfg/Custom_Clash.ini

2. Clash

CCR
DEPOT: https://github.com/xzsajo/Custom_Clash_Rules/tree/main/cfg

Full
https://raw.githubusercontent.com/xzsajo/Custom_Clash_Rules/main/cfg/Custom_Clash_Full.ini

Android
https://raw.githubusercontent.com/xzsajo/Custom_Clash_Rules/main/cfg/Custom_Clash_Android.ini

AdBlock https://gh-proxy.com/https://raw.githubusercontent.com/xzsajo/Custom_Clash_Rules/main/cfg/Custom_Clash_AdBlock.ini

4. 我的Rules

DEPOT: https://github.com/xzsajo/Custom_OpenClash_Rules/tree/main/rule

1. Rule-provider - Direct(直连)

https://raw.githubusercontent.com/xzsajo/Custom_OpenClash_Rules/main/rule/Rule-provider%20-%20Direct.list

2025-03-09 修改为
https://raw.githubusercontent.com/xzsajo/Custom_OpenClash_Rules/main/rule/Rule-provider-Direct.list

2. Rule-provider - Proxy(代理)

https://raw.githubusercontent.com/xzsajo/Custom_OpenClash_Rules/main/rule/Rule-provider%20-%20Proxy.list

2025-03-09 修改为
https://raw.githubusercontent.com/xzsajo/Custom_OpenClash_Rules/main/rule/Rule-provider-Proxy.list

[up主专用,视频内嵌代码贴在这]