Skip to content

Commit

Permalink
adblock2privoxy: Update to version 2.2.0
Browse files Browse the repository at this point in the history
* Remove unused debug code
  • Loading branch information
essandess committed Jan 31, 2024
1 parent c0e9100 commit 551def2
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 25 deletions.
4 changes: 2 additions & 2 deletions adblock2privoxy-utils/adblock2privoxy-utils.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: adblock2privoxy-utils
version: 2.1.1
version: 2.2.0
cabal-version: >= 1.10
build-type: Simple
tested-with: GHC==8.10.7
Expand Down Expand Up @@ -45,4 +45,4 @@ source-repository this
type: git
location: https://github.com/essandess/adblock2privoxy.git
subdir: adblock2privoxy-utils
tag: v2.1.1
tag: v2.2.0
4 changes: 2 additions & 2 deletions adblock2privoxy/adblock2privoxy.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: adblock2privoxy
version: 2.1.1
version: 2.2.0
cabal-version: >= 1.10
build-type: Simple
tested-with:
Expand Down Expand Up @@ -103,4 +103,4 @@ source-repository this
type: git
location: https://github.com/essandess/adblock2privoxy.git
subdir: adblock2privoxy
tag: v2.1.1
tag: v2.2.0
3 changes: 3 additions & 0 deletions adblock2privoxy/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.2.0
* Remove unused debug code

2.1.1
* Fix compilation issues for ghc 9.6.3

Expand Down
14 changes: 8 additions & 6 deletions adblock2privoxy/src/ElementBlocker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ elemBlock path info = writeElemBlock . elemBlockData
writeElemBlock :: ElemBlockData -> IO ()
writeElemBlock (ElemBlockData flatPatterns rulesTree) =
do
let debugPath = path </> "debug"
filteredInfo = filter ((||) <$> not . startswith "Url:" <*> startswith "Url: http") info
let filteredInfo = filter ((||) <$> not . startswith "Url:" <*> startswith "Url: http") info
-- debugPath = path </> "debug"
createDirectoryIfMissing True path
cont <- getDirectoryContents path
_ <- sequence $ removeOld <$> cont
createDirectoryIfMissing True debugPath
-- createDirectoryIfMissing True debugPath
-- writeBlockTree path debugPath rulesTree
writeBlockTree path rulesTree
writePatterns_with_debug filteredInfo (path </> "ab2p.common.css") (debugPath </> "ab2p.common.css") flatPatterns
writePatterns_with_debug filteredInfo (path </> "ab2p.common.css") "" flatPatterns
-- writePatterns_with_debug filteredInfo (path </> "ab2p.common.css") (debugPath </> "ab2p.common.css") flatPatterns
removeOld entry' =
let entry = path </> entry'
in do
Expand Down Expand Up @@ -64,9 +65,10 @@ elemBlock path info = writeElemBlock . elemBlockData
writePatterns_with_debug _ _ _ [] = return ()
writePatterns_with_debug info' normalFilename debugFilename patterns =
do
writeCssFile debugFilename $ intercalate "\n" $ (++ Templates.blockCss) <$> patterns
writeCssFile normalFilename $ intercalate "\n" ((++ Templates.blockCss) . intercalate "," <$>
splitEvery 4000 patterns)
splitEvery 4000 patterns)
when (debugFilename /= "") $
writeCssFile debugFilename $ intercalate "\n" $ (++ Templates.blockCss) <$> patterns
where
splitEvery n = takeWhile (not . null) . unfoldr (Just . splitAt n)
writeCssFile filename content =
Expand Down
2 changes: 1 addition & 1 deletion adblock2privoxy/src/Paths_adblock2privoxy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
catchIO = Exception.catch

version :: Version
version = Version [2,1,0] []
version = Version [2,2,0] []
bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath

