From 60a36ab9862cbe3455c1a591da44dc6319f4edcc Mon Sep 17 00:00:00 2001 From: gently <1243610+gentlyxu@users.noreply.github.com> Date: Thu, 13 Feb 2020 09:44:09 +0800 Subject: [PATCH 1/3] update rules. fixed #37 --- anti-ad-easylist.txt | 10 ++++++++-- tools/easylist-extend.php | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/anti-ad-easylist.txt b/anti-ad-easylist.txt index 92b75ce6..0a35b0ba 100644 --- a/anti-ad-easylist.txt +++ b/anti-ad-easylist.txt @@ -1,5 +1,5 @@ !AdBlock-style blocklists -!VER=20200211100531 +!VER=20200213014222 !URL=https://github.com/privacy-protection-tools/anti-AD ||201*.myhard.com^ ||8*.tianya.cn^ @@ -211,7 +211,7 @@ ||0xxd.com^ ||0z5jn.cn^ ||1-cl0ud.com^ -/^[1-3]\.[0-9a-z\.\-]+\.(com|cn|net|org|cc|me)$/ +/^[1-2]\.[0-9a-z\.\-]+\.(com|cn|net|cc|me)$/ ||92caijing.com^ ||as1.m.hao123.com^ ||mini.hao123.com^ @@ -531,7 +531,10 @@ ||2xbpub.com^ ||2zfzly.com^ ||2zm4.cn^ +||3.chuanyi5.com^ +||3.guidaye.com^ ||ff.guidaye.com^ +||3.ssqzj.com^ ||301848.com^ ||303marketplace.com^ ||304c40d20085e.com^ @@ -30087,3 +30090,6 @@ @@||tongji.*kuwo.cn^ @@||ntp.org^ @@||*push-apple.com.akadns.net^ +@@||tracking.epicgames.com^ +@@||tracker.eu.org^ +@@||1.itzmx.com^ diff --git a/tools/easylist-extend.php b/tools/easylist-extend.php index 14e8a160..bb42c62a 100644 --- a/tools/easylist-extend.php +++ b/tools/easylist-extend.php @@ -70,7 +70,7 @@ $ARR_MERGED_WILD_LIST = array( $ARR_REGEX_LIST = array( '/01daa\.[a-z]+\.com$/' => null, '/9377[a-z]{2}\.com$/' => null, - '/^[1-3]\.[0-9a-z\.\-]+\.(com|cn|net|org|cc|me)$/' => null, + '/^[1-2]\.[0-9a-z\.\-]+\.(com|cn|net|cc|me)$/' => null, // '/^a1\.[0-9a-z\.]+\.(com|cn|org|net|me)$/' => null, '/^ad([0-9]|m|s)?\./' => null, '/^([a-z0-9\-\.]+\.)?affiliat(es|ion|e)\./' => null, @@ -92,7 +92,9 @@ $ARR_WHITE_RULE_LIST = array( '@@||tongji.*kuwo.cn^' => 0, '@@||ntp.org^' => 1, //针对上面正则表达式的一个赦免规则,例如:2.android.pool.ntp.org '@@||*push-apple.com.akadns.net^' => 1, //强制加白, 苹果推送2.courier-push-apple.com.akadns.net - '@@||tracking.epicgames.com' => 0, + '@@||tracking.epicgames.com^' => 0, + '@@||tracker.eu.org^' => 1, //BT tracker + '@@||1.itzmx.com^' => 0, //PT tracker ); //针对上游赦免规则anti-AD不予赦免的规则,即赦免名单的黑名单 From f9468d3adfc0668c21bf6fcd6b9a96641b6641aa Mon Sep 17 00:00:00 2001 From: gently <1243610+gentlyxu@users.noreply.github.com> Date: Thu, 13 Feb 2020 10:58:34 +0800 Subject: [PATCH 2/3] update summary info --- adblock-for-dnsmasq.conf | 5 +++-- anti-ad-domains.txt | 5 +++-- anti-ad-easylist.txt | 5 +++-- anti-ad-surge.txt | 5 +++-- lib/writerFormat.class.php | 8 ++++---- tools/easylist-extend.php | 23 ++++++++++++++++++----- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/adblock-for-dnsmasq.conf b/adblock-for-dnsmasq.conf index 11e9a507..9f9bb800 100644 --- a/adblock-for-dnsmasq.conf +++ b/adblock-for-dnsmasq.conf @@ -1,6 +1,7 @@ -#VER=20200211100531 +#TITLE=anti-AD +#VER=20200213025631 #URL=https://github.com/privacy-protection-tools/anti-AD -#TOTAL_COUNT=31352 +#TOTAL_LINES=31352 address=/0024aaaa.com/ address=/0026645142c89aeb1.com/ address=/003store.com/ diff --git a/anti-ad-domains.txt b/anti-ad-domains.txt index 67d850ad..15780ae7 100644 --- a/anti-ad-domains.txt +++ b/anti-ad-domains.txt @@ -1,6 +1,7 @@ -#VER=20200211100532 +#TITLE=anti-AD +#VER=20200213025631 #URL=https://github.com/privacy-protection-tools/anti-AD -#TOTAL_COUNT=35807 +#TOTAL_LINES=35807 0024aaaa.com 0026645142c89aeb1.com 003store.com diff --git a/anti-ad-easylist.txt b/anti-ad-easylist.txt index 0a35b0ba..808b27fa 100644 --- a/anti-ad-easylist.txt +++ b/anti-ad-easylist.txt @@ -1,6 +1,7 @@ -!AdBlock-style blocklists -!VER=20200213014222 +!TITLE=anti-AD +!VER=20200213025631 !URL=https://github.com/privacy-protection-tools/anti-AD +!TOTAL_LINES=30092 ||201*.myhard.com^ ||8*.tianya.cn^ ||a*.chajiaotong.com^ diff --git a/anti-ad-surge.txt b/anti-ad-surge.txt index aa49ce2f..b19bd56c 100644 --- a/anti-ad-surge.txt +++ b/anti-ad-surge.txt @@ -1,6 +1,7 @@ -#VER=20200211100532 +#TITLE=anti-AD +#VER=20200213025631 #URL=https://github.com/privacy-protection-tools/anti-AD -#TOTAL_COUNT=31352 +#TOTAL_LINES=31352 DOMAIN-SUFFIX,0024aaaa.com DOMAIN-SUFFIX,0026645142c89aeb1.com DOMAIN-SUFFIX,003store.com diff --git a/lib/writerFormat.class.php b/lib/writerFormat.class.php index d29ce4df..11238723 100644 --- a/lib/writerFormat.class.php +++ b/lib/writerFormat.class.php @@ -11,7 +11,7 @@ class writerFormat{ /*dnsmasq支持格式的屏蔽广告列表*/ const DNSMASQ = array( 'format' => 'address=/{DOMAIN}/', - 'header' => "#VER={DATE}\n#URL={URL}\n#TOTAL_COUNT={COUNT}\n", + 'header' => "#TITLE=anti-AD\n#VER={DATE}\n#URL={URL}\n#TOTAL_LINES={COUNT}\n", 'full_domain' => 0, 'name' => 'dnsmasq', 'filename' => 'adblock-for-dnsmasq.conf', @@ -39,7 +39,7 @@ class writerFormat{ /*easylist 兼容格式的屏蔽广告列表*/ const EASYLIST = array( 'format' => '||{DOMAIN}^', - 'header' => "!AdBlock-style blocklists\n!VER={DATE}\n!URL={URL}\n", + 'header' => "!TITLE=anti-AD\n!VER={DATE}\n!URL={URL}\n!TOTAL_LINES=00000\n", 'full_domain' => 0, 'name' => 'easylist', 'filename' => 'anti-ad-easylist.txt', @@ -67,7 +67,7 @@ class writerFormat{ /*Surge 兼容格式的屏蔽广告列表*/ const SURGE = array( 'format' => 'DOMAIN-SUFFIX,{DOMAIN}', - 'header' => "#VER={DATE}\n#URL={URL}\n#TOTAL_COUNT={COUNT}\n", + 'header' => "#TITLE=anti-AD\n#VER={DATE}\n#URL={URL}\n#TOTAL_LINES={COUNT}\n", 'full_domain' => 0, 'name' => 'surge', 'filename' => 'anti-ad-surge.txt', @@ -95,7 +95,7 @@ class writerFormat{ /*Domains 格式的屏蔽广告列表,用于支持pi-hole等*/ const DOMAINS = array( 'format' => '{DOMAIN}', - 'header' => "#VER={DATE}\n#URL={URL}\n#TOTAL_COUNT={COUNT}\n", + 'header' => "#TITLE=anti-AD\n#VER={DATE}\n#URL={URL}\n#TOTAL_LINES={COUNT}\n", 'full_domain' => 1, //保留子域名,即使其上级域名 'name' => 'domains', 'filename' => 'anti-ad-domains.txt', diff --git a/tools/easylist-extend.php b/tools/easylist-extend.php index bb42c62a..637e7b7e 100644 --- a/tools/easylist-extend.php +++ b/tools/easylist-extend.php @@ -164,15 +164,19 @@ while(!feof($wild_fp)){ fclose($wild_fp); $arr_wild_src = array_merge($arr_wild_src, $ARR_MERGED_WILD_LIST); - +$insert_pos = $written_size = $line_count = 0; while(!feof($src_fp)){ $row = fgets($src_fp, 512); if(empty($row)){ continue; } + if(($row{0} === '!') && (substr($row, 0, 13) === '!TOTAL_LINES=')){ + $insert_pos = $written_size; + } + if(!preg_match('/^\|.+?/', $row)){ - fwrite($new_fp, $row); + $written_size += fwrite($new_fp, $row); continue; } @@ -181,7 +185,8 @@ while(!feof($src_fp)){ if(preg_match($regex_str, substr(trim($row), 2, -1))){ $matched = true; if(!array_key_exists($regex_str, $wrote_wild)){ - fwrite($new_fp, "${regex_str}\n"); + $written_size += fwrite($new_fp, "${regex_str}\n"); + $line_count++; $wrote_wild[$regex_str] = 1; } } @@ -194,7 +199,8 @@ while(!feof($src_fp)){ foreach($arr_wild_src as $core_str => $wild_row){ $match_rule = str_replace('*', '.*', $core_str); if(!array_key_exists($core_str, $wrote_wild)){ - fwrite($new_fp, "||${core_str}^\n"); + $written_size += fwrite($new_fp, "||${core_str}^\n"); + $line_count++; $wrote_wild[$core_str] = 1; } if(preg_match("/\|${match_rule}/", $row)){ @@ -206,7 +212,8 @@ while(!feof($src_fp)){ if($matched){ continue; } - fwrite($new_fp, $row); + $written_size += fwrite($new_fp, $row); + $line_count++; } //按需写入白名单规则 @@ -229,6 +236,7 @@ foreach($ARR_WHITE_RULE_LIST as $row => $v){ if($v === 1){ $wrote_whitelist[$matches[1]] = null; fwrite($new_fp, "@@||${matches[1]}^\n"); + $line_count++; continue; } @@ -251,10 +259,15 @@ foreach($ARR_WHITE_RULE_LIST as $row => $v){ } $wrote_whitelist[$matches[1]] = null; fwrite($new_fp, "@@||${matches[1]}^\n"); + $line_count++; } } } +if(($insert_pos > 0) && (fseek($new_fp, $insert_pos) === 0)){ + fwrite($new_fp, "!TOTAL_LINES={$line_count}\n"); +} + fclose($src_fp); fclose($new_fp); rename($src_file . '.txt', $src_file); From 4965909e49d9b2ba59c9bd4646da2e77b635588e Mon Sep 17 00:00:00 2001 From: gently <1243610+gentlyxu@users.noreply.github.com> Date: Thu, 13 Feb 2020 17:17:19 +0800 Subject: [PATCH 3/3] update white rules, fixed #38 --- anti-ad-easylist.txt | 5 +++-- tools/easylist-extend.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/anti-ad-easylist.txt b/anti-ad-easylist.txt index 808b27fa..824f6cf2 100644 --- a/anti-ad-easylist.txt +++ b/anti-ad-easylist.txt @@ -1,7 +1,7 @@ !TITLE=anti-AD -!VER=20200213025631 +!VER=20200213091608 !URL=https://github.com/privacy-protection-tools/anti-AD -!TOTAL_LINES=30092 +!TOTAL_LINES=30093 ||201*.myhard.com^ ||8*.tianya.cn^ ||a*.chajiaotong.com^ @@ -30094,3 +30094,4 @@ @@||tracking.epicgames.com^ @@||tracker.eu.org^ @@||1.itzmx.com^ +@@||stats.uptimerobot.com^ diff --git a/tools/easylist-extend.php b/tools/easylist-extend.php index 637e7b7e..5927da42 100644 --- a/tools/easylist-extend.php +++ b/tools/easylist-extend.php @@ -90,11 +90,12 @@ $ARR_REGEX_LIST = array( //对通配符匹配或正则匹配增加的额外赦免规则 $ARR_WHITE_RULE_LIST = array( '@@||tongji.*kuwo.cn^' => 0, - '@@||ntp.org^' => 1, //针对上面正则表达式的一个赦免规则,例如:2.android.pool.ntp.org + '@@||ntp.org^' => 1, //强制加白,针对上面正则表达式的一个赦免规则,例如:2.android.pool.ntp.org '@@||*push-apple.com.akadns.net^' => 1, //强制加白, 苹果推送2.courier-push-apple.com.akadns.net '@@||tracking.epicgames.com^' => 0, - '@@||tracker.eu.org^' => 1, //BT tracker + '@@||tracker.eu.org^' => 1, //强制加白,BT tracker,有形如2.tracker.eu.org的域 '@@||1.itzmx.com^' => 0, //PT tracker + '@@||stats.uptimerobot.com^' => 0, //uptimerobot监测相关 ); //针对上游赦免规则anti-AD不予赦免的规则,即赦免名单的黑名单