PowerShell Script to generate IE8 Fanboy Adblock XML (for import to InPrivate)

Author Message
rekrapg

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 10/26/2011
  • Status: offline
PowerShell Script to generate IE8 Fanboy Adblock XML (for import to InPrivate) Thursday, January 12, 2012 11:52 AM (permalink)
0
Hi All,
Took me a while, but I finally got there - script to download Fanboy's IE9 TPL Adblock files, clean them up, generate XML ready for import :)  Anyone able to convert to VBS might be handy too.  Reason for script is i'm stuck on XP at work, IE only, which leaves me here

# Remove previous filter XML
Remove-Item "*.xml"
# Set the file names for the downloaded and converted files
$File1 = "fanboy-adblock_{0:dd.MM.yyyy}.txt" -f (Get-Date)
$File2 = "fanboy-tracking_{0:dd.MM.yyyy}.txt" -f (Get-Date)
$File3 = "ie8-fanboy-adblock-{0:dd.MM.yyyy}.xml" -f (Get-Date)
# Download adblock and tracking files
$WebClient = New-Object System.Net.WebClient
# If auth required for network uncomment below line
#$WebClient.Credentials = New-Object System.Net.Networkcredential("Username", "Password")
$WebClient.DownloadFile( "http://www.fanboy.co.nz/adblock/ie/fanboy-noele.tpl", "C:\Utils\Adblock\$File1" )
$WebClient.DownloadFile( "http://www.fanboy.co.nz/adblock/ie/fanboy-tracking.tpl", "C:\Utils\Adblock\$File2" )
# Filter text file cleanup - remove first lines not relating to filters
(gc $File1) | ? {(1..12) -notcontains $_.ReadCount} | sc $File1
(gc $File2) | ? {(1..8) -notcontains $_.ReadCount} | sc $File2
# Filter text file cleanup - remove hash lines (non-filters)
(Get-Content $File1) -notmatch "#" | Out-File $File1
(Get-Content $File2) -notmatch "#" | Out-File $File2
# Create XML file and add initial lines to XML
New-Item $File3 -type file
Add-Content $File3 "<?xml version=`"1.0`" encoding=`"UTF-8`"?>`n<rss version=`"2.0`" xmlns:wf=`"http://www.microsoft.com/schemas/webfilter/2008`">`n<channel>`n<title>Fanboy AdBlock IE8 XML</title>`n<link>http://www.fanboy.co.nz/a...noele.tpl</link>`n<description>Converted to IE8 filters by REKRAPG</description>"
# Convert filters from TPL to XML add to XML file
Get-Content $File1 | foreach { $_ = $_.trim(); $_ } | foreach {
$_ = @"
<item><wf:blockRegex><![CDATA[$_]]></wf:blockRegex></item>
"@; $_ } | foreach { Add-Content $File3 $_ }
Get-Content $File2 | foreach { $_ = $_.trim(); $_ } | foreach {
$_ = @"
<item><wf:blockRegex><![CDATA[$_]]></wf:blockRegex></item>
"@; $_ } | foreach { Add-Content $File3 $_ }
# Add final lines for XML
Add-Content $File3 "`n</channel>`n</rss>"
# Clear out temp files
Remove-Item $File1
Remove-Item $File2
 
#1
    rekrapg

    • Total Posts : 4
    • Scores: 0
    • Reward points : 0
    • Joined: 10/26/2011
    • Status: offline
    Re:PowerShell Script to generate IE8 Fanboy Adblock XML (for import to InPrivate) Sunday, February 05, 2012 9:58 AM (permalink)
    0
    Take 2 - realised I wasn't trimming all the fat
    
     
    # Remove previous filter XML
    Remove-Item "*.xml"
    # Set the file names for the downloaded and converted files
    $File1 = "fanboy-adblock_{0:dd.MM.yyyy}.txt" -f (Get-Date)
    $File2 = "fanboy-tracking_{0:dd.MM.yyyy}.txt" -f (Get-Date)
    $File3 = "ie8-fanboy-adblock-{0:dd.MM.yyyy}.xml" -f (Get-Date)
    # Download adblock and tracking files
    $WebClient = New-Object System.Net.WebClient
    # If auth required for network uncomment below line
    #$WebClient.Credentials = New-Object System.Net.Networkcredential("Username", "Password")
    $WebClient.DownloadFile( "http://www.fanboy.co.nz/adblock/ie/fanboy-noele.tpl", "C:\Utils\Adblock\$File1" )
    $WebClient.DownloadFile( "http://www.fanboy.co.nz/adblock/ie/fanboy-tracking.tpl", "C:\Utils\Adblock\$File2" )
    # Filter text file cleanup - remove first lines not relating to filters
    (gc $File1) | ? {(1..12) -notcontains $_.ReadCount} | sc $File1
    (gc $File2) | ? {(1..8) -notcontains $_.ReadCount} | sc $File2
    # Filter text file cleanup - remove hash lines (non-filters)
    (Get-Content $File1) -notmatch "#" | Out-File $File1
    (Get-Content $File2) -notmatch "#" | Out-File $File2
    # Create XML file and add initial lines to XML
    New-Item $File3 -type file
    Add-Content $File3 "<?xml version=`"1.0`" encoding=`"UTF-8`"?>`n<rss version=`"2.0`" xmlns:wf=`"http://www.microsoft.com/schemas/webfilter/2008`">`n<channel>`n<title>Fanboy AdBlock IE8 XML</title>`n<link>http://www.fanboy.co.nz/adblock/ie/fanboy-noele.tpl</link>`n<description>Converted to IE8 filters by REKRAPG</description>"
    # Convert filters from TPL to XML add to XML file *new* trimmed off excess fat
    Get-Content $File1 | foreach { $_ = $_.trim("- "); $_ } | foreach { $_ = $_.trim("-d "); $_ } | foreach { $_ = $_.trim("+d "); $_ } | foreach { 
    $_ = @"
    <item><wf:blockRegex><![CDATA[$_]]></wf:blockRegex></item>
    "@; $_ } | foreach { Add-Content $File3 $_ }
    Get-Content $File2 | foreach { $_ = $_.trim("- "); $_ } | foreach { $_ = $_.trim("-d "); $_ } | foreach { $_ = $_.trim("+d "); $_ } | foreach { 
    $_ = @"
    <item><wf:blockRegex><![CDATA[$_]]></wf:blockRegex></item>
    "@; $_ } | foreach { Add-Content $File3 $_ }
    # Add final lines for XML
    Add-Content $File3 "`n</channel>`n</rss>"
    # Clear out temp files
    Remove-Item $File1
    Remove-Item $File2 

     
    #2
      Estless37

      • Total Posts : 1
      • Scores: 0
      • Reward points : 0
      • Joined: 3/3/2012
      • Status: offline
      Re:PowerShell Script to generate IE8 Fanboy Adblock XML (for import to InPrivate) Saturday, March 03, 2012 5:36 AM (permalink)
      0
      Hi
      Thanks mate! 
      Interesting post, impressive.
      Good to see scripts for taking care of this issues in IE8 :) Still XP supported in two more years.

      Understand (even my skills in scripting is from a beginners view), this can run automatically and triggered to start from different kind of tools or windows task scheduler.
      Is it prepared and tested for that?

      How does it handle these sources, does it adding the content after another or merging it together without duplicate entries? 

      What is this?
      http://www.microsoft.com/schemas/webfilter/2008`
       
      <message edited by Estless37 on Saturday, March 03, 2012 10:55 AM>
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9