Login reminder popup remover

Removes the nagging login popups and banners in mobile and desktop versions of Facebook, Instagram, Reddit and Twitter, and in the mobile version of Youtube.

// ==UserScript==
// @name        Login reminder popup remover
// @namespace   StephenP
// @description Removes the nagging login popups and banners in mobile and desktop versions of Facebook, Instagram, Reddit and Twitter, and in the mobile version of Youtube.
// @match     https://*.facebook.com/*
// @exclude   https://developers.facebook.com/*
// @exclude   https://www.instagram.com/accounts/login/*
// @match     https://www.instagram.com/*
// @match     https://m.youtube.com/*
// @match     https://www.reddit.com/*
// @match     https://twitter.com/*
// @match     https://mobile.twitter.com/*
// @version   1.5.2
// @grant     none
// @icon			data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAAG1BMVEXTrvFOWZTEN4aXQ6vcRGPsbUH2sVjlt7/////5Q3C9AAAAAXRSTlMAQObYZgAAANJJREFUKM+9z7EKwjAQgOFIqbPFpXMUmlHMoKsQsKtgsC9g3WMkWS2V3GN7SZrQwdl/68fdlRBCFtWac74jqYLHsvBUHjiA75lGCm6dMca6BPzg9hSzajPBcQjfbKAJFLXgTJOBqQYMqAx7pnCaDRko060W5xGhwlZk20Y4R6iIaHU3inYG3euGR3UG2b0k/lYg1AABPhLDTQoRbs7D1SYoJcTHCQZvf6PsH+H5GiEcJb0Pd0Q9wdLDXV5PdVyZRF7CYgDMz/6E9xyqdPR/sMiw+gKZRGTvTIJM4gAAAABJRU5ErkJggg==
// ==/UserScript==
var interval_0;
var interval_1;
var interval_3;
var interval_4;
(function(){
  //startCheck();
  window.onpopstate = startCheck();
})();
function isMobile(site){
  /*switch (site){
    'ig':
      if(document.getElementsByClassName("XTCLo").length>0){//check if search bar is shown
        if(document.getElementsByClassName("XTCLo")[0].style.display!="none"){
          return false;
        }
      }
      return true;
    'tw':
      if(document.getElementsByClassName("XTCLo").length>0){//check if search bar is shown
        if(document.getElementsByClassName("XTCLo")[0].style.display!="none"){
          return false;
        }
      }
      return true;
  }*/
}
function startCheck(){
 interval_4=setInterval(check,500);
}
function check(){
  if((document.getElementsByTagName("BUTTON").length>0)||(document.getElementsByTagName("FORM").length>0)){//If buttons are there, the page should have loaded. At least that's what I see...
    clearInterval(interval_4);
    if(document.location.href.includes("facebook.com")){
      interval_0=setInterval(blockPopupFB,500);
    }
    else if(document.location.href.includes("instagram.com")){
      if(isMobile("ig")){
        console.log("is mobile");
        //interval_1=setInterval(blockBannerIG,500);
        document.getElementsByTagName('head')[0].innerHTML+='<style>.RnEpo{display: none !important} .xZ2Xk{display: none !important} .tHaIX{display: none !important} body{overflow-y: scroll !important}</style>';
        //interval_2=setInterval(blockPopupIG,500);
        interval_3=setInterval(removeRelatedAccounts,500);
        addSearchBar();//sometimes might even work, Instagram design changhes every fucking minute...
      }
      else{
        console.log("is desktop");
        //interval_1=setInterval(blockBannerIG,200);
        document.getElementsByTagName('head')[0].innerHTML+='<style>.RnEpo{display: none !important} .xZ2Xk{display: none !important} .tHaIX{display: none !important} body{overflow-y: scroll !important}</style>';
        //interval_2=setInterval(blockPopupIG,200);
        interval_3=setInterval(removeRelatedAccounts,200);
        setInterval(removePicturePopup,500);
      }
    }
    else if(document.location.href.includes("m.youtube.com")){
      blockPopupYTM();
    }
    else if(document.location.href.includes("//twitter.com")){
      blockBannerTW('d');
    }
    else if(document.location.href.includes("mobile.twitter.com")){
      blockBannerTW('m');
    }
    else if(document.location.href.includes("reddit.com")){//reddit has a wide range of different login reminders for installing the app or logging in when browsing from a phone
      document.getElementsByTagName('head')[0].innerHTML+='<style>.xPromoChoiceBanner {display: none !important} .XPromoPill {display: none !important} .XPromoPopup{display: none !important} .GetAppFooter{display: none !important} .XPromoInFeed {display: none !important} .PreviewDrawer{display: none !important} .NavFrame{overflow-y: scroll !important}</style>';
      enableScrollingReddit();
    }
  }
  else{
    console.log("still non buttons");
  }
}
function addSearchBar(){
  var sb=document.getElementsByClassName("coreSpriteSearchIcon");
  do{
    sb=sb.parentNode;
  }
  while(sb.style.display!="none")
  sb.style.display="block";
}
function blockPopupFB(){
  var popupFB;
  var loc=document.location.href;
  if((loc.includes("m.facebook.com"))||(loc.includes("iphone.facebook.com"))||(loc.includes("x.facebook.com"))){
    popupFB=document.getElementById("popup_xout").parentNode.parentNode.parentNode;    
	}
  else{
    popupFB=document.getElementById("pagelet_growth_expanding_cta");
  }
  if(popupFB==undefined){
    popupFB=document.getElementsByClassName("_5hn6")[0];
  }
  if(popupFB!==undefined){
    popupFB.parentNode.removeChild(popupFB);
    clearInterval(interval_0);
  }
}
function removeRelatedAccounts(){
  var closeButtons=document.getElementsByClassName("fUzmR");
  if(closeButtons.length>0){
    for(var i=0;i<closeButtons.length;i++){
      closeButtons[i].click();
    }
    clearInterval(interval_3);
  }
}
function removePicturePopup(){
  console.log("removing picture popup");
  if(!document.location.href.includes("/p/")){
    var photoLinks=document.getElementsByClassName("v1Nh3");
    for(var i=0;i<photoLinks.length;i++){
      if(photoLinks[i].getAttribute("class").includes("repaired")===false){
        if(photoLinks[i].getElementsByTagName("IMG")[0].getAttribute("src")!==null){
          var cln = photoLinks[i].children[0].cloneNode(true);
          photoLinks[i].removeChild(photoLinks[i].children[0]);
          photoLinks[i].appendChild(cln);
          photoLinks[i].setAttribute("class",(photoLinks[i].getAttribute("class")+" repaired"));
          photoLinks[i].children[0].setAttribute("target","_blank");
          photoLinks[i].children[0].setAttribute("rel","noopener noreferrer");
          photoLinks[i].children[0].children[0].children[0].children[0].style.visibility="visible";
        }
      }
    }
  }
}

