[Greasemonkey] document.getElementsByTagName("a") problem

chris feldmann cfeldmann at gmail.com
Wed Sep 7 14:20:21 EDT 2005


On 9/7/05, Ying Zhang <meow at regretless.com> wrote:
> Tried that. Same thing happens as when I use search. :(
> 

Did you look at the file Jeremy attached? It works as advertised out
of the box. Here it is as a userscript:

// ==UserScript==
// @name          commentfinder
// @namespace    
// @description	  pulls comments out
// @include       *tabulas.com*
// ==/UserScript==

var allLinks, thisLink; 
allLinks = document.evaluate( '//a[contains(@href, "#comment")]', 
		document, 
		null, 
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, 
		null); 

for (var i = 0; i < allLinks.snapshotLength; i++) { 
  thisLink = allLinks.snapshotItem(i); 
  //do something with the link
	
}

> 
> 
> On Wed, 7 Sep 2005 10:55:32 -0500, "Jason Hutchinson"
> <thezikes at gmail.com> said:
> > You might try if(uim.indexOf("#comment") > -1) instead, I think that'll
> > clear it up.
> >
> > On 9/7/05, Ying Zhang <meow at regretless.com> wrote:
> > >
> > > Hello, I'm a newbie to greasymonkey. I'm trying to develop a script that
> > > opens all the comments links in tabulas.com <http://tabulas.com> in a
> > > popup window. I thought
> > > this should be quite easy but I'm running into a weird problem. Here's
> > > my code
> > >
> > > (function(){
> > > var l = document.getElementsByTagName("a");
> > > alert(l.length);
> > > var uim = "";
> > > var cand = null;
> > > for (i = 0; i<l.length; i++) {
> > > cand = l[i];
> > > uim = cand.getAttribute('href');
> > > // alert(uim);
> > > if(uim.search("#comment") >= 0)
> > > alert(uim);
> > > }
> > > })();
> > >
> > > Right now I just want to identify all the links to comments page which
> > > always end with #comment. The funny thing is if I comment out the
> > > .search if state, and uncomment the alert(uim), it produces more links
> > > on the page than the if statement. It seems if I use the .search if
> > > statement, many of the links are being omitted on the page even tho it's
> > > in the same for loop. I'm so confused as why it is happening.
> > >
> > > You can test out the script at
> > > http://userscripts.org/scripts/show/1660
> > > at tabulas.com/~dodozhang21 <http://tabulas.com/~dodozhang21>
> > >
> > > Let me know if there is a better way to identify the links. Thanks!
> > > --
> > > http://regretless.com
> > >
> > > --
> > > http://www.fastmail.fm - Or how I learned to stop worrying and
> > > love email again
> > >
> > > _______________________________________________
> > > Greasemonkey mailing list
> > > Greasemonkey at mozdev.org
> > > http://mozdev.org/mailman/listinfo/greasemonkey
> > >
> >
> >
> >
> > --
> > --Jason Hutchinson
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey at mozdev.org
> > http://mozdev.org/mailman/listinfo/greasemonkey
> --
> http://regretless.com
> 
> --
> http://www.fastmail.fm - A no graphics, no pop-ups email service
> 
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list