Make Privoxy Filters

はじめに

ある程度の広告は容認できるけど,見えない広告を画面上方からスライドしてタップさせる広告にはイラッとする.

Privoxy用フィルタを適当に生成することにした.

結論を言ってしまうと,やりたいことは概ねこれ.
webnetforce.net

プロキシ構築やadblock2privoxyコマンドの説明諸々は割愛する.

スクリプト

Adblock用フィルタリスト

adblock用のフィルタは色々な人たちが作ってくれている.
日本用フィルタのまとめ - なんJ AdGuard部 Wiki*

これら適当なリストをまとめたファイル(source.list)を作成する.

#################################
## https://280blocker.net/
#################################
https://280blocker.net/files/280blocker_adblock.txt

#################################
## http://tofukko.r.ribbon.to/abp.html
#################################
http://tofukko.r.ribbon.to/Adblock_Plus_list.txt

#################################
## http://qme.mydns.jp/adblock.html
#################################
http://qme.mydns.jp/data/AdblockV2.txt

#################################
## http://pokapoka.html.xdomain.jp/
#################################
https://raw.githubusercontent.com/eEIi0A5L/adblock_filter/master/mochi_filter.txt
https://raw.githubusercontent.com/eEIi0A5L/adblock_filter/master/mochi_filter_extended.txt
https://raw.githubusercontent.com/eEIi0A5L/adblock_filter/master/negi_filter.txt
https://raw.githubusercontent.com/eEIi0A5L/adblock_filter/master/kame_filter.txt
https://raw.githubusercontent.com/eEIi0A5L/adblock_filter/master/kotori_filter.txt
https://raw.githubusercontent.com/eEIi0A5L/adblock_filter/master/ichigo_filter.txt
https://raw.githubusercontent.com/eEIi0A5L/adblock_filter/master/kujira_filter.txt
https://raw.githubusercontent.com/eEIi0A5L/adblock_filter/master/tamago_filter.txt

#################################
## OTHERS
#################################
https://secure.fanboy.co.nz/easylist.txt

Privoxy用フィルタ生成スクリプト

adblock用フィルタを収集し,Privoxy用に変換するスクリプトを用意する. これを適当に実行して適宜フィルタを更新すればOK.

#!/bin/bash
#############################
#
#   mkfilter - Rev.0.1.0
#
#############################
#
#   ABOUT
#   make filter for privoxy
#
#############################

## GlobalConfig #############
ScriptName=$(basename ${0})
ScriptPath=$(cd $(dirname ${0}) && pwd)
LogFile=/Path/To/LogFile/${ScriptName}_$(date '+%Y-%m-%d').log

LogInfo () {
    echo "$(date '+%Y-%m-%d %T') [INFO] $@" | tee -a $LogFile
}
LogWarn () {
    echo "$(date '+%Y-%m-%d %T') [WARN] $@" | tee -a $LogFile
}
LogErr () {
    echo "$(date '+%Y-%m-%d %T') [ERR] $@" | tee -a $LogFile
    exit 1
}
LogDebug () {
    echo "$(date '+%Y-%m-%d %T') [DEBUG] $@" | tee -a $LogFile
}

## Init #####################

ConfFile=/Path/To/source.list
if [ ! -e $ConfFile ]; then
    LogErr "missing conf file: $ConfFile"
fi

FilterLists=/Path/To/Directory/For/Adblock/Filter
if [ ! -e $FilterLists ]; then
    mkdir $FilterLists
fi

FilterDir=/Path/To/Directory/For/Privoxy
if [ ! -e $FilterDir ]; then
    mkdir $FilterDir
fi

## Main ####################

LogInfo "Start"

LogInfo "Update Adblock Filters"
for TargetUrl in $(grep -v \# $ConfFile)
do
    LogInfo "TargetUrl: $TargetUrl"
    wget -N -nv $TargetUrl -P $FilterLists 2>> $LogFile
    if [ $? -ne 0 ]; then
        LogWarn "probqrem occurred: $TargetUrl"
    fi
done

LogInfo "Convert To Privoxy Filters"
adblock2privoxy -p $FilterDir $FilterLists/* >> $LogFile 2>&1

LogInfo "Archive Files"
tar cf $DataDir/PrivoxyFilter_$(date '+%Y-%m-%d').tar.gz $ConfFile $FilterLists $FilterDir

LogInfo "End"
exit 0

おわりに

とりあえず過剰な広告は消すことができた.

Privoxyとかadblock2privoxy周りの説明を完全に割愛したけれど,とりあえず私的メモなのであしからず. 気が向いたらいずれ書くかも,書かないかも.