mark.bockenstedt.net header image
Twitter
Gaming Linux Mac Software Tech
mu Updates
Web
Musings Rants & Raves Rumor Sports Weather
Video Reviews

Noise Filtering on Google Search Results

August 24th, 2008 · No Comments

Firefox with Greasemonkey: If you’ve ever searched for your website content on Google (and chances are you have), you’ll agree with me that it can be difficult to find your material amongst the results. Sometimes I search for my posts and see where they rank in specific queries to Google. Usually it takes me a while to find it because I’m impatient and skip over the link accidentally.

Off to trusty ol’ Greasemonkey we go for a quick script to run through each search result on the page and see if it points to my site (or has my site’s URL in it). If it does, it gets highlighted with a pretty orange box to make it stand out.

I also wanted to know if my first and last name were mentioned in any of the descriptions on the current page. These results get highlighted with a red box.

Some quick, easy noise filtration on Google’s results makes life much easier. Here’s the code for the script (feel free to use and modify it as you see fit).

// ==UserScript==
// @name           My Google Results
// @namespace      google.com
// @include        http://www.google.com/search?*
// ==/UserScript==
 
// Enter the name of the URL you wish to find - for multiple sites, separate urls by the vertical bar character |
// You don't need to enter the full url, just the domain is fine. (eg google.com)
var find_site = /mark.bockenstedt.net/i;
 
// If you wish to regex your full name also, enter it here
// Otherwise, comment out the next two lines
var first_name = /mark/i;
var last_name = /bockenstedt/i;
 
// Get a list of all li elements
var lis = document.getElementsByTagName("li");
for(var i = 0; i < lis.length; i++)
{
	// the li we're working with
	var li = lis[i];
 
	// for search results, the element has a class of g
	if(li.className = "g")
	{
		// get the anchor and the result text
		var a = li.getElementsByTagName("a")[0];
		var d = li.getElementsByTagName("div")[0];
 
		// regex match the anchor href
		var result = a.href.match(find_site);
		if(result != null)
		{
			li.style.border = "2px solid orange";
			li.style.width = "600px";
		}
		// regex match the name
		else if(first_name && last_name)
		{
			if(d.innerHTML.match(first_name) && d.innerHTML.match(last_name))
			{
				li.style.border = "2px solid red";
				li.style.width = "600px";
			}
		}
	}
}

Categories: Firefox
Tags:, , ,