[Greasemonkey] Re: So, how do I do ... everything?

Andre gm at andrecgn.de
Sun Jul 16 01:57:57 EDT 2006


Hi Dave,

I assumed you were doing something like that with the timeout. And 
actually I didn't answer your original question why that code does not 
work as a GM script while it works as a script embedded in the page.

When you pass a string to setTimeout it is evaluated in the context of 
the page, but the function setFloater is unknown there, because it 
'lives' in the GM environment. If you use a reference to your function 
instead

   setTimeout(function() { setFloater("floater"); }, 10)

it would work. Search for "javascript closure" and you will find 
excellent explanations.

But then you don't need it anymore for the positioning ...

Cheers, Andre

Dave Jacoby wrote:
> On 7/15/06, Andre <gm at andrecgn.de> wrote:
>> try
>>         position = "fixed";
>> that way FF will float the div in the same position.
> 
> I was using absolute and resetting top in relation to
> document.body.scrollTop, like the sample code I found. So that sample
> code sucked? Good to know.
> 
>> I don't understand what you wrote about the setTimeout. It is nowhere in
>> your script. If you use that to reposition the div, it is not needed
>> with "fixed".
> 
> Look at the diked-out function call in here:
>  http://csociety.org/~jacoby/Code/AI/floater.js
> 
> All that complexity fixed with one addition to the style. Heh.
> 
> That's what I was trying to replicate. And I shouldn't work at 3am,
> because I copied the user script to the desktop, started working on it
> again and drafting the email, then decided that I shouldn't send
> attachment, I should post links.
> 



More information about the Greasemonkey mailing list