
// ==UserScript==
// @name           Hackaday Nostalgia
// @namespace      http://hackaday.com
// @description    Overlay photograph border and taped corners for article images at Hack a Day.
// @include        http://hackaday.com/*
// ==/UserScript==

//get all DIVs of the snap_preview class
var allDivs, thisDiv;
allDivs = document.evaluate(
	"//div[@class='snap_preview']",
	document,
	null,
	XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
	null);
//step through each DIV
for (var i=0; i<allDivs.snapshotLength; i++) {
	thisDiv = allDivs.snapshotItem(i);

        //Alter the first img of each DIV
	var image = thisDiv.getElementsByTagName('img');
	
	//Make sure we've got an IMG in this DIV	
	if (image[0]) {

		//Save original source URL
		var orig_src = image[0].src;
		//Concatenate for CSS use
		orig_src = 'url(' + orig_src + ')';
		//Set original as background
		image[0].style.background = orig_src;

		//Set Hack a Day overlay as image
		image[0].src = 'http://hackadaycom.wordpress.com/files/2009/10/had_frame.png';
	}
}
