// ==UserScript==
// @name          Images to Links
// @namespace     http://loucypher.wordpress.com/
// @include       http://forums.mozillazine.org/viewtopic.php*
// @description	  
// ==/UserScript==

function imgToLink(img, src) {
  var a = document.createElement('a');
  a.href = src;
  a.appendChild(document.createTextNode(src));
  img.parentNode.insertBefore(a, img);
}

var XPath = '//div[@class="postbody"]//img[starts-with(@src, "http://")]';
var imgs = document.evaluate(XPath, document, null, 6, null);

if(!imgs.snapshotLength) return;

for(var i = 0; i < imgs.snapshotLength; i++) {
  var img = imgs.snapshotItem(i);
  imgToLink(img, img.src);
  img.parentNode.removeChild(img);
}

