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);