Twitter Promotion Filter

Hides promotion on twitter

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Twitter Promotion Filter
// @name:ja      Twitterプロモーションフィルター
// @namespace    https://greasyfork.org/ja/users/175598
// @version      23.03.1
// @description  Hides promotion on twitter
// @description:ja 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("TPF: Twitter Promotion Filter is enabled.");

    var style=document.createElement("style");
    style.textContent='[tabindex="0"][data-testid][tpf-checked="hidden"]{ display:none!important; }';
    document.head.appendChild(style);

    var root=document.getElementById("react-root")||document.body;
    var check=function(){
        var targets=root.querySelectorAll('[tabindex="0"][data-testid]:not([tpf-checked])'),elems,i,j,m,n;
        topfor: for(i=0,m=targets.length;i<m;i++){
            elems=targets[i].getElementsByTagName("path");
            for(j=0,n=elems.length;j<n;j++){
                if(elems[j].getAttribute("d")==="M19.498 3h-15c-1.381 0-2.5 1.12-2.5 2.5v13c0 1.38 1.119 2.5 2.5 2.5h15c1.381 0 2.5-1.12 2.5-2.5v-13c0-1.38-1.119-2.5-2.5-2.5zm-3.502 12h-2v-3.59l-5.293 5.3-1.414-1.42L12.581 10H8.996V8h7v7z"){
                    console.log("TPF: Hit "+targets[i].dataset.testid);
                    targets[i].setAttribute("tpf-checked","hidden");
                    continue topfor;
                }
            }
            /*
            elems=targets[i].querySelectorAll('div:last-child > svg[viewBox="0 0 24 24"]:first-child + :last-child > span:last-child'); //Change here for other language (e.g. '(...) > span:first-child' for English)
            for(j=0,n=elems.length;j<n;j++){
                if(elems[j].textContent.slice(-7)==="プロモーション"){ //Change here for other language (e.g. slice(0,8)==="Promoted" for English)
                    console.log("TPF: Hit");
                    targets[i].parentNode.removeChild(targets[i]);
                    continue topfor;
                }
            }
            */
            targets[i].setAttribute("tpf-checked","");
        }
    };
    new MutationObserver(check).observe(root,{childList:true,subtree:true});
    check();
})();