Monday, December 18, 2006

Power to the consumer with Greasemonkey

Fool me once, shame on you... plus I'll build a greasemonkey script to
filter you out of my daily browsing so that we don't get into that whole 'fool me twice' scenario.

This simple how-to is for all the online bargain hunters that have been screwed over by an online retailer. My personal inpiration came from TigerDirect.com. I made only 1 purchase from them, but that and hindsight research into their Better Business Bureau record was enough to swear them off forever.

Unfortunately, they kept popping up. I like to surf deal sites like dealnews.com and techbargains.com. Nothing was more frusterating than scanning through the site and seeing an item you've been waiting for... only to read the fine print and see it's from your online nemisis. Well, I finally got around to building a simple Greasemonkey userscript for Firefox that will filter TigerDirect (or modify it to match your own retailer of choice) out of my deal sites for good.

Let's tackle Dealnews.com first. Looking at the HTML source, we can see that each deal entry is actually a sequence of 4 div elements for the item image, headline, item description and a timestamp:

<span style="font-family: courier new;"><div class="imgdiv"> ... </div></span>

<span style="font-family: courier new;"><div class="article art-headline"> ... </div></span>

<span style="font-family: courier new;"><div class="article article-body"> ... </div></span>

<span style="font-family: courier new;"><div class="timestamp"> ... </div></span>


The approach I'll take is to match a regular expression against the content of the "article article-body" div elements. If the content of that div contains the text "TigerDirect", then I'll set the display property of the div and its image, headline and timestamp to 'none'. Of course, there is a risk of blocking out the wrong items. Sometimes a deal article will compare the deal price to other similar prices. In this case, you could block out deals simply b/c they compared the price to your retailer. I'll take that chance... here's the script:

var regEx = /tigerdirect/i;
var elems = document.getElementsByTagName('div');

for (i=0;i if (elems.item(i).className == 'article article-body'
&& regEx.test(elems.item(i).innerHTML)) {

for (j=i-2;j<=i+1;j++) {
elems.item(j).style.display='none';
}
}
}

It's even easier to do this at TechBargains.com. Each deal entry there is completely contained in a single div element of class 'Content', making an equivalent script look like:

var regEx = /tigerdirect/i;
var elems = document.getElementsByTagName('div');

for (i=0;i if (elems.item(i).className == 'Content' &&
regEx.test(elems.item(i).innerHTML)) {
elems.item(i).style.display='none';
}
}


From here, you can customize it to suit your needs. Want to still have the deals on the page, but just flagged? Try a line-through text decoration or background color style instead of hiding the div. Want to block out more than 1 retailer? Just modify the regular expression. Here's one to add walmart to the blocked list:

regEx = /(tigerdirect)|(walmart)/i;

That's it! You can roll your own or modify the versions here (dealnews) or here (TechBargains). Save it as a user.js userscript, install it in GreaseMonkey, map it to the site URLs, and say goodbye to your least favorite retailers.

Labels:

1 Comments:

At 8:04 PM, Blogger JavaChips said...

Hi Josh,

Take a look at Boddit.com.

I used to browse a lot of deal sites, but this has made it a LOT easier.

 

Post a Comment

<< Home