facebook logout new facebook

pulsante logout facebook

// ==UserScript==
// @name          facebook logout new facebook
// @description   pulsante logout facebook
// @author        figuccio
// @version       0.9
// @namespace     https://greasyfork.org/users/237458
// @match         https://*.facebook.com/*
// @noframes
// @grant         GM_addStyle
// @icon          https://facebook.com/favicon.ico
// @require       https://greasyfork.org/scripts/12228/code/setMutationHandler.js
// @license        MIT
// ==/UserScript==
window.addEventListener('load', function() {
        // Attendi che la pagina si carichi completamente
        setTimeout(NEWaddtopnavbarlogoutbutt, 100); // Regola il ritardo se necessario
    });
////////////////////////////////////////logout
function NEWaddtopnavbarlogoutbutt(){
    console.log('addtopnavbarlogoutbutt');
  if(document.querySelectorAll('div[role="banner"] div[role="navigation"]').length!=2) {
    console.log("Didn't find insert point for logout button");
	return;
  }

  var logoutlink=document.createElement('a');
  logoutlink.innerHTML="&nbsp;Log<br/>&nbsp;Out&nbsp;";
  logoutlink.href="";
  logoutlink.title = 'esci';
  logoutlink.id="fbpLogoutLink";
  logoutlink.style="text-decoration: none;margin-left:7px;color:var(--primary-text);position:relative;left:8px;background-color:var(--secondary-button-background);font-weight:700;padding-left: 4px;padding-right: 4px;padding-top: 4px; padding-bottom: 4px; leftmargin:15px;border-top-left-radius: 50%;border-bottom-left-radius: 50%;border-top-right-radius: 50%;border-bottom-right-radius: 50%;";

  document.querySelectorAll('div[role="banner"] div[role="navigation"]')[1].firstChild.parentNode.insertBefore(logoutlink,document.querySelectorAll('div[role="banner"] div[role="navigation"]')[1].firstChild);

  logoutlink.addEventListener("click", function(e) {e.preventDefault(); document.querySelector('form[action^="/logout.php?"').submit(); e.target.innerHTML='<img src="//www.facebook.com/images/loaders/indicator_blue_small.gif"/>'},false);

}

function addtopnavbarlogoutbutt(){
    console.log('addtopnavbarlogoutbutt');
  if(document.getElementById('logout_form2')) // logout button has already been added, must be another version of fbp running?
    return;
  if(!document.getElementById('temp_logout_butt')) { //create a temporary logout button, to ease icons in navbar jumping around
    var temp_logout_butt=document.createElement("form");
	temp_logout_butt.style.left="10px";
	temp_logout_butt.id="temp_logout_butt";
	var tmplogoutli=document.createElement('div');
	tmplogoutli.setAttribute('style',"position:relative;top:5px"); //float:right
	tmplogoutli.appendChild(temp_logout_butt);
	var tmpsubbutt=document.createElement('input');
	tmpsubbutt.setAttribute('type','submit');
	tmpsubbutt.setAttribute('value','Log Out');
	tmpsubbutt.style.border="0";
	tmpsubbutt.setAttribute('class','_2s25');
	temp_logout_butt.appendChild(tmpsubbutt);
	temp_logout_butt.style.visibility='hidden';
	if(document.querySelector('#blueBarDOMInspector div[role="navigation"]')) {
	  var tmplogoutinpoint=document.querySelector('#blueBarDOMInspector div[role="navigation"]');
	  tmplogoutinpoint.appendChild(temp_logout_butt);
	}
  }
  var newlogoutbutt, subbutt, logoutli;
  if(document.getElementById('pageLoginAnchor')) {
    document.getElementById('pageLoginAnchor').click(); // open menu
	document.getElementById('pageLoginAnchor').click(); // close menu

	if(!document.querySelector('div.uiContextualLayerPositioner[data-ownerid="pageLoginAnchor"]')) {
	  console.log('couldnt find fb settings menu anchor');
	  window.setTimeout(addtopnavbarlogoutbutt,25000);
	  return;
	}

	var waitforlobcount=0; //lob = log out button
	var waitforlob=window.setInterval(function(){
	  if (waitforlobcount<=15) {
	    waitforlobcount+=1;
		  console.log("logoutbutton check count=" +waitforlobcount);
        if(document.querySelector('form[action^="https://www.facebook.com/login/device-based/regular/logout/"]')) {  //('form[action^="https://www.facebook.com/logout.php"]')) {
          newlogoutbutt=document.querySelector('form[action^="https://www.facebook.com/login/device-based/regular/logout/"]').cloneNode(true);   //('form[action^="https://www.facebook.com/logout.php"]').cloneNode(true);
		  window.clearInterval(waitforlob);
	    }
	    else {
		  console.log('Logout button not found...');
		  return;
	    }
	    newlogoutbutt.setAttribute('style',"position:relative;top:4px;left:10px");
        newlogoutbutt.setAttribute('id','logout_form2');
	    logoutli=document.createElement('div');
	    logoutli.setAttribute('style',"position:relative;top:5px"); //float:right
	    logoutli.appendChild(newlogoutbutt);
	    var subbutt=document.createElement('input');
	    subbutt.setAttribute('type','submit');
	    subbutt.setAttribute('value','Log Out');
        subbutt.style.color='#FFF';
	    subbutt.style.border="0";
		subbutt.setAttribute('class','_2s25');
	    subbutt.style.backgroundColor="transparent";
	    newlogoutbutt.appendChild(subbutt);
	    if(document.querySelector('#blueBarDOMInspector ul[role="navigation"]')) {
		  var logoutinpoint=document.querySelector('#blueBarDOMInspector ul[role="navigation"]').firstChild;
		  logoutli.setAttribute('style',"float:right");
          logoutinpoint.parentNode.insertBefore(logoutli, logoutinpoint);
	    }
		else if(document.querySelector('#blueBarDOMInspector div[role="navigation"]')) {
		  var logoutinpoint=document.querySelector('#blueBarDOMInspector div[role="navigation"]');
		  logoutli.setAttribute('style',"position:relative;top:3px");
		  if(document.getElementById('temp_logout_butt'))
			document.getElementById('temp_logout_butt').parentNode.removeChild(document.getElementById('temp_logout_butt'));
		  logoutinpoint.appendChild(logoutli);
	    }
		else
		  console.log('didnt find the navigation bar div, so couldnt insert logout button');
     }
	 else
	   window.clearInterval(waitforlob);
    }, 1000);
  }
  else {
    console.log('didnt find the logout link');
  }
}
window.setTimeout(addtopnavbarlogoutbutt,7000);