views:

79

answers:

2

It's a greasemonkey script. I don't know javascript so that makes this especially fun.

function notify(){
    if window.find("1 minute")==true{
        alert("y");
        setTimeout("alert('time to click soon!')",60000)
    }
    if window.find("2 minute")==true{
        alert("y");
        setTimeout("alert('time to click soon!')",2*60000)
    }

...repeated x30...

}
notify();

Thanks in advance.

+6  A: 

You're missing parentheses around the if conditionals. They should look like:

if (window.find("1 minute")) {
    alert("y");
    setTimeout("alert('time to click soon!')",60000)
}

Also, no need to explicitly test against true; the if statement does that for you!


More things to make Douglas Crockford less angry with you

Don't pass strings into setTimeout. Pass functions. Like this:

setTimeout(function () {
    alert('time to click soon!');
}, 60000);

or like this (even better, since you're reusing the function):

function showAlert() {
    alert('time to click soon!');
}

// later...

setTimeout(showAlert, 60000);
Matt Ball
Thanks! Very helpful.
xelab
A: 

Also, I think you should probably be using unsafeWindow.

Fozi
The article says **NOT** to use unsafeWindow, why on earth would you suggest it? `This command can open certain security holes in your user script, and it is recommended to use this command sparingly.` and further down `USE OF UNSAFEWINDOW IS INSECURE, AND IT SHOULD BE AVOIDED WHENEVER POSSIBLE. `
Marko
Because he probably wants to find something in the page. `window` will not search in the client page, but in greasmonkey script context. Also, the article says that sometimes there is no other way to use it. And the other thing is that for the page to use this security hole, it would have to know about xeleb's script, and that he's using greasemonkey.
Fozi
Using unsafeWindow in private scripts is ok, using it in a script that you publish is no-no.
Fozi