Fix Elon's Folly

Removes the Views counter & Analytics icon from tweets.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Fix Elon's Folly
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Removes the Views counter & Analytics icon from tweets.
// @author       ThriceGreatAlex
// @match        *://twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const callback = function(mutationsList, observer) {
        for (let mutation of mutationsList) {
            const views = Array.from(
                document.body.querySelectorAll('span')
            ).filter(
                x => {
                    var y = x.textContent.toLowerCase()
                    return y.startsWith('view') && !y.startsWith('view ')
                }
            );
            views.forEach(
                x => x.parentElement.parentElement.parentElement.remove()
            );
            const analytics = Array.from(
                document.body.querySelectorAll(
                    "path[d='M8.75 21V3h2v18h-2zM18 21V8.5h2V21h-2zM4 21l.004-10h2L6 21H4zm9.248 0v-7h2v7h-2z']"
                )
            )
            analytics.forEach(
                x => {
                    var y = x.parentElement.parentElement.parentElement.parentElement
                    if (y.textContent.toLowerCase() !== 'view tweet analytics') {
                        y.parentElement.parentElement.remove()
                    }
                }
            )
        }
    }

    const observer = new MutationObserver(callback);
    observer.observe(
        document.querySelector('body'),
        { attributes: true, childList: true, subtree: true }
    );

})();