[Greasemonkey] help with user script

Tom Sonsuwan tom.sonsuwan at speedydomainregistration.com
Tue Aug 30 03:01:03 EDT 2005


  var xpath="//a[contains(text(), 'page')]";
  links =
document.evaluate(xpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);

1. How can I change var xpath="//a[contains(text(), 'page')]"; so 
that it only return links with certain  url in it?

2. How to search for phrases with space?  var 
xpath="//a[contains(text(), 'page')]";

Thanks for your help.

Tom

----- Original Message ----- 
From: "John Plsek" <gm at plsek.id.au>
To: <greasemonkey at mozdev.org>
Sent: Monday, August 29, 2005 3:23 AM
Subject: Re: [Greasemonkey] help with user script


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);
  }
})();
_______________________________________________
Greasemonkey mailing list
Greasemonkey at mozdev.org
http://mozdev.org/mailman/listinfo/greasemonkey



More information about the Greasemonkey mailing list