The Adblock Project Forum Index The Adblock Project
Pull up a seat ...stay a while.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AdBlock for Opera 8.0x, for real this time

 
Post new topic   Reply to topic    The Adblock Project Forum Index -> Main
View previous topic :: View next topic  
Author Message
FosterSJC
Guest





PostPosted: Sun Aug 07, 2005    Post subject: AdBlock for Opera 8.0x, for real this time Reply with quote

I know AdBlock for Opera has been discussed tons of times before. The reason given for it never happening is that Opera doesn't support XUL and user-specified JS, and why should the extension writers have to rewrite their program from scratch using a proprietary SDK. These are good reasons.

However, Opera 8.0x was recently released, with some really interesting new features that would allow for a GUI-less adblock script to be installed.
See http://www.opera.com/support/tutorials/userjs/ . UserJS allows users to specify local JavaScript files for Opera to include on every page that they visit.

My radical idea is this: gut the primary adblock javascript (http://www.mozdev.org/source/browse/adblock/adblock/content/adblock.js), removing everything that has to do with XUL (the extension GUI). Hardcode in a simple filterset (or a complex one, like filterset.g), and instead of having the script ask the GUI for the values of "hide" and "enabled", set them manually.

In the following snippet, the bold code would remain the same, and the italic code would need to be slightly changed, as described above:

Quote:
// Array holding all the patterns to block.
var Patterns;
// Boolean signalling whether to remove or hide images. Images will be hidden if true. They will be removed if false.
var Hide;
// These tags are being processed.
var tags = ["img", "embed", "object", "iframe"]; // iframe is still listed so it can be killed at it's source, if desired

// Loads the preferences.
function loadSettings() {

try {
prefObj = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var Branch = prefObj.getBranch("adblock." ) ;
Enabled = Branch.getBoolPref("enabled" ) ;
Hide = Branch.getBoolPref("hide" ) ;
Patterns = Branch.getCharPref("patterns" ).split(" " ) ;
} catch(exception) {}

// If AdBlock is not enabled... Return false as a signal that the program should not filter.
if (!Enabled) {
return false;
}


for (var i = 0 ; i < Patterns.length ; i++) {
Patterns[i] = new RegExp(convert2RegExp(Patterns[i]), "i" ) ;
}
return true;
}


As far as I can tell, if we make these simple changes to the script in the beginning, for it to work with Opera, only 1 more line might need to be changed!
Quote:
// Resolves the absolute URL of the image-address being sent as an argument.
// page is the document which contains the image.
function getImageURL(imageSrc, page) {
var URL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURL);
URL.spec = page.URL;
return URL.resolve(imageSrc);
}


I am no javascript wizard, so I can't make the changes myself. But everything I've read says that this should be trivial. It would take an experienced coder about 5 minutes. I have included below the entire script, with the GUI-interaction parts removed, and the lines to be changed in bold:
Quote:
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is AdBlock for Mozilla.
*
* The Initial Developer of the Original Code is
* Henrik Aasted Sorensen.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Henrik Aasted Sorensen <henrik@aasted.org>
* Stefan Kinitz <mcmurmel.blah@gmx.de>
* Rue <quill@ethereal.net>
*
* ***** END LICENSE BLOCK ***** */

// Array holding all the patterns to block.
var Patterns;
// Boolean signalling whether to remove or hide images. Images will be hidden if true. They will be removed if false.
var Hide;
// These tags are being processed.
var tags = ["img", "embed", "object", "iframe"]; // iframe is still listed so it can be killed at it's source, if desired

// Loads the preferences.
function loadSettings() {
try {
prefObj = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var Branch = prefObj.getBranch("adblock.");
Enabled = Branch.getBoolPref("enabled");
Hide = Branch.getBoolPref("hide");
Patterns = Branch.getCharPref("patterns").split(" ");
} catch(exception) {}

// If AdBlock is not enabled... Return false as a signal that the program should not filter.
if (!Enabled) {
return false;
}

for (var i = 0 ; i < Patterns.length ; i++) {
Patterns[i] = new RegExp(convert2RegExp(Patterns[i]), "i");
}
return true;
}

// Resolves the absolute URL of the image-address being sent as an argument.
// page is the document which contains the image.
function getImageURL(imageSrc, page) {
var URL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURL);
URL.spec = page.URL;
return URL.resolve(imageSrc);
}

// This method checks if a picture matches a filter.
// It returns true if the imageurl is caught by one of the filters.
// It returns false if the imageurl is not caught by any filter.
function validate(imageurl) {
for (var i = 0 ; i < Patterns.length ; i++) {
if (Patterns[i].test(imageurl))
return true;
}

return false;
}

// Converts a pattern in this programs simple notation to a regular expression.
function convert2RegExp( pattern ) {
// If the user already entered a regular expression.
if ( isRegExp( pattern ) ) {
return pattern.substr(1, pattern.length - 2);
}

s = new String(pattern);
res = new String("^");

for (var i = 0 ; i < s.length ; i++) {
switch(s[i]) {
case '*' :
res += ".*";
break;

case '.' :
case '?' :
case '^' :
case '$' :
case '+' :
case '{' :
case '[' :
case '|' :
case '(' :
case ')' :
case ']' :
res += "\\" + s[i];
break;

case '\\' :
res += "\\\\";
break;

case ' ' :
// Remove spaces from URLs.
break;

default :
res += s[i];
break;
}
}
return res + '$';
}


// initiates filtering on the given document (if possible).
// --accepts either the target-document directly, or through its parent-event
// --(mozilla sends an event parameter by default if nothing was directly passed *and* there's an event trigger)
function filter(eventorotherparam) {
// If loadsettings returns false, it means that the page should not be filtered.
if (!loadSettings()) {
return;
}

// if we were called by an event -- (as opposed to another function)
if (eventorotherparam.type) {
if (eventorotherparam.target.contentDocument)
var page = eventorotherparam.target.contentDocument; // This is the tab. We need to get the contents.
} else
var page = eventorotherparam; // we were sent the document directly -- (by the function)

parseFrames(page);// initiate the filtering!
}

// parses document looking for frames, *recursively* -- (embedded frames?)
function parseFrames(page) {
// if the element/page has frames
if (page.getElementsByTagName("frame").length > 0) {
for (var f = 0 ; f < page.getElementsByTagName("frame").length ; f++) {
var frame = page.getElementsByTagName("frame").item(f).contentDocument;
parseFrames(frame);
}
}
else
parseInlineFrames(page);
}

// parses document looking for iframes -- *Inline-Frames*
function parseInlineFrames(page) {
// if the element/page has iframes
if (page.getElementsByTagName("iframe").length > 0) {
for (var f = 0 ; f < page.getElementsByTagName("iframe").length ; f++) {
var iframe = page.getElementsByTagName("iframe").item(f).contentDocument;
parsePage(iframe);
}
}
// even if there weren't -- "onward, ho -!"
parsePage(page);
}

// Goes through all relevant tags and determines if they should stay or be banished. Smile
function parsePage(page) {
for (var j = 0 ; j < tags.length ; j++) {
var scanTags = page.getElementsByTagName( tags[j] );

for (var i = 0 ; i < scanTags.length ; i++) {
var src = findAttribute(scanTags[i],"src");
if (src && validate( getImageURL(src, page))) {
if (Hide) {
scanTags[i].style.visibility = "hidden";
} else {
scanTags[i].style.display = "none";
}
}
}
}
}

// Checks an element and its children recursively for an attribute.
function findAttribute(element, name) {
if (element.hasAttribute(name)) {
return element.getAttribute(name);
}

if (element.hasChildNodes()) {
for (var i = 0 ; i < element.childNodes.length ; i++) {
var res = findAttribute(element.childNodes[i], name);
if (res != false)
return res;
}
}

return false; // Didn't find it!
}


I impore either the developers or any javascript gurus out there to help me make AdBlock Opera compatible. Please! Take an hour and see if I'm right.

PS:
One of the other ways AdBlock is such an efficient ad blocker is that it uses CSS to make pages less messy, in lieu of all the holes from blocked ads. Opera also supports User CSS since version 7.5: http://www.chooseopera.com/FAQs/OperaUserCSS.html . Opera could be configured to use AdBlcok's style sheets very easily.

Contact me at aaron DOT foster AT gmail DOT com to talk about this more.
Back to top
Guest






PostPosted: Mon Aug 08, 2005    Post subject: Reply with quote

Why go through all that work for something that would only be a slow running hack if it worked at all?

Just get Ad Muncher.

It lets you right click on and remove images/links/frames in all the major browsers including opera and works as soon as you install it.

http://www.admuncher.com/beta.pl?version=4.7&build=18491&key=1102949266
Back to top
FosterSJC
Guest





PostPosted: Mon Aug 08, 2005    Post subject: Reply with quote

Anonymous wrote:
Why go through all that work for something that would only be a slow running hack if it worked at all?

Just get Ad Muncher.

It lets you right click on and remove images/links/frames in all the major browsers including opera and works as soon as you install it.

http://www.admuncher.com/beta.pl?version=4.7&build=18491&key=1102949266


Two reasons: 1. I am running Mac OS X Tiger, not Windows. 2. It would not be a slow-running hack... at least, it wouldn't run any slower than AdBlock runs in Firefox.
Back to top
Guest






PostPosted: Mon Aug 08, 2005    Post subject: Reply with quote

3. Admuncher costs money
Back to top
Marcus
Guest





PostPosted: Mon Aug 08, 2005    Post subject: Reply with quote

@FosterSJC

It's going to be ported to *nix and mac.


@Guest on the cost

It's a one time fee and it's worth the cost.
Nothing beats it.
Back to top
Guest






PostPosted: Mon Aug 08, 2005    Post subject: Reply with quote

Ad Muncher is trash, spam on other forums, not here...
Back to top
Drahken



Joined: 30 Oct 2004
Posts: 107

PostPosted: Wed Aug 10, 2005    Post subject: Reply with quote

Marcus wrote:

It's a one time fee and it's worth the cost.
Nothing beats it.


Anything that charges you for something that you can get for free elsewhere is NOT worth the cost. There are many free adblockers for IE, there are a couple free adblockers for moz/FF, there's a free adblocker or two for opera, there are many free "universal" adblockers that work with any browser (most such act as proxies), there are 2 completely free techniques that work for all browsers (HOSTS and PAC), plus most browsers (except M$IE, although most IE frontends such as maxthon, avant, etc have one form of adblocker or another built in) have some sort of custom adblocking scripting available. In gecko browsers there is the usercontent.css method and the hostperm method, opera browsers also have a filter.ini method and a css based method.
With all these FREE options, NO adblocker that tries to charge you anything is worth the cost.
Back to top
View user's profile Send private message
Wasgo
Guest





PostPosted: Wed Aug 31, 2005    Post subject: Reply with quote

Any word on if this works yet?
Back to top
mcm_ham



Joined: 17 Dec 2004
Posts: 310

PostPosted: Wed Aug 31, 2005    Post subject: Reply with quote

The critical part to get Adblock to work in Opera is to find something akin to Firefox's content policy module and how to hook into it. The crux of Adblock happens in the nsAdblock.js file (or at least it should). Not that I know much about Opera but I didn't think there was an extensions system like there is with Firefox and IE.
Back to top
View user's profile Send private message Visit poster's website
Guest_



Joined: 03 Sep 2005
Posts: 30

PostPosted: Sun Sep 04, 2005    Post subject: Reply with quote

Yeah, yeah. I say drop opera and just use Firefox, but if that hacks works more power to you.
_________________
Web bugs. just like good old hidden cameras inside your house.
Back to top
View user's profile Send private message
NotaUser
Guest





PostPosted: Thu Sep 22, 2005    Post subject: ... Reply with quote

I would love to see this. Opera is free now. A lot of folks who would normally try it out are blocked by lack of good adblocking support. Firefox users in particular.

Some way to carry adblock/filterset.g over to Opera would absolutely rock.

The Opera world would thank you immensely.
Back to top
G



Joined: 10 Oct 2004
Posts: 550

PostPosted: Thu Sep 22, 2005    Post subject: Reply with quote

http://forum.pierceive.com/viewtopic.php?t=88
_________________
Filterset.G
Back to top
View user's profile Send private message Visit poster's website
Vinnie Anjelica
Guest





PostPosted: Tue Oct 18, 2005    Post subject: Reply with quote

Anonymous wrote:
... Ad Muncher ...
PeerGuardian 2 (using the Ads list) is faster than admuncher, doesn't even allow any packets to go to ad sites, and it's opensource http://peerguardian.sourceforge.net/
Back to top
Display posts from previous:   
Post new topic   Reply to topic    The Adblock Project Forum Index -> Main All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group