Twitter - Hide Retweet

Support 2019 new UI Twitter only.

目前為 2019-06-14 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitter - Hide Retweet
// @version      1.0.1
// @description  Support 2019 new UI Twitter only.
// @author       Hayao-Gai
// @namespace	 https://github.com/HayaoGai
// @icon         https://i.imgur.com/M9oO8K9.png
// @include      https://twitter.com/*
// @require      http://code.jquery.com/jquery-3.4.1.slim.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const $ = window.jQuery;

    // 觀察文件是否產生變化
    waitLoaded(); //等待文件讀取
    const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; //前綴
    function waitLoaded() {
        const section = document.getElementsByTagName("section");
        setTimeout(() => {
            if (section.length !== 2) waitLoaded();
            else {
                const target = section[0].children[1].children[0].children[0]; //取出會產生變化的節點
                hideRetweet();
                const observer = new MutationObserver(e => { //建立觀察者,文件有變化就執行下列函式
                    hideRetweet();
                });
                const config = { attributes: true, childList: true, characterData: true }; //設定觀察選項
                observer.observe(target, config); //開始觀察
            }
        }, 500);
    }

    function hideRetweet() {
        // 已轉推
        const strClass = ".css-1dbjc4n.r-obd0qt.r-1iusvr4.r-16y2uox.r-5f2r5o.r-1gmbmnb.r-bcqeeo";
        $(strClass).each((i, retweet) => {
            console.log("retweet", retweet);
            // 父物件
            $(retweet).parents().each((j, parent) => {
                let check = false; //確認推文是否已隱藏
                // 最上層
                $(parent).each((k, hide) => {
                    if ($(hide).hasClass("")) {
                        $(hide).hide();
                        check = true;
                        return false;
                    }
                });
                if (check) return false;
            });
        });
    }

})();