netuoso / Hide Resteemed Posts on Steem Blog Page

// ==UserScript==
// @name         Hide Resteemed Posts on Steem Blog Page
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Hide resteemed posts on SteemIt.com
// @author       netuoso
// @match        https://steemit.com/*
// @grant        WTFPL
// ==/UserScript==

function hideResteemedPosts() {
    // Get all resteemed posts
    var elements = document.getElementsByClassName("PostSummary__reblogged_by");
    // Loop over the posts and hide the entire post if it is a resteemed post
    for (var i=0; i<elements.length; i++) {
        elements[i].parentElement.parentElement.style.display="none";
    }
}

function showResteemedPosts() {
    // Get all posts
    var elements = document.getElementsByClassName("PostSummary");
    var footerElements = document.getElementsByClassName("PostSummary__footer");
    // Loop over the posts and unhide them
    for (var i=0; i<elements.length; i++) {
        elements[i].parentElement.style.display="list-item";
        footerElements[i].style.display = "list-item";
    }
}

function toggleAutoFilter(setting) {
    if (setting == "enable" ) {
        hideResteemedPosts();
        document.getElementById("enableResteemedFilterLink").style.display = "none";
        document.getElementById("disabledResteemedFilterLink").style.display = "inline-block";

        // Enable auto filtering
        document.getElementsByClassName("PostsList__summaries")[0].addEventListener("DOMNodeInserted", function(event) {
            hideResteemedPosts();
        });
    } else {
        showResteemedPosts();
        document.getElementById("disabledResteemedFilterLink").style.display = "none";
        document.getElementById("enableResteemedFilterLink").style.display = "inline-block";

        // Disable auto filtering
        // Enable auto filtering
        document.getElementsByClassName("PostsList__summaries")[0].addEventListener("DOMNodeInserted", function(event) {
            showResteemedPosts();
        });
    }
}

/*--- Note, gmMain () will fire under all these conditions:
    1) The page initially loads or does an HTML reload (F5, etc.).
    2) The scheme, host, or port change.  These all cause the browser to
       load a fresh page.
    3) AJAX changes the URL (even if it does not trigger a new HTML load).
*/
var fireOnHashChangesToo    = true;
var pageURLCheckTimer       = setInterval (
    function () {
        if ( this.lastPathStr  !== location.pathname || this.lastQueryStr !== location.search || (fireOnHashChangesToo && this.lastHashStr !== location.hash) ) {
            this.lastPathStr  = location.pathname;
            this.lastQueryStr = location.search;
            this.lastHashStr  = location.hash;
            gmMain ();
        }
    }, 111
);

function gmMain () {
    // Create a button called "Hide Resteemed Posts"
    var enableWrapper = document.createElement("li");
    enableWrapper.id = "enableResteemedFilterLink";
    enableWrapper.className = "resteemedScript";
    var enableLink = document.createElement("a");
    enableLink.innerHTML = "hide resteemed posts";
    enableLink.onclick = function() { toggleAutoFilter("enable"); };
    enableLink.style.pointer = "cursor";
    enableWrapper.appendChild(enableLink);

    // Create a button called "Hide Resteemed Posts"
    var disableWrapper = document.createElement("li");
    disableWrapper.id = "disabledResteemedFilterLink";
    disableWrapper.className = "resteemedScript";
    var disableLink = document.createElement("a");
    disableLink.innerHTML = "show resteemed posts";
    disableLink.onclick = function() { toggleAutoFilter("disable"); };
    disableLink.style.pointer = "cursor";
    disableWrapper.appendChild(disableLink);
    disableWrapper.style.display = "none";

    try {
        // Append the link to the navigation bar on the top of the screen
        if (window.location.href.indexOf("@") > 0 && window.location.href.indexOf("feed") < 0) {
            if (document.getElementsByClassName("resteemedScript").length === 0) {
                document.getElementsByClassName('HorizontalMenu')[0].appendChild(enableWrapper);
                document.getElementsByClassName('HorizontalMenu')[0].appendChild(disableWrapper);
            } else {
                document.getElementsByClassName("resteemedScript")[0].style.display = "inline-block";
            }
        } else {
            if (document.getElementsByClassName("resteemedScript").length > 0) {
                for (i=0;document.getElementsByClassName("resteemedScript").length;i++) {
                    document.getElementsByClassName("resteemedScript")[i].style.display = "none";
                }
            }
        }
    } catch (e) {}
}