2

I would like to add a delay of 5 seconds after likeMe() loop has finished. Once finsh I would like to trigger a click on the log out button of Facebook.

I'm stupid when it comes to javascript symantics; therefore I have no idea on how to trigger any of this? With this in mind where/how would I add this effect after the loops is over:

I've normally use .promise().done() to do the finally steps after a loops but I have no idea how to place this $.delay(5000).promise().done( $('input[value="Log Out"]').click()); within the javascript.

BACKGROUND: creating a installation art piece using arudino, processing and & greasemonkey jQuery.

FULL SCRIPT:

unsafeWindow.likeMe = likeMe;
function likeMe() 
{   

        input = document.getElementsByTagName("input");
        for(i = 0; i < input.length; i++) 
        {
            myID = input[i].getAttribute("data-profileid");
            if(myID != null && myID.indexOf("342584172457437") >= 0)
                input[i].click();
        }
        $.delay(5000).promise().done( $('input[value="Log Out"]').click()); 
        // this is wrong but yeah i have no clue where or how to put it on here.

}


$(window).load(function(){

    var isCtrl = false;
    document.onkeyup=function(e) {
        if(e.which == 17) isCtrl=false;
    }
    document.onkeydown=function(e){
        if(e.which == 17) isCtrl=true;
        if(e.which == 46 && isCtrl == true) {
            likeMe()

            return false;
        }
    }

});
2
  • you have to use settimeout instead of delay Commented Jun 23, 2012 at 5:34
  • detect the end of the loop, if(input.length == -1){ setTimeout(function(){ // code here }, 5000);} Commented Jun 23, 2012 at 5:35

2 Answers 2

2

You can use setTimeout like

function likeMe() 
{   

    input = document.getElementsByTagName("input");
    for(i = 0; i < input.length; i++) 
        {
            myID = input[i].getAttribute("data-profileid");
            if(myID != null && myID.indexOf("342584172457437") >= 0)
            input[i].click();
        }

   setTimeout(function() {
        $('input[value="Log Out"]').click();
   }, 5000);

}

or inside the onkeydown like

document.onkeydown=function(e){
        if(e.which == 17) isCtrl=true;
        if(e.which == 46 && isCtrl == true) {
            likeMe();
            setTimeout(function() {
               $('input[value="Log Out"]').click();
            }, 5000); 
            return false;
        }
    }

But not in both at the same time.

Sign up to request clarification or add additional context in comments.

3 Comments

Damn joy you got me on autofollow dont you?! You answer all my questions!
@MatthewHarwood, Nop Sir I don't. It's coincidence maybe. :)
Anyway, it would have been the most fruitful form of stalking :]
0

Use setTimeout() like this:

setTimeout(function() {
    $('input[value="Log Out"]').click();
}, 5000);

to execute a function in five seconds.

2 Comments

where would i place this winthin the loop?
You put it whenever you want to start the 5 seconds. I would assume you put it after your for loop finishes executing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.