Extending Firefox With Greasemonkey Script: A Google Search Filter

greasemonkeyOne of the many reasons Firefox has enjoyed a strong following is the ability to extend its functionality with add-ons.  These optional enhancements allow users to incorporate a huge variety of features and formatting changes to the browser, such as FTP, Web Design, Ad Blocking and Synchronization.  One particular add-on, called Greasemonkey is unique in that it “allows users to install scripts that make on-the-fly changes to HTML web page content on the DOMContentLoaded event, which happens immediately after it is loaded in the browser (also known as augmented browsing). As Greasemonkey scripts are persistent, the changes made to the web pages are executed every time the page is opened, making them effectively permanent for the user running the script. Greasemonkey can be used for adding new functions to web pages (for example, embedding price comparison in Amazon.com web pages), fixing rendering bugs, combining data from multiple webpages, and numerous other purposes.” (Wikipedia).

I’m going to show you a simple Greasemonkey script that will remove undesirable search results from a Google so you don’t have to manually filter through them. The necessity came to me because I regularly use Google for research and have noticed a high number of “false positives” resulting from a certain site’s aggressive (and inaccurate) SEO practices,. Once this script is installed, their domain’s results will no longer appear in Google searches performed from my web browser.

Pre-Requisites:

Once you have these install, the next step is to understand the structure of a Greasemonkey script.  A comprehensive guide to Greasemonkey script is available online, but here is a quick summary.

Greasemonkey Script Header


// ==UserScript==
// @name           A Unique Name For Your Script
// @namespace   URL Location the script was initially published at
// @description    So, uhm, what does this script do exactly?
// @include         What domains/urls should this script be applied to?
// @exclude        What domains/urls should this script be NOT apply to?
// ==/UserScript==

The // ==UserScript== begins and terminates this section, encapsulating the various elements and their definition (called meta-data). @include and @exclude can be listed multiple times if several locations need to be specified and the wildcard definition * can be used to define “all” domains.

The next section of a Greasemonkey script. This can be relatively simple, such as in our case or an entire sophisticated application.


var count = 0;
list = document.getElementsByTagName('a');
for (i=0; i

Replace "domain-name" with the offending search result. Example: www.awful-serp-polluter.com would simply be "awful-serp-polluter" (no quotes). This will also filter subdomains, but not domains with similar names (i.e. sub.awful-serp-polluter would be blocked but awful-serp-polluter.blogger.com would not).

serp_cleanerInstalling Greasemonkey Script

So, we have a Greasemonkey Script and want to share it with the world. Hosting the entirety of the code as a .js file will allow anyone with Greasemonkey to click on the link and they will receive an Install prompt from Firefox. Those without Greaemonkey will get a .js file for viewing or downloading. A note about naming conventions; the javascript file must end with ".user.js". This let's the Greasemonkey add-on identity the script as an installable piece of code. As with ANY software, you should only install from trusted sources or after inspecting the source code for yourself.

Here is a the completed script ready for install. This version blocks spammy Torrent Reactor results in Google searches. Install/Download SERPS Cleaner, Torrent Reactor.

You may also like...

Leave a Reply