Platinum Partner

Filterset Updater For Ghostsaw's Adlbock For Opera

There is no adblock feature implemented in Opera as fully functional as Adblock Plus for Firefox, but a guy called Ghostsaw created a javascript plug-in that does almost the same job, less efficiently though if performance matters. I wrote an updater script which takes aaaa-customlist.js and updates it. It was written in Perl, but if you're using Opera on Windows instead of an UNIX-based operating system it can easily be compiled using ActivePerl and Perl2Exe. You can easily add this to cron (or scheduler in Windows) and your adlbock list will always be up-to-date.
Don't forget to create two comments one below the other:

// FSGUPDATE BEGIN
                           <-- leave empty between
// FSGUPDATE START


#!/usr/bin/perl

use strict;
use warnings;

use LWP;
use Getopt::Std;
use vars qw( $ua $res %o );

$ua = new LWP::UserAgent(
	agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11',
);

$| = 1;
getopts("o:", \%o);

if(defined $o{p}) {
    print "HTTP Proxy: $o{p}\n";
    $o{p} = "http://" . $o{p} unless($o{p} =~ /^http:\/\//);
    $ua->proxy('http', $o{p});
}

my $adblock = shift;
my $filterset = shift;
my $copy = 1;
my (@black, @white);

unless(defined $filterset) {
    print("usage: $0 [-p http-proxy]  \n");
    exit(0);
}

my $tmp;

print "fetching $adblock... ";
$res = $ua->get($adblock);
print $res->status_line . "\n";
exit(1) unless($res->is_success);

foreach(split(/[\r\n]+/, $res->content)) {
    if(/\[\s*(.*?adblock.*?)\s*\]/i) {
	print "found ABP header: $1\n";
    } elsif(/checksum: (.+)/i) {
	print "found checksum $1 (skipping check)\n";
    } else {
	if(/^\@\@\|?\/?(.+)\/?$/) {
	    $tmp = $1;
	    $tmp =~ s/\*/\.\*/g;
	    $tmp =~ s/\//\\\//g;
	    push(@white,"(/$tmp/)");
	} elsif(/^\|?\/?(.+)\/?$/) {
	    $tmp = $1;
	    $tmp =~ s/\*/\.\*/g;
	    $tmp =~ s/\//\\\//g;
	    push(@black,"(/$tmp/)");
	}
    }
}

print "updating filterset... ";
unless(open(FILTERSET, "<$filterset")) {
    print "failed: $!\n";
    exit(1);
}
my @filterset = ;
close(FILTERSET);

unless(open(FILTERSET, ">$filterset")) {
    print "failed: $!\n";
    exit(1);
}

for(@filterset) {
    if(/^\/\/ FSGUPDATE BEGIN/) {
	print FILTERSET;
	print FILTERSET "ujs_white_array.push(\"" . join("|", @white) . "\");\n";
	print FILTERSET "ujs_black_array.push(\"" . join("|", @black) . "\");\n";
	$copy = 0;
    } elsif(/^\/\/ FSGUPDATE END/) {
	print FILTERSET;
	$copy = 1;
    } elsif($copy) {
	print FILTERSET;
    }
} 
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}