[英]Triggering a logout and redirect using jQuery
幸運的是,我知道腳本可以工作。 問題來自於$('input[value="Log Out"]').click();
注銷太慢,並且會被窗口重定向覆蓋。 如何增加額外的超時時間,或者社區會建議些什么來減少此過程的波動性?
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;
}
}
使用arduino,處理,javascript / jquery,油脂猴子和Facebook創建項目。 藝術品安裝。
問題是注銷將加載一個新頁面,因此,如果您等待它,則重定向將永遠不會觸發(因為該頁面(運行代碼的頁面已消失)) 1 。
因此,這意味着腳本必須跟蹤頁面之間的登錄和所需重定向狀態。 一種方法是使用GM_setValue() 。
為了說明這一點,下面是一個完整的腳本,該腳本顯示了如何注銷然后重定向。
在這種情況下,它將在Facebook頁面的右上角添加一個按鈕。 按下后,按鈕(1)注銷您,(2)等待注銷完成,(3)重定向到新頁面。
// ==UserScript==
// @name _Logout and Redirect
// @include http://www.facebook.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// ==/UserScript==
//--- Are we on a log-in page and has a redirect been requested?
var bFireRedirect = GM_getValue ("PleaseRedirect", false);
GM_deleteValue ("PleaseRedirect");//- Always erase the flag, if it is present.
if (bFireRedirect && $("#login_form #loginbutton").length) {
//--- We've just come from our auto-logout. Redirect.
window.location = "http://dogs.icanhascheezburger.com/"
}
//--- We only get this far if no redirect occurred.
$("body").append (
'<button id="gmLogOutAndRedirectBtn">Logout and redirect</button>'
);
$("#gmLogOutAndRedirectBtn").click ( function () {
GM_setValue ("PleaseRedirect", true);
$('input[value="Log Out"]').click ();
} );
GM_addStyle ( (<><![CDATA[
#gmLogOutAndRedirectBtn {
margin: 1 ex;
position: fixed;
top: 0;
right: 0;
z-index: 888;
}
]]></>).toString () );
1個新頁面-注銷僅觸發部分AJAX內容更改-沒有這個問題。 但這不是事實,這是另一個時間/問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.