[Greasemonkey] help with user script

John Plsek gm at plsek.id.au
Mon Aug 29 20:41:34 EDT 2005


Here's a little something I just knocked up ;-) adds a smiley after any 
link that has "page" in the anchor text

// ==UserScript==
// @name          anchorImage
// @description      Test
// @include       *
// ==/UserScript==
(function() {
  var style=[
    "a.smilied:after{content: url(",
    "data:image/gif;base64,",
    "R0lGODlhDwAPANUAAAAAAI2z2D9mswAzmbfQ53Wj0f///2WPxi1Wqai83M/g75Sn",
    "zZa53LzT6BFAn4Sk0GaZzKzI48/W4pO22XWby9bj8KzA3oSt1i9crYyl1kpts32o",
    "1JS428XZ6tDW45y+3qbE4a/K5N3p863F3pGt1DJfrkRstWaZzHuezcPY6yhXq5q0",
    "2O3t7QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    "AAAAAAAAAAAAAAAAACH5BAUUACwALAAAAAAPAA8AAAaWQJaQtdA4Bg7NYjj0IAQW",
    "RYdAEiAkQ4kjIeo0QmDQw4FlIbgAQCQCSn9QCKKmS1iDPnh8qRhtRAB3HwAchChG",
    "FSlgAHgcAAGPAUcKdSB3hAEXmRdIHSGAHwwMmBcAGxtJK55pq6sFB0ombAAGtLQA",
    "BQUqSwgPd6y3rnEsHg4PeBOYG64OHk0IGA/IFxQlCM1MckdJS0NBADs=",
    ");}"
  ].join("");
  var head=document.getElementsByTagName("head")[0];
  var ele=document.createElement('link');
  ele.rel='stylesheet';
  ele.type='text/css';
  ele.href='data:text/css;charset=utf-8,'+escape(style);
  ele=head.appendChild(ele);
  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++) {
    node = links.snapshotItem(i);
    node.className+=" smilied";
  }
})();

Tom Sonsuwan wrote:

>Hello,
>
>Been trying to write a script to add an image to the end of 
>links on a page.
>Only links with certain anchor text would be selected.
>
>Tried unsuccessfully for couple of days now.
>
>Please help. 
>
>_______________________________________________
>Greasemonkey mailing list
>Greasemonkey at mozdev.org
>http://mozdev.org/mailman/listinfo/greasemonkey
>
>  
>


More information about the Greasemonkey mailing list