TweetDeck User-Column Replies Filter

Hides (not retweet or thread) replies in user-column.

当前为 2021-05-28 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         TweetDeck User-Column Replies Filter
// @name:ja      TweetDeck Userカラム リプライフィルター
// @namespace    https://greasyfork.org/users/175598
// @version      1.0
// @description  Hides (not retweet or thread) replies in user-column.
// @description:ja Userカラム内の(リツイートやスレッドではない)リプライを隠します
// @author       N.Y.Boyu
// @match        https://tweetdeck.twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==
(function(){
    var MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;
    var init,columnCheck,chirpCheck;

    var yourUserName="";
    //NOTE: If put your user name, hides your tweet/retweet in home-column.

    init=function(){
        var style,app,observer,init2;
        style=document.createElement("style");
        style.textContent='article[drf-removed]{ position:absolute; z-index:-1; }';
        document.head.appendChild(style);
        app=document.getElementsByClassName("application")[0];
        init2=function(){
            if(app.className==="application js-app is-condensed"){
                observer.disconnect();
                var cols=app.getElementsByClassName("app-columns")[0];
                new MutationObserver(columnCheck).observe(cols,{childList:true});
                columnCheck([{addedNodes:cols.children}]);
            }
        };
        (observer=new MutationObserver(init2)).observe(app,{attributes:true,attributeFilter:["class"]});
        init2();
    };

    columnCheck=function(recs){
        for(var i=0;i<recs.length;i++){for(var j=0;j<recs[i].addedNodes.length;j++){
            var target=recs[i].addedNodes[j];
            if(target.dataset.column&&!target.drfColumnMarked){
                target.drfColumnMarked=true;
                var chirps=target.getElementsByClassName("chirp-container")[0];
                chirps.type=target.getElementsByClassName("column-type-icon")[0].className.split("icon-")[1];
                new MutationObserver(chirpCheck).observe(chirps,{childList:true});
                chirpCheck([{addedNodes:chirps.children}]);
            }
        }}
    };

    chirpCheck=function(recs){
        var i,j,target,type,isReply,isRetweet,author;
        for(i=0;i<recs.length;i++){for(j=0;j<recs[i].addedNodes.length;j++){
            target=recs[i].addedNodes[j];
            if(!type)type=target.parentNode.type;
            if(!target.dataset.tweetId)break;
            isReply=!!target.querySelector(".tweet-body>.nbfc>.other-replies");
            isRetweet=!!target.querySelector(".tweet-context>.item-img>.icon-retweet-filled");
            if(yourUserName){
                author=isRetweet?target.querySelector('.tweet-context>.nbfc>[rel="user"]').href.slice(20)
                                :target.querySelector(".tweet>header>.account-link").href.slice(20);
            }
            if((type==="user"&&isReply&&!isRetweet)||
               (type==="home"&&yourUserName&&yourUserName===author)){
                console.log("DRF: Hit");
                target.removeChild(target.children[0]);
                target.setAttribute("drf-removed","");
                //DO NOT delete DIRECTLY to avoid bugs.
            }
        }}
    };

    init();
    console.log("DRF: TweetDeck User-Column Replies Filter is enabled.");
})();