Blocking Ads with Adblock

 < Day Day Up > 

Many advertisements can be blocked in Firefox by using an extension named Adblock. Adblock lets you create, import, and export filter lists to block content.

Installing Adblock is relatively easy: Start at http://adblock.mozdev.org/ and read about the Adblock project. On the navigation bar at the top of the page click Install (see Figure 5.4). This option takes you to the Adblock installation page.

Figure 5.4. The Mozilla Adblock home page (http://adblock.mozdev.org) is the Adblock home page. Note the navigation bar at the top.


When you're at the installation page, install the latest build. (Most likely the latest build is the only build available.)

Adblock is an easy extension to use. You configure Adblock by selecting Tools, Adblock in Firefox. This displays a second level of menu selections:

  • List All Blockable Elements This option scans the currently displayed page and lists all the elements that can be blocked. You can also reach this list by clicking Adblock at the right end of the status bar.

  • Overlay Flash (for left-click) This allows context clicking Flash objects.

  • Preferences As with all extensions, Adblock has a Preferences window. This window is covered next.

Tip

By default, Firefox is configured to block installation of software or extensions except those on the approved list. If this blocks your installation of Adblock, an error status bar appears below the Firefox toolbar (or the tab bar if you have a tab bar displayed). By default, the various Mozilla sites are preapproved.


Figure 5.5 shows the Adblock Preferences window. This window enables you to create new filters by typing them in the New Filter box and clicking Add.

Figure 5.5. In Adblock's Preferences window, you can set options and create new filters.


In addition to allowing you to create new filters, the Adblock Preferences window also lets you set Adblock options and display help (this actually comprises two links one to the Adblock home page and a second link to a page that describes regular expressions).

The Adblock options you can configure include

  • Obj-Tabs Obj-Tabs are small tabs displayed on content that Adblock is capable of blocking. If you click this tab, the content is automatically added to your filter list.

  • Collapse Blocked Elements When content is blocked, you can collapse (remove) the space that was used by that content. Some pages look better with this option utilized.

  • Check Parent Links This option causes Adblock to block not only the ad server, but also the site to which the ad is pointing. It's a bit radical, but for some users the target is as bad as the advertising pusher.

  • Site Blocking If this option is set, Adblock blocks the site; otherwise, it displays the site but not the blocked content.

  • Keep List Sorted The Adblock filters list can be sorted to allow easier management. In addition, you can sort the list by exporting it and sorting with a sort utility. Once sorted, the filter list must have [Adblock] as its first line.

  • Import Filters Even though users can create their own filters, they also can import filters from other sources (such as from the Internet) into Adblock.

  • Export Filters A wise user will export and save his customized filters to a safe location. This allows recovery if the installation of Firefox is lost as well as sharing.

  • Remove All Filters Sometimes things just get too messed up to continue. We've all done it made some rules and later found that one (we don't know which) was causing a problem. With this option, you can remove all the filters.

  • Deinstall It is always a good idea to remove all the installed extensions before upgrading your version of Firefox. As well, if you find that Firefox becomes unstable, try removing extensions. The Deinstall option is available in case you need to remove Adblock.

Note

There is nothing to prevent you, or anyone else, from creating all the necessary filters. But, an old rule of computing says, "Don't reinvent the wheel!" This means that, if filters already exist that work well, then use these instead of writing your own. One site that has Adblock filters that are updated every few days is at http://www.geocities.com/pierceive/adblock/.


Importing, Exporting, and Removing Filters

Adblock allows you to import, export, and remove filters. This capability is the heart and soul of Adblock's functionality. Sites that serve advertisements change frequently, old sites disappear, and new sites pop up with startling regularity.

As well, sometimes it is best to just start with a clean slate. You can remove all existing filters if necessary.

Importing Filters

Importing filters lets you load filters you have created and exported (see the next section, "Exporting Filters," for details on exporting filters). A Google search shows many sites that list available filters.

Don't ignore filter lists that originate from outside your country. A filter list from Germany can work just as well as one from the United States usually. The best advice here is to try it and see if you like it.

Importing is done from Adblock's Preferences window. Click Adblock Options, and select Import Filters from the menu displayed. This opens the Select a File window, which is the Windows Open File window, renamed. Select your text-based filter file. This file must have an extension of .txt; if it doesn't, enter a filename of *.* to see all files available in the target folder. After a file has been selected, a Confirm window asks you whether you want to overwrite the current list of filters or append to the end of the list.

Recovering from an Import Disaster

"Oops, I made a mistake." How many times has this thought run through your mind just after confirming a choice? In importing, after you select a file to import, you have only two options: replace or append. You might append many filters to the end of your list, or you might accidentally lose the filters you created on your own.

All is not lost, though. There are two recovery tricks. First, when you are in the Adblock Preferences window, click the Close button in the title bar. This closes the window without updating the list of preferences.

Another recovery is to open a Windows Explorer window, navigate to your profile, and copy the prefs.js file to a backup location (refer to Chapter 4, "Managing Profiles," to find where your profile is located.) Then close Firefox and copy that saved backup copy of prefs.js back to the Firefox profile location. (Firefox rewrites prefs.js when it exits, so until then the original file is still on your drive.)

Of course, this is a good place to point out that before modifying anything, you should back up your profile!


The filter file format is a simple text file. However, Notepad will not effectively edit this file because the lack of carriage returns in the file causes Notepad difficulty. Instead of Notepad, edit this file with WordPad, and you should be set!

The first line (and only mandatory line) contains

[Adblock] 

Each subsequent line contains one filter per line. The filters can be URLs, with an allowed * as a wildcard character. Also allowed are GREP, such as regular expressions. In Adblock regular expressions begin and end with a forward slash (/).

Note

Regular expressions are strings that contain a complex wildcard syntax to allow matching multiple strings. If you want to learn all about regular expressions, many sites on the Internet can help you. One that I can recommend is http://www.regular-expressions.info/reference.html. Anyone familiar with GREP utilities should understand regular expressions.


Exporting Filters

Adblock lets you export their filters. When exporting, Adblock prompts for a filename to save to. I recommend supplying both a filename and an extension of .txt which is not supplied by default. An exported filter set can be directly imported into Adblock as desired.

Exporting filters provides a great way to both back up and share your filters.

Removing Filters

Adblock's Remove All Filters option enables you to clear all filter definitions, which is useful if you want to start from scratch. If you will be loading new filters, you don't need to remove the existing filters. Rather, simply click OK in the Confirm dialog box.

Adblock Preferences

Adblock stores filters and Adblock option settings in prefs.js. There are a number of lines in this file for Adblock, as the following code shows:

user_pref("adblock.enabled", true); user_pref("adblock.fastcollapse", false); user_pref("adblock.frameobjects", true); user_pref("adblock.hide", false); user_pref("adblock.linkcheck", false); user_pref("adblock.pageblock", false); user_pref("adblock.patterns", "ads.com adserv.com advertise.com"); 

Settings are saved for a number of Adblock options, including the following. (Please note that not all versions of Adblock support all the options listed here.)

  • enabled This Boolean setting turns Adblock on and off. Its values allowed are true and false.

  • fastcollapse This Boolean setting turns on fast collapsing of frames and content to areas where advertising was removed.

  • frameobjects This Boolean object is used to control whether objects are framed.

  • hide This Boolean object controls whether objects are hidden (which does not alter the page layout) or removed (which collapses or changes the layout of the page).

  • linkcheck This Boolean object controls whether Adblock will check the links in JavaScript for spaces.

  • pageblock This Boolean object controls whether Adblock will block pages.

  • patterns This string object contains the patterns (filters) the user has defined.

Caution

You could put Adblock settings in user.js. However, doing so has no effect. Adblock checks for settings only in prefs.js, and not in user.js.


     < Day Day Up > 


    Firefox and Thunderbird. Beyond Browsing and Email
    Firefox and Thunderbird Garage
    ISBN: 0131870041
    EAN: 2147483647
    Year: 2003
    Pages: 245

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net