🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Twitter: hide promoted tweets

Hide promoted tweets

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Twitter: hide promoted tweets
// @name:fr      Twitter : masque les tweets sponsorisés
// @namespace    http://tampermonkey.net/
// @version      0.3.0
// @description  Hide promoted tweets
// @description:fr  Masque les tweets sponsorisés
// @author       Darth Obvious
// @match       *://twitter.com/*
// @match       *://*.twitter.com/*
// @license MIT
// @grant        none
// ==/UserScript==
(function() {
    "use strict";
    let count_hidden = 0;
    const promoted_texts = ["Ad", "Promoted", "Gesponsert", "Promocionado", "Sponsorisé", "Sponsorizzato", "Promowane", "Promovido", "Реклама", "Uitgelicht", "Sponsorlu", "Promotert", "Promoveret", "Sponsrad", "Mainostettu", "Sponzorováno", "Promovat", "Ajánlott", "Προωθημένο", "Dipromosikan", "Được quảng bá", "推廣", "推广", "推薦", "推荐", "プロモーション", "프로모션", "ประชาสัมพันธ์", "प्रचारित", "বিজ্ঞাপিত", "تشہیر شدہ", "مُروَّج", "تبلیغی", "מקודם"];
    function hide_promoted(){
        // Select all <article> not processed
        const unprocessedArticles = document.querySelectorAll('article:not([data-processed])');

        // Loop on all articles
        unprocessedArticles.forEach(article => {
            article.setAttribute('data-processed', 'true');
            // Search all divs
            const divs = article.querySelectorAll('div');

            // Test if a div contains only the "promoted" text
            let containsAd = false;
            divs.forEach(div => {
                const spans = div.querySelectorAll('span');
                spans.forEach(span => {
                    if (promoted_texts.includes(span.textContent.trim())) {
                        containsAd = true;
                    }
                });
            });

            // If it looks like a promoted tweet, it's hidden
            if (containsAd) {
                article.style.display = 'none';
                count_hidden += 1;
                console.log("Promoted tweet hidden (" + count_hidden + ")");
            }
        });
    }


    // MutationObserver to observe changes in <body>
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            mutation.addedNodes.forEach(function(node) {
                // Is this node a <div>?
                if (node instanceof HTMLDivElement) {
                    // Check all children of the <div> to find <article> tags
                    const articlesInDiv = node.querySelectorAll('article');
                    if (articlesInDiv.length > 0) {
                        hide_promoted();
                    }
                }
            });
        });
    });

    // Observer for changes in <body>
    const observerConfig = { childList: true, subtree: true };
    observer.observe(document.body, observerConfig);
})();