Last Updated: February 25, 2016
·
1.525K
· ivanca

Hide button for twitter

hide button in 'more' menu
Snippet to use with Control Freak or any other way to inject Javascript every time you open Twitter.

// ==UserScript==
// @name       Twitter STFO
// @namespace  http://twitter.com/ivanca
// @version    0.8
// @description  Delete button for individual annoying tweets you hate to read again!
// @match      https://twitter.com/*
// @copyright  2012+, You
// ==/UserScript==

(function () {

    var w = window.unsafeWindow ? unsafeWindow : window.top;
    var $ = w.$;

    if(w.$){
        $(ini);
    } else {        
        Object.defineProperty(w, "jQuery", {
            _this: null,
            get: function() {
                return this._this;
            },
            set: function(val) {
                this._this = val;
                $ = val;
                ini();
            }
        });   
    }

    function ini(){
        w.hideThis = function (btn) {
            var $tweet = $(btn).closest(".js-stream-item");
            $tweet.hide();
            localStorage[ns] += $tweet.attr("data-item-id") + ",";
            return false;
        };

        var ns = "deletedBy" + ($(".account-summary").find("[data-user-id]").attr("data-user-id") || -1);
        localStorage[ns] = localStorage[ns] || "";
        var deleted = localStorage[ns].split(",");

        if (deleted.length > 200) {
            localStorage[ns] = deleted.splice(-200).join(",");
        }

        var ruleNs = '#stream-item-tweet-';
        $("head").append('<style>' + ruleNs + deleted.join(',' + ruleNs) + '{ display:none !important; }</style>');
        ruleNs = '#stream-item-activity-';
        $("head").append('<style>' + ruleNs + deleted.join(',' + ruleNs) + '{ display:none !important; }</style>');

        var btn = '<li class="hide-stream"><a class="js-hide-tweet" onClick="hideThis(this)" href="#" data-nav="hide_tweet" title="Hide Tweet">Hide Tweet</a></li>';

        $("body").on("mouseover", ".dropdown-toggle", function () {
            var $tweet = $(this).closest(".js-stream-item");
            $tweet.not(":has(.hide-stream)").find(".dropdown-menu").append(btn);
        });
    }

})();

1 Response
Add your response

Sweet. The code works with Greasemonkey using @grant none.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside