[Greasemonkey] Too many IDs?

Brendan Crosser-McGay verifex at gmail.com
Tue Sep 27 17:06:50 EDT 2005


I have found a curious problem, maybe this is something to do with mozilla
and memory usage?

I've got Firefox 1.0.7 running with Tabbrowser prefs 1.2.8.5<http://1.2.8.5>,
Download Manager Tweak 0.6.6, Livebookmark This 0.2, Mouse Gestures
1.0.2and finally Greasemonkey
0.5.3 running.

I am using a script that assigns ID tags to a bunch of span tags it injects
into a page (sometimes up to 200 per page). Randomly, the entire script
fails, as though nothing happened. Sometimes it will succeed, then fail, and
sometimes it will work just fine. I wanted to know, is there another way to
address massive specific amounts of elements with psuedo JS added into the
page (JS added to function on the page, using GM to insert that extra JS
code. I'm frustrated because I can run a set of code, I add this extra
variable to the code, run it and it doesn't work. However if I remove that
code, at that point, it still crashes.

Here is a snippt of code that seems to work for a while:
toggleswitch="<select onChange='for(i=0;i<tb.length;i++) {";
toggleswitch=toggleswitch+"if ((document.getElementsByTagName
(\"span\")[i].id.match(/on/))&&(this.options[this.selectedIndex].value==1))
document.getElementsByTagName(\"span\")[i].onclick();";
toggleswitch=toggleswitch+" if ((document.getElementsByTagName
(\"span\")[i].id.match(/off/))&&(this.options[this.selectedIndex].value==2))
document.getElementsByTagName(\"span\")[i].onclick();";
-----------------------------------
toggleswitch=toggleswitch+"}'><option value=1>Collapse All</option><option
value=2>Expand All</option></select>";
document.body.innerHTML=toggleswitch+document.body.innerHTML;

But as soon as I add this code in the place of the line above, it breaks and
stays broken, even after I remove this code:
toggleswitch=toggleswitch+" if (this.options[this.selectedIndex].value==3)
{";
toggleswitch=toggleswitch+" if
(document.getElementsByTagName(\"span\")[i].id.match(/off+/))
{";
toggleswitch=toggleswitch+"
ns=tb[i].childNodes[3].childNodes[1].childNodes[1].childNodes[0].childNodes[0];";
toggleswitch=toggleswitch+" if (ns.innerHTML.match(/[0-9]+
[0-9][0-9][0-9][0-9]/)) {";
toggleswitch=toggleswitch+" document.getElementsByTagName
(\"span\")[i].onclick();";
toggleswitch=toggleswitch+" }";
toggleswitch=toggleswitch+" }";
toggleswitch=toggleswitch+" }";


More information about the Greasemonkey mailing list