Skip to content

Instantly share code, notes, and snippets.

@0x46616c6b
Created September 1, 2012 20:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x46616c6b/3585720 to your computer and use it in GitHub Desktop.
Save 0x46616c6b/3585720 to your computer and use it in GitHub Desktop.
Privoxy Filter from Adblock Plus
URL="http://adblockplus.mozdev.org/easylist/easylist.txt"
ACTION=/root/user.action
FILTER=/root/user.filter
FILE=$(basename ${URL})
LIST=${FILE%\.*}
wget -qO ${FILE} ${URL}
echo -e "{ +block{${LIST}} }" > ${ACTION}
sed '/^!.*/d;1,1 d;/^@@.*/d;/\$.*/d;/#/d;s/\./\\./g;s/\?/\\?/g;s/\*/.*/g;s/(/\\(/g;s/)/\\)/g;s/\[/\\[/g;s/\]/\\]/g;s/\^/[\/\&:\?=_]/g;s/^||/\./g;s/^|/^/g;s/|$/\$/g;/|/d' ${FILE} >> ${ACTION}
echo "FILTER: ${LIST} Tag filter of ${LIST}" > ${FILTER}
sed '/^#/!d;s/^##//g;s/^#\(.*\)\[.*\]\[.*\]*/s|<([a-zA-Z0-9]+)\\s+.*id=.?\1.*>.*<\/\\1>||g/g;s/^#\(.*\)/s|<([a-zA-Z0-9]+)\\s+.*id=.?\1.*>.*<\/\\1>||g/g;s/^\.\(.*\)/s|<([a-zA-Z0-9]+)\\s+.*class=.?\1.*>.*<\/\\1>||g/g;s/^a\[\(.*\)\]/s|<a.*\1.*>.*<\/a>||g/g;s/^\([a-zA-Z0-9]*\)\.\(.*\)\[.*\]\[.*\]*/s|<\1.*class=.?\2.*>.*<\/\1>||g/g;s/^\([a-zA-Z0-9]*\)#\(.*\):.*[:[^:]]*[^:]*/s|<\1.*id=.?\2.*>.*<\/\1>||g/g;s/^\([a-zA-Z0-9]*\)#\(.*\)/s|<\1.*id=.?\2.*>.*<\/\1>||g/g;s/^\[\([a-zA-Z]*\).=\(.*\)\]/s|\1^=\2>||g/g;s/\^/[\/\&:\?=_]/g;s/\.\([a-zA-Z0-9]\)/\\.\1/g' ${FILE} >> ${FILTER}
echo "{ +filter{${LIST}} }" >> ${ACTION}
echo "*" >> ${ACTION}
echo "{ -block }" >> ${ACTION}
sed '/^@@.*/!d;s/^@@//g;/\$.*/d;/#/d;s/\./\\./g;s/\?/\\?/g;s/\*/.*/g;s/(/\\(/g;s/)/\\)/g;s/\[/\\[/g;s/\]/\\]/g;s/\^/[\/\&:\?=_]/g;s/^||/\./g;s/^|/^/g;s/|$/\$/g;/|/d' ${FILE} >> ${ACTION}
echo "{ -block +handle-as-image }" >> ${ACTION}
sed '/^@@.*/!d;s/^@@//g;/\$.*image.*/!d;s/\$.*image.*//g;/#/d;s/\./\\./g;s/\?/\\?/g;s/\*/.*/g;s/(/\\(/g;s/)/\\)/g;s/\[/\\[/g;s/\]/\\]/g;s/\^/[\/\&:\?=_]/g;s/^||/\./g;s/^|/^/g;s/|$/\$/g;/|/d' ${FILE} >> ${ACTION}
@wmyrda
Copy link

wmyrda commented Apr 20, 2018

Very fine job! Unfortunately with newer versions of sed it gives out an error
"sed: character class syntax is [[:space:]], not [:space:]"

I able to trace it back to the .[:[^:]][^:] section in the filter, but I was unable to fix it. Commenting this line out creates properly the Action file, but obviously Filter file does not get created. Please take a look at it if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment