Twitter プロモリムーバー

Twitterのプロモーションを隠します

当前为 2021-01-07 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitter プロモリムーバー
// @namespace    https://greasyfork.org/ja/users/175598
// @version      21.01.2
// @description  Twitterのプロモーションを隠します
// @author       N.Y.Boyu
// @match        https://twitter.com/*
// @match        https://mobile.twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function(){
    var MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;
    if(MutationObserver)console.log("TPR: Twitter Promotion Remover is enabled.");

    var check=function(){
        var targets=document.body.querySelectorAll('[data-focusable="true"]:not([data-tpr])'),target,elems,i,j,m,n;
        topfor: for(i=0,m=targets.length;i<m;i++){
            target=targets[i];
            elems=target.getElementsByTagName("path");
            for(j=0,n=elems.length;j<n;j++){
                if(elems[j].getAttribute("d")==="M20.75 2H3.25C2.007 2 1 3.007 1 4.25v15.5C1 20.993 2.007 22 3.25 22h17.5c1.243 0 2.25-1.007 2.25-2.25V4.25C23 3.007 21.993 2 20.75 2zM17.5 13.504c0 .483-.392.875-.875.875s-.875-.393-.875-.876V9.967l-7.547 7.546c-.17.17-.395.256-.62.256s-.447-.086-.618-.257c-.342-.342-.342-.896 0-1.237l7.547-7.547h-3.54c-.482 0-.874-.393-.874-.876s.392-.875.875-.875h5.65c.483 0 .875.39.875.874v5.65z"){
                    console.log("TPR: First Hit");
                    target.dataset.tpr="detected";continue topfor;
                }
            }
            if(n>0){ //When exist <path> (<svg>)
                elems=target.querySelectorAll('div:last-child>svg[viewBox="0 0 24 24"]:first-child+:last-child>span:first-child:last-child,div:last-child>svg[viewBox="0 0 24 24"]:first-child+:last-child>span:first-child~span:last-child');
//div:last-child > svg[viewBox="0 0 24 24"]:first-child + :last-child > span:first-child:last-child,
//div:last-child > svg[viewBox="0 0 24 24"]:first-child + :last-child > span:first-child ~ span:last-child //with emoji pattern
                for(j=0,n=elems.length;j<n;j++){
                    if(elems[j].textContent.slice(-7)==="プロモーション"){
                        console.log("TPR: Second Hit");
                        target.dataset.tpr="detected";continue topfor;
                    }
                }
            }
            target.dataset.tpr="checked";
        }
    };

    new MutationObserver(check).observe(document.body,{childList:true,subtree:true});
    check();

    var style=document.createElement("style");
    style.textContent='[data-focusable="true"][data-tpr="detected"]{ display:none!important; }';
    document.body.appendChild(style);
})();