Fortunately, I know the script works. The problems comes about that $('input[value="Log Out"]').click(); Logout is too slow and gets overridden by the window redirect. How can I add an additional time out or what would the community suggest to make this process less volatile?
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();
}
setTimeout(function() {
$('input[value="Log Out"]').click();
window.location.href = "https://www.facebook.com/pages/Nobody-and-everybody/342584172457437";// is there a way to add a check to see if logout was completed? if not, how would I add just another setTimeout();?
}, 5000);
}
$(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) {
/*var setText = $('input[value="Search for people, places and things"]').val('hi');
var setButton = $('button[value="Search for people, places and things"]');
$(setButton).click();*/
likeMe()
return false;
}
}
Creating a project using arduino, processing, javascript/jquery, greasemonkey and facebook.
Art installation.
The problem is that the logout loads a new page, so that if you wait for it, the redirect will never fire (because the page — that the code was running in — is gone)1.
So, that means that the script has to track login and desired-redirect state between pages. One way to do that is with GM_setValue().
To illustrate, here is a complete script that shows how to logout and then redirect.
In this case, it adds a button to the top-right corner of Facebook pages. When pressed, the button (1) Logs you out, (2) Waits for the logout to finish, (3) Redirects to a new page.
1 Newfangled pages — where the logout triggers just a partial AJAX content change — don’t have this problem. But as that is not the case here, it is for another time/question.