[Greasemonkey] insertBefore(document.body) glitch

Joe la Poutre jsixpack at gmail.com
Wed Jul 13 00:00:09 EDT 2005


Sorry, was replying to an old thread in previous mail, so here a quote
from Malcom Mill I was referring to:

Hi,
I'm using the script below to insert text at the top of each viewed page.

var start, newElement;
start = document.body;
newElement = document.createElement('b');
newText = document.createTextNode("The Greasemonkey salutes you!");
newElement.appendChild(newText);
start.insertBefore(newElement, start.firstChild);

It has two unexpected/undesired results in certain circumstances.

1). With my home page set to about:blank, when I open a new browser
tab the string is echoed twice.

2). On certain pages (i.e. google.com) it seems the entire body is
reproduced underneath itself and only links on the bottom body work.


On 7/12/05, Joe la Poutre <jsixpack at gmail.com> wrote:
> Just for the record: I'm seeing the same behavior with GM 0.3.4 and
> the following code:
> 
> var ol = document.createElement('ol');
> // append child stuff removed...
> document.getElementsByTagName("body")[0].appendChild(ol);
> 
> This is solved by calling the appendChild line from a timeout:
> 
> setTimeout(function() { // stuff removed...
> document.getElementsByTagName("body")[0].appendChild(ol);
>  }, 1000);
> 
> Anyway, this solution looks like a kludge to me.
>


More information about the Greasemonkey mailing list