felzsirostej / facebook-crap-remover

// ==UserScript==
// @name         facebook-crap-remover
// @namespace    https://openuserjs.org/scripts/felzsirostej/
// @version      0.0.2
// @description  removes some crap from facebook
// @author       felzsirostej
// @match        https://www.facebook.com/*
// @grant        none
// @updateURL https://openuserjs.org/meta/felzsirostej/facebook-crap-remover.meta.js
// @downloadURL https://openuserjs.org/src/scripts/felzsirostej/facebook-crap-remover.user.js
// ==/UserScript==

//updated version2


(function() {
    'use strict';

    var suggestedPostLocals = ["Javasolt bejegyzés", "Suggested Post", "Vorgeschlagener Beitrag", "Publicación sugerida", "Publicação sugerida", "Navrhovaný příspěvek", "Navrhovaný príspevok", "Voorgesteld bericht"];

    //searches for crap
    function crapSearcher(crapText, crapTag) {
        var crapElements = document.getElementsByTagName(crapTag);
        var found = [];

        for (var i = 0; i < crapElements.length; i++) {
            if (crapText.includes(crapElements[i].textContent)) {
                found.push(crapElements[i]);
            }
        }

        return found;
    }

    //removes some crap
    function removeCrap() {
        var suggestedCrap = crapSearcher(suggestedPostLocals,"span");
        suggestedCrap.forEach(function(item){
            try { item.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none"; }catch(err) {console.log("nincse");}
        });

        try { document.getElementById("pagelet_canvas_nav_content").style.display = "none";     }catch(err) {console.log("nincse");}
        try { document.getElementById("pagelet_instant_games_rhc").style.display = "none";     }catch(err) {console.log("nincse");}
        try { document.getElementById("pagelet_ego_pane").style.display = "none";     }catch(err) {console.log("nincse");}
        try { document.getElementById("pagelet_ego_contextual_group").style.display = "none";     }catch(err) {console.log("nincse");}
        try { document.getElementById("pagelet_composer").style.display = "none";     }catch(err) {console.log("nincse");}
        try { document.getElementById("appsNav").style.display = "none";     }catch(err) {console.log("nincse");}
    }

    window.onload = function() {
        removeCrap();
    };

    window.onscroll = function(){
        setTimeout(function(){
            removeCrap();
        }, 300);
    };


})();