facebook recent home e logo

logo facebook e logo home reinderizzano a post recenti

// ==UserScript==
// @name          facebook recent home e logo
// @namespace     https://greasyfork.org/users/237458
// @version       0.5
// @description   logo facebook e logo home reinderizzano a post recenti
// @author        figuccio
// @match         https://*.facebook.com/*
// @grant         GM_addStyle
// @grant         GM_setValue
// @grant         GM_getValue
// @grant         GM_registerMenuCommand
// @icon          https://www.google.com/s2/favicons?domain=facebook.com
// @run-at        document-end
// @license        MIT
// ==/UserScript==
(function() {
    'use strict';
    var CONTENT_HAS_LINKS_SELECTORS = ".userContentWrapper, ._5pcr";
    var BLOCK_LIST_SELECTORS = "._5r69, ._5g-l, ._2r3x, .uiLikePageButton, .uiStreamSponsoredLink";
    var observer;
    var contentAreaFoundTimeout;

    function findAncestor (el, cls) {
        while ((el = el.parentElement) && !el.classList.contains(cls));
        return el;
    }

    function filterPosts(elements) {
        //console.log("filterPosts");
        if(!Array.isArray(elements) && !(elements instanceof NodeList)) {
            return filterPosts([elements]);
        }
        //console.log("elements",elements);
        for (var i = 0; i < elements.length; i++) {
            var element = elements[i];
            var elementDirty = false;
            //console.log("element",element);
            if (element.matches(BLOCK_LIST_SELECTORS) || element.querySelectorAll(BLOCK_LIST_SELECTORS).length>0) {
                elementDirty = true;
            } else {
                var allLinks = element.querySelectorAll('a');
                for (var j = 0; j < allLinks.length; j++) {
                    var str = allLinks[j].getAttribute("href");
                    if (str !== undefined && !str.startsWith("/") && !str.startsWith("#") && !str.includes("www.facebook.com")) {
                        elementDirty = true;
                        break;
                    }
                }
            }

             // mostra solo le voci pertinenti
            if(elementDirty) {
                findAncestor(element, "_4-u2").style.display = "none";

            } else {

            }
        }
    }

    function mutationsHandler(mutations) {
        mutations.forEach(function(mutation) {
            var newNodes = mutation.addedNodes;
            if (newNodes !== null) {
                for (var i = 0; i < newNodes.length; i++) {
                    if (newNodes[i] && newNodes[i].className && (newNodes[i].className.contains("userContentWrapper") || newNodes[i].className.contains("_5pcr"))) {
                        filterPosts(newNodes[i]);
                    } else if (newNodes[i] && newNodes[i].querySelectorAll) {
                        filterPosts(newNodes[i].querySelectorAll(CONTENT_HAS_LINKS_SELECTORS));
                    }
                }
            }
        });
    }

    function setupHistoryStateListener(callback) {
        (function (old) {
            window.history.pushState = function () {
                old.apply(window.history, arguments);
                console.log("push state");
                callback();
            };
        })(window.history.pushState);
    }

    function main() {
        if (window.top != window.self) {
            return;
        }

        if(window.self.location.pathname !== "/") {
            console.log("not on main feed");
            return;
        }

        if(!window.self.location.search) {
            window.self.location.search = "?sk=h_chr";
        }

        var contentArea = document.getElementById("contentArea");
        if(!contentArea) {
            console.log("contentarea not found, retry soon");
            if(contentAreaFoundTimeout) {
                clearTimeout(contentAreaFoundTimeout);
                contentAreaFoundTimeout = null;
            }
            contentAreaFoundTimeout = setTimeout(main, 200);
            return;
        }

        console.log("contentarea found");

        observer.disconnect();
        observer.observe(contentArea, { attributes: false, childList: true, characterData: false, subtree: true });
        filterPosts(document.querySelectorAll(CONTENT_HAS_LINKS_SELECTORS));

        setTimeout(function() {
            document.body.scrollTop = 160;
            contentArea.style.display = "block";
        },100);

    }

    function setup() {
        observer = new MutationObserver(mutationsHandler);

        if (document.readyState === "complete") {
            main();
        } else {
            window.addEventListener("load", main);
        }

        setupHistoryStateListener(function() {
            setTimeout(main,1000);
        });

        var style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML =
            '.home .newsFeedComposer #contentArea { display:none; }'+
        document.getElementsByTagName('head')[0].appendChild(style);
    }

    setup();
})();
//torna ai post piu popolari reinderiza ha topstorie
  // Verifica che l'URL principale sia il più recente
   if (document.URL == "https://www.facebook.com/home.php") window.location.href = "/?sk=h_chr";//log in da google
         // reindirizzamento istantaneo al feed più recente se vengono rilevate le notizie principali
  if( window.location.href.match(/facebook\.com\/?$|\?sk=h_nor|\?sk=nf|\?ref=tn_tnmn|\?ref=logo|\.com\/?_rdr$/) && (!window.location.href.match(/\?sk=h_nor#topstories/))){
	if(!/m.facebook.com/.test(window.location.href))
	  window.location.href="/?sk=h_chr"; //https://www.facebook.com
    else
	  window.location.href="/home.php?sk=h_chr"; }//https://m.facebook.com
//////////////////////////////////////////////////////////////////////////////
function fixbacktotoppostslink() {
// correggi il collegamento alle storie principali per un nuovo design
  var y,x;
  x=document.querySelector('div[role="main"] a[href="/"][aria-label]'); // should now work for all languages
  if(!x){
	if(debug)
	  console.log('didnt find (plain) top stories link');
	return;
  }


    console.log('fixing top stories link');
  x.id="aa";
  y=x.cloneNode(true);
  y.id="topstorieslink";
  y.title="post popolari";
  if(!document.querySelector('#topstorieslink'))
    x.parentNode.insertBefore(y,x.nextSibling);
  document.getElementById("aa").style="display:none !important";
  document.getElementById("topstorieslink").href="/?sk=h_nor#topstories";
  if(x.style && x.style.display=='none')
	 x.style="block";
  x=y=null;
}


function addnewsfeedmenufeeds(){
	// vecchio codice per vecchio design, non più necessario, può eliminare...
    if(debug)
	  console.log('clicked - shows event listener is working');
	  if(document.getElementById('mstorieslink')) {
		if(document.querySelector("div.uiContextualLayerPositioner.hidden_elem #mstorieslink")) {
		  // fix top stories link
		  try{
		    if(document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"])').querySelector('a[href*="?sk=h_nor"]').href)
		      document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"])').querySelector('a[href*="?sk=h_nor"]').href="/?sk=h_nor#topstories";
		  }
		  catch(e){
			  ; //non fare niente in questo momento...
		  }

		  // correggi il menu a discesa del feed nascosto
		  var inpoint=document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"]) a[href*="?sk=h_chr"]');
		  try{
		    inpoint.parentNode.parentNode.insertBefore(document.getElementById('pstorieslink').parentNode, inpoint.parentNode.nextSibling);
			if(document.getElementById("navItem_605397933004645")) // if explore feed exists
			  inpoint.parentNode.parentNode.insertBefore(document.getElementById('estorieslink').parentNode, inpoint.parentNode.nextSibling);
			inpoint.parentNode.parentNode.insertBefore(document.getElementById('gstorieslink').parentNode, inpoint.parentNode.nextSibling);
			inpoint.parentNode.parentNode.insertBefore(document.getElementById('pgstorieslink').parentNode, inpoint.parentNode.nextSibling);
		    inpoint.parentNode.parentNode.insertBefore(document.getElementById('mstorieslink').parentNode, inpoint.parentNode.nextSibling);
		  }
		  catch(e) {
			  ; //niente dovrebbe andare bene?
		  }
		}

		else if (window.location.href.match(/\?sk=h_chr/) || document.querySelector("#contentCol a[href='/?sk=h_nor']")){
		  try {
		    document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"]) a[href*="?sk=h_chr"]').parentNode.className += " _54nd";
		  }
		  catch(e) {;
		    // do nothing
		  }
		}
		else if (window.location.href.match(/\?sk=h_nor/) ){
		  try{
		    document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"]) a[href*="?sk=h_nor"]').parentNode.className += " _54nd";
		  }catch (e) {
			;// fare niente
		  }

		}

	    return;
	   }
	   else {

         var inpointA=document.querySelectorAll('div.uiContextualLayer.uiContextualLayerBelowRight a[href*="?sk=h_chr"]');
         if(!inpointA.length) {
		   console.log('Didnt find the newsfeed feed selector menu, try again in 1 seconds');
		   window.setTimeout(addnewsfeedmenufeeds,3000);//aumentato da 1 a 3secondi
	       return;
         }

/////////////////////////////////////////////////////////////////////////////////////////////////serve
		 // INSERT EXPLORE FEED LINK
		 if(document.getElementById("navItem_605397933004645")) // se esiste il feed di esplorazione
		   insertfeedintonewsfeedselector("estorieslink","Explore Feed","/explore");
//////////////////////////////////////////////////////////////////////////
		if (window.location.href.match(/\?sk=h_chr/) || document.querySelector("#contentCol a[href='/?sk=h_nor']")){ // evidenziare i più recenti
		  try{
		    document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"])').querySelector('li:not([class*="_54nd"]) a[href*="?sk=h_chr"]').parentNode.className+= ' _54nd';
		  }
		  catch(e) {
			; // do nothing
		  }
		}
		else if (window.location.href.match(/\?sk=h_nor/) ){ // evidenziare le storie principali
		  try{
		    document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"])').querySelector('li:not([class*="_54nd"]) a[href*="?sk=h_nor"]').parentNode.className+= ' _54nd';
		  }
		  catch(e) {
			; // fare niente
		  }
		}
		// correggere il collegamento alle storie principali
		if(document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"])') && document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"])').querySelector('a[href*="?sk=h_nor"]').href)
		  document.querySelector('div.uiContextualLayerPositioner:not([class*="hidden_elem"])').querySelector('a[href*="?sk=h_nor"]').href="/?sk=h_nor#topstories";
	   }
	 }
    window.setTimeout(fixbacktotoppostslink,3000);
    window.setTimeout(fixbacktotoppostslink,6000);
    window.setTimeout(fixbacktotoppostslink,8000);
    window.setTimeout(fixbacktotoppostslink,10000);//se la connessione e lenta 1minuto
    GM_registerMenuCommand("mostra popolari",fixbacktotoppostslink);
    window.setTimeout(addnewsfeedmenufeeds,3000);
////////////////////////////////////////////////////////
//nasconde il vecchio torna ai post popolari
 GM_addStyle(' div._4-u2.mvm._495i {position:relative; top:-21px; width:138px; height:10px; overflow:hidden !important; padding :0px; padding-top:1px; padding-bottom:6px; margin-top:0px; margin-bottom:-17px} /*Nascondi il link Torna allinizio dei post(new design) finché non è pronto*/ div[role="main"] a[href="/"][aria-label]{display:none!important;}');
////////////////////////////////////////////////////////////
//title logo facebook e home
(function a() {
	var title=document.querySelectorAll("div[role='banner'] a[role='link'][href='/'],div[role='banner']+div[data-isanimatedlayout] a[role='link'][href='/']");
	if(title && title.length>1)

    title=document.querySelectorAll("a[role='link'][href='/']");
	if(title && title.length>1)
	  for(i=0;i<3;i++){
	    title[i].title="Most Recent"
	  }

////////////////////////////////////////////////////////////
window.setTimeout(a,6000);
  })();