/*function blockPopupIG(){ //kept for reference
  if(document.getElementsByClassName("RnEpo")[0]!==undefined){
    setScrollable();
  }
}*/
/*function setScrollable(){ //kept for reference
  document.body.style.overflow = "scroll !important";
}*/
function blockBannerTW(s){
  if(s=='d'){
  	document.getElementsByClassName("css-1dbjc4n r-16y2uox r-1n0xq6e")[0].parentNode.parentNode.parentNode.parentNode.remove();
  }
  else{
    var banner=document.getElementsByClassName("css-1dbjc4n r-1awozwy r-1pz39u2 r-18u37iz r-16y2uox")[0].parentNode;
    if(banner!=='undefined'){
      banner.parentNode.style.height="53px";
      banner.remove();
    }
    banner=document.getElementsByClassName("css-1dbjc4n r-urgr8i r-97e31f")[0];
    if(banner!=='undefined'){
      banner.remove();
    }
  }
}
function blockPopupYTM(){
  /*if(document.getElementsByClassName("upsell-dialog-lightbox")[0]!==undefined){ //kept for possible future use
    //document.getElementsByClassName("upsell-dialog-lightbox")[0].remove();
    try{
      document.body.removeAttribute("modal-open-body");
    }
    catch(err){}
  }*/
  document.getElementsByTagName('head')[0].innerHTML+='<style>.upsell-dialog-lightbox{display: none !important} [modal-open-body]{position: inherit !important}</style>';
}
function enableScrollingReddit(){
  const body=document.body;
  const config = { attributes: true, childList: false, subtree: false };
  const callback = function(mutationsList, observer) {
    for(const mutation of mutationsList) {
      if (mutation.type === 'attributes') {
        observer.disconnect();
        body.classList.remove("scroll-disabled");
        observer.observe(body, config);
      }
    }
  };
    const bodyObserver = new MutationObserver(callback);
  bodyObserver.observe(body, config);
}