setInterval can be part of one solution..
what I think you can do, is to create a function that is called every
100 ms (with setInterval, maybe), and checks if the original
javascript has run. (perhaps the original js create some global
variable, or add a stylesheet, or something). Then if find detect
this, wait another 100 ms (just in case). And then do your stuff.
you can emulate setInterval with setTimeout, if for some reason
setInterval confuse you.
function my_Stuff(){
}
function loop(){
if( is_my_moment_already() ){
setTimeout(my_Stuff,200);
return;
}
setTimeout(loop,200);
}
Here is_my_moment_already would do something to detect if the original
javascript has finished/is running.
note: I don't think Greasemonkey is a good way to learn javascript,
because is not a simple enviroment, and can be harder to debug. Also
usually you are reading other people javascript, and tryiing to
"break" the page and do things the page is not designed for, so is
more a advanced topic. The one reason that make greasemonkey good
for learning js is that is fun,and whatever usefull you do can be
shared with millions of people. I can only imagine the feel of
greatness if your tiny script run on million computers. Or the small
and awesome "fuck you", wen you make a option in a webpage forever
"default", fix your favorite forum to use helvetica, or the million
nice things you can do with greasemonkey.
- - -
I think that Greasemonkey runs on the "DOM Ready" event. Wen the DOM
tree is finished, but before all the resources are loaded. The webpage
own javascript could have his javascript configured to load in <body
onload="", this is a different event that is called wen resources
(like images and css) have fully loaded.
On 19 March 2012 03:24, Forrest <[email protected]> wrote:
> Thank you very much for you replay.
> I'm new to javascript and don't know a good way to delay my script. I
> tried using setInterval and found that some buttons on the webpage
> failed. I suspect whatever script I insert via GM, the webpage fails.
>
> On Mar 7, 11:16 pm, Tei <[email protected]> wrote:
>> On 7 March 2012 06:15, Forrest <[email protected]> wrote:
>>
>> > There are some DOM elements created by the web page's jQuery script. I
>> > just add a css class for the body; the elements didn't show up. I
>> > guess my script stops the webpage's own script.
>>
>> > Anyway to fix this and let the original script continue? Thank u.
>>
>> You can program your script to run something after the original script
>> has finished. Also fix the cause of breakage. Perhaps the new class
>> you are adding to body is a name that the jquery script already want
>> to use for something else. if the script needs to do
>> $(".logo").something and expect that to run on a image, will break if
>> you add logo to body <body class="body">.
>>
--
--
ℱin del ℳensaje.
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.