Twitter/X.com mark all media as sensitive

Marks all media as sensitive. This could be used to avoid seeing unwanted NSFW content.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitter/X.com mark all media as sensitive
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Marks all media as sensitive. This could be used to avoid seeing unwanted NSFW content.
// @author       Azeez
// @match        https://*.twitter.com/*
// @match        https://*.x.com/*
// @icon         https://www.google.com/s2/favicons?domain=twitter.com
// @license      MIT
// ==/UserScript==

(function() {
    let findObjectsForKey = function(obj, keys) {
        return Object.entries(obj).reduce((found, [key, value]) => {
            if (keys.includes(key)) {
                found.push(value);
            }
            if (value != null && typeof(value) == 'object') {
                found = found.concat(findObjectsForKey(value, keys));
            }
            return found;
        }, []);
    };

    let blurMedia = function(data) {
        findObjectsForKey(data, ['media']).forEach(obj => {
            if (Array.isArray(obj)) {
                obj.forEach(media => {
                    if (typeof media == 'object') {
                        media.sensitive_media_warning = {other: true};
                    }
                });
            }
        });
    };

    let old_parse = unsafeWindow.JSON.parse;
    let new_parse = function(string) {
        let data = old_parse(string);
        blurMedia(data);
        return data;
    };
    exportFunction(new_parse, unsafeWindow.JSON, { defineAs: "parse" });
})();