bindir = "/opt/local/bin"
Expand Down
8 changes: 5 additions & 3 deletions adblock2privoxy/src/Templates.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ writeTemplateFiles outDir cssDomain useHTTP = do
lns = lines content
replace' line (from, to) = replace from to line
filterLine line
| null cssDomain && (startswith "[?CSS_DOMAIN]" line || startswith "[?CSS_DOMAIN_DEBUG]" line) = ""
| otherwise = foldl replace' line [("[?CSS_DOMAIN]", ""), ("[?CSS_DOMAIN_DEBUG]", "# "), ("[CSS_DOMAIN]", cssDomain), ("[CSS_PROTOCOL]", cssProtocol useHTTP)]
| null cssDomain && (startswith "[?CSS_DOMAIN]" line) = ""
| otherwise = foldl replace' line [("[?CSS_DOMAIN]", ""), ("[CSS_DOMAIN]", cssDomain), ("[CSS_PROTOCOL]", cssProtocol useHTTP)]
-- | null cssDomain && (startswith "[?CSS_DOMAIN]" line || startswith "[?CSS_DOMAIN_DEBUG]" line) = ""
-- | otherwise = foldl replace' line [("[?CSS_DOMAIN]", ""), ("[?CSS_DOMAIN_DEBUG]", "# "), ("[CSS_DOMAIN]", cssDomain), ("[CSS_PROTOCOL]", cssProtocol useHTTP)]

copySystem file = do
dataDir <- getDataDir
content <- readFile $ dataDir </> "templates" </> file
content <- readFile $ dataDir </> "templates" </> file
writeFile (outDir </> file) $ filterDomain content
5 changes: 0 additions & 5 deletions adblock2privoxy/templates/ab2p.system.action
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

{+set-image-blocker{blank} \
[?CSS_DOMAIN] +filter{ab2p-elemhide-filter} \
+client-header-tagger{ab2p-elemhide-check-debug} \
+client-header-tagger{ab2p-handle-as-image-c} \
+server-header-tagger{ab2p-handle-as-image-s}}
/

[?CSS_DOMAIN]{-filter{ab2p-elemhide-filter} \
[?CSS_DOMAIN] +filter{ab2p-elemhide-filter-debug}}
[?CSS_DOMAIN]TAG:^ab2p-elemhide-filter-debug$

{+handle-as-image}
TAG:^ab2p-handle-as-image$

Expand Down
33 changes: 33 additions & 0 deletions adblock2privoxy/templates/ab2p.system.action.debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#AbBlock system actions -- don't edit --

{+set-image-blocker{blank} \
[?CSS_DOMAIN] +filter{ab2p-elemhide-filter} \
+client-header-tagger{ab2p-elemhide-check-debug} \
+client-header-tagger{ab2p-handle-as-image-c} \
+server-header-tagger{ab2p-handle-as-image-s}}
/

[?CSS_DOMAIN]{-filter{ab2p-elemhide-filter} \
[?CSS_DOMAIN] +filter{ab2p-elemhide-filter-debug}}
[?CSS_DOMAIN]TAG:^ab2p-elemhide-filter-debug$

{+handle-as-image}
TAG:^ab2p-handle-as-image$

{+block{ adblock rules }}
TAG:^ab2p-block-s$

{-block}
TAG:^ab2p-unblock-u$

{-block}
TAG:^ab2p-unblock-d$

{-block}
TAG:^ab2p-unblock-s$

# Omit per GitHub issue #7
# workaround for gzip handling privoxy bugs
#{ +prevent-compression }
#.yahoo.com
#.amazon.com
6 changes: 0 additions & 6 deletions adblock2privoxy/templates/ab2p.system.filter
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ s@^accept(?=:[\s\w]*image\/):.*@ab2p-handle-as-image@Ti
SERVER-HEADER-FILTER: ab2p-xframe-filter
s@.*\sHTTP\/1.*@$&\r\nX-Frame-Options: DENY@i

[?CSS_DOMAIN_DEBUG]CLIENT-HEADER-TAGGER: ab2p-elemhide-check-debug
[?CSS_DOMAIN_DEBUG]s@^cookie:.*ab2p-elemhide-filter-debug=true(?:;|$).*@ab2p-elemhide-filter-debug@Ti

[?CSS_DOMAIN]FILTER: ab2p-elemhide-filter
[?CSS_DOMAIN]s@[^'"\s]\s*<head[^>]*>(?=\s*[^'"\s])@$&<link rel="stylesheet" type="text/css" href="[CSS_PROTOCOL]://[CSS_DOMAIN]/ab2p.common.css"></link><link rel="stylesheet" type="text/css" href="[CSS_PROTOCOL]://[CSS_DOMAIN]/$host/ab2p.css"></link>@iUD

[?CSS_DOMAIN_DEBUG]FILTER: ab2p-elemhide-filter-debug
[?CSS_DOMAIN_DEBUG]s@[^'"\s]\s*<head[^>]*>(?=\s*[^'"\s])@$&<link rel="stylesheet" type="text/css" href="[CSS_PROTOCOL]://[CSS_DOMAIN]/debug/ab2p.common.css"></link><link rel="stylesheet" type="text/css" href="[CSS_PROTOCOL]://[CSS_DOMAIN]/$host.debug/ab2p.css"></link>@iUD

FILTER: ab2p-popup-filter
s@[^'"\s]\s*<head[^>]*>(?=\s*[^'"\s])@$&<script type="text/javascript">parent==window&&opener&&close()</script>@iUD
37 changes: 37 additions & 0 deletions adblock2privoxy/templates/ab2p.system.filter.debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#AbBlock system filters -- don't edit --


SERVER-HEADER-TAGGER: ab2p-block-s
s@.*@ab2p-block-s@Ti


CLIENT-HEADER-TAGGER: ab2b-unblock-u
s@user-agent.*@ab2p-unblock-u@Ti

SERVER-HEADER-TAGGER: ab2p-unblock-d
s@date.*@ab2p-unblock-d@Ti

SERVER-HEADER-TAGGER: ab2p-unblock-s
s@server.*@ab2p-unblock-s@Ti


SERVER-HEADER-TAGGER: ab2p-handle-as-image-s
s@^content-type(?=:[\s\w]*image\/):.*@ab2p-handle-as-image@Ti

CLIENT-HEADER-TAGGER: ab2p-handle-as-image-c
s@^accept(?=:[\s\w]*image\/):.*@ab2p-handle-as-image@Ti

SERVER-HEADER-FILTER: ab2p-xframe-filter
s@.*\sHTTP\/1.*@$&\r\nX-Frame-Options: DENY@i

[?CSS_DOMAIN_DEBUG]CLIENT-HEADER-TAGGER: ab2p-elemhide-check-debug
[?CSS_DOMAIN_DEBUG]s@^cookie:.*ab2p-elemhide-filter-debug=true(?:;|$).*@ab2p-elemhide-filter-debug@Ti

[?CSS_DOMAIN]FILTER: ab2p-elemhide-filter
[?CSS_DOMAIN]s@[^'"\s]\s*<head[^>]*>(?=\s*[^'"\s])@$&<link rel="stylesheet" type="text/css" href="[CSS_PROTOCOL]://[CSS_DOMAIN]/ab2p.common.css"></link><link rel="stylesheet" type="text/css" href="[CSS_PROTOCOL]://[CSS_DOMAIN]/$host/ab2p.css"></link>@iUD

[?CSS_DOMAIN_DEBUG]FILTER: ab2p-elemhide-filter-debug
[?CSS_DOMAIN_DEBUG]s@[^'"\s]\s*<head[^>]*>(?=\s*[^'"\s])@$&<link rel="stylesheet" type="text/css" href="[CSS_PROTOCOL]://[CSS_DOMAIN]/debug/ab2p.common.css"></link><link rel="stylesheet" type="text/css" href="[CSS_PROTOCOL]://[CSS_DOMAIN]/$host.debug/ab2p.css"></link>@iUD

FILTER: ab2p-popup-filter
s@[^'"\s]\s*<head[^>]*>(?=\s*[^'"\s])@$&<script type="text/javascript">parent==window&&opener&&close()</script>@iUD

0 comments on commit 551def2

Please sign in to comment.