Greasy Fork 还支持 简体中文。

Twitter media-only filter toggle.

Toggle non-media tweets on and off, for the power-viewer!

目前為 2021-04-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitter media-only filter toggle.
// @version      0.7
// @description  Toggle non-media tweets on and off, for the power-viewer!
// @author       Cro
// @match        https://twitter.com/*
// @run-at       document-idle
// @grant        GM_setValue
// @grant        GM_getValue
// @namespace https://greasyfork.org/users/10865
// ==/UserScript==
/* jshint esversion: 6 */

(function() {
    'use strict';
    let storageKey = "cro-media-toggle";
    // The complexity of determining what is a meaningful image post.
    let containsImage = function(node)
    {
        let res = false;
        node.querySelectorAll("img").forEach(function (sub)
                                             {
            if (!(sub.src.startsWith("https://abs-0.twimg.com/emoji") ||
                  sub.src.startsWith("https://pbs.twimg.com/profile_images") ||
                  sub.src.startsWith("https://abs.twimg.com/hashflags")))
            {
                res = true;
            }
        });
        return res;
    };
    let isTarget = node => node.tagName &&
        node.tagName.toLowerCase() == "article" &&
        !(node.querySelector("video") || containsImage(node));
    let hideIfTarget = function(node) { if (isTarget(node)) node.parentNode.parentNode.parentNode.style.display = "none"; };
    let show = function(node) { node.parentNode.parentNode.parentNode.style.display = "block"; };
    let hideAll = function() { document.body.querySelectorAll("article").forEach(hideIfTarget); };
    let showAll = function() { document.body.querySelectorAll("article").forEach(show); };
    let running = GM_getValue(storageKey);

    let createUi = function(target)
    {
        let button = document.createElement("button");
        let setButtonState = function()
        {
            if (running)
            {
                button.innerText = "Only Media Tweets";
            }
            else
            {
                button.innerText = "All Tweets";
                showAll();
            }
        };

        button.onclick = function(event)
        {
            running = !running;
            GM_setValue(storageKey, running);
            setButtonState();
        };

        target.prepend(button);
        setButtonState();
    };

    let startProcess = function()
    {
        setInterval(function()
        {
            if (running && !location.pathname.startsWith("/notifications"))
            {
                hideAll();
            }
        }, 250);
    };

    // Wait for twitter's react crap finish loading things.
    let scanInterval = setInterval(function()
    {
        let target = document.body.querySelector("h1[role='heading']");
        if (target)
        {
            clearInterval(scanInterval);
            startProcess(target);
            createUi(target);
        }
    }, 10);
})();