SiteTraverser is a JavaScript class1 which you can use to create bookmarklets that crawl websites looking for the presence or lack of certain features.
Here’s an example that utilises SiteTraverser (give it a click!):
Click to traverse!
All it does is list the titles of some pages on this site. The code behind the bookmarklet is quite simple:
var s = document.createElement('script'),
t = setInterval(function(){
if ( window.SiteTraverser ) {
// Script is loaded
clearInterval(t);
s.parentNode.removeChild(s);
// Let's start traversing
new SiteTraverser({
// Just for this demo, we're specifying the URLs.
// Normally, SiteTraverser would just crawl in all directions.
urls: ['/foo/1.html','/foo/2.html','/foo/3.html'],
check: function(source, url){
var titleMatch, title;
if ( titleMatch = source.match(/<title>(.+?)< \//) ) {
return this.success(
"Title found: " + '"' + titleMatch[1] + '"',
"URL: " + url
);
}
return this.failure("No title :(");
}
}).go();
}
}, 100);
s.src = 'http://qd9.co.uk/projects/SiteTraverser/sitetraverser.js';
document.body.appendChild(s);
First, we load sitetraverser.js, and then we continue to instantiate (new SiteTraverser()) and run it (.go()).
I’m sure none of you have missed the recent hype surrounding the new ‘Let me google that for you’ initiative, but for those who did miss it here’s what it’s all about, from the site:
This is for all those people that find it more convenient to bother you with their question rather than google it for themselves.
I think it’s an awesome idea and I’m already making use of it… it’s so much more fun to retort with a LMGTFY URL instead of the everyday "Have you tried Google?"!
I’m quite lazy and can rarely be bothered to go to the LMGTFY website so I created a cool bookmarklet which will let you enter a search phrase then it will go off and get a shortened version of the "let me Google that for you" URL. (It’s shortened so that when you post it on a forum/IRC/chat the recipient won’t know what hit ‘em until they click on it!)
You can try it out now by clicking this link:
Let me Google that for you!
If you want to keep it then drag the bookmark up to your bookmark panel/toolbar. (Or right-click to add to favourites).
UPDATE: The above bookmarklet doesn’t appear to work in older browsers and is a little bloated. I’ve created a much simpler one which will alert the shortened LMGTFY URL:
Let me Google that for you! (simpler)
Let me know if you spot any bugs in the second one (the simpler version) – it should be working in ALL browsers.