[Greasemonkey] help with user script

John Plsek gm at plsek.id.au
Mon Aug 29 21:23:26 EDT 2005


Tom Sonsuwan wrote:

>Thanks John,
>
>Great start.
>
>Is there any way to make the html of the links look like this:
>normal:   <a href=someurl>Some anchor</a>
>new:  <a href=someurl>Some anchor</a> - <img 
>src=image.php?url=someurl>
>
>  
>
haven't tested this one

// ==UserScript==
// @name          anchorImage
// @description      Test
// @include       *
// ==/UserScript==
(function() {
  var baseImage="http://somewhere.com/image.php?url=";
  var xpath="//a[contains(text(), 'page')]";
  links = 
document.evaluate(xpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  for (var i = 0; i < links.snapshotLength; i++) {
    var node = links.snapshotItem(i);
    var parent = node.parentNode;
    var before = node.nextSibling;
    parent.insertBefore(document.createTextNode(" - "), before);
    var img=document.createElement("IMG");
    img.src=baseImage+escape(node.href); // to be sure????
    parent.insertBefore(img, before);
  }
})();


More information about the Greasemonkey mailing list