Opera Adblocker

Share your advanced PureBasic knowledge/code with the community.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Opera Adblocker

Post by Foz »

Using antique hardware (circa 2000) has forced me to look at other browsers for a "modern" browsing experience with a minimal amount of ram. I've settled on Opera which can be configured to use a tiny amount of ram in comparison to other ram "hungry" browsers.

Of course the downside to Opera is the lack of an automatic updating adblocking list. The given method is to download the Fanboy's lists from http://www.fanboy.co.nz/adblock/opera/, but it is a manual method.

So I decided to automate the list update on boot up - one little script later and a start up shortcut on windows... fantastic.

Of course, as I'm sharing it here, I've added in the other OS's (Linux & MacOSX) but these are not tried, I'm just following directions. If it's wrong please let me know and all correct this snippet.

Code: Select all

; wait 5 seconds for the system to load

Delay(5000)

If InitNetwork() = 0
  MessageRequester("Error", "Can't initialize the network !", 0)
  End
EndIf

Define DropPoint.s = ""

CompilerSelect #PB_Compiler_OS
  CompilerCase  #PB_OS_Windows
    DropPoint = GetEnvironmentVariable("APPDATA") + "\Opera\Opera\"
  CompilerCase #PB_OS_Linux
    DropPoint = GetHomeDirectory() + ".opera/"
  CompilerCase #PB_OS_MacOS
    DropPoint = GetHomeDirectory() + "Library/Preferences/Opera Preferences/"
CompilerEndSelect

Dim Site.s(1)
Site(0) = "http://www.fanboy.co.nz/adblock/opera/complete/"
Site(1) = "http://fanboy-adblock-list.googlecode.com/hg/opera/"
;Site(1) = "https://fanboy-adblock-list.googlecode.com/hg/opera/"

Define RetryCount = 0

RetryUrlFilter:

If Not ReceiveHTTPFile(Site(RetryCount % 2) + "urlfilter.ini", DropPoint + "urlfilter.ini")
  If RetryCount < 10
    RetryCount + 1
    Delay(1000)
    Goto RetryUrlFilter
  EndIf
  
  If MessageRequester("Opera Adblocker", "Failed to download url filter!", 5) = 4
    RetryCount = 0
    Goto RetryUrlFilter
  EndIf
EndIf

RetryElementHider:

If Not ReceiveHTTPFile(Site(RetryCount % 2) + "fanboy-adblocklist-elements-v4.css", DropPoint + "fanboy-adblocklist-elements-v4.css") And Not ReceiveHTTPFile(Site(RetryCount % 2) + "fanboy-adblocklist-elements-v3.css", DropPoint + "fanboy-adblocklist-elements-v3.css")
  If RetryCount < 10
    RetryCount + 1
    Delay(1000)
    Goto RetryElementHider
  EndIf
  
  If MessageRequester("Opera Adblocker", "Failed to download element hider!", 5) = 4
    RetryCount = 0
    Goto RetryElementHider
  EndIf
EndIf