Replace Images and Videos with White Divs (Social Media Version)

Replace all images and videos on Facebook, Instagram, and Reddit with white divs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Replace Images and Videos with White Divs (Social Media Version)
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Replace all images and videos on Facebook, Instagram, and Reddit with white divs
// @match        *://*.facebook.com/*
// @match        *://*.instagram.com/*
// @match        *://*.reddit.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function replaceRedditVideos() {
        const redditVideos = document.querySelectorAll('shreddit-player');
        redditVideos.forEach(player => {
            const div = document.createElement('div');
            div.style.width = '640px';  // Default video width
            div.style.height = '360px'; // Default video height
            div.style.backgroundColor = 'white';
            div.style.display = 'inline-block';
            div.textContent = 'Video Blocked';
            div.style.display = 'flex';
            div.style.justifyContent = 'center';
            div.style.alignItems = 'center';
            div.style.color = 'black';
            div.style.fontFamily = 'Arial, sans-serif';
            if (player.parentNode) {
                player.parentNode.replaceChild(div, player);
            }
        });
    }

    function replaceMediaWithDivs() {
        const mediaElements = document.querySelectorAll('img, video');
        mediaElements.forEach(element => {
            const div = document.createElement('div');
            if (element.tagName.toLowerCase() === 'img') {
                div.style.width = (element.width || element.offsetWidth || 100) + 'px';
                div.style.height = (element.height || element.offsetHeight || 100) + 'px';
            } else if (element.tagName.toLowerCase() === 'video') {
                div.style.width = (element.videoWidth || element.offsetWidth || 640) + 'px';
                div.style.height = (element.videoHeight || element.offsetHeight || 360) + 'px';
            }
            div.style.backgroundColor = 'white';
            div.style.display = 'inline-block';
            if (element.parentNode) {
                element.parentNode.replaceChild(div, element);
            }
        });

        // Call the function to replace Reddit videos
        replaceRedditVideos();
    }

    // Run the functions when the page loads
    window.addEventListener('load', () => {
        replaceMediaWithDivs();
        replaceRedditVideos();
    });

    // Run the functions periodically to catch dynamically loaded media
    setInterval(() => {
        replaceMediaWithDivs();
        replaceRedditVideos();
    }, 2000);

    // Use MutationObserver to detect DOM changes
    const observer = new MutationObserver(() => {
        replaceMediaWithDivs();
        replaceRedditVideos();
    });
    observer.observe(document.body, { childList: true, subtree: true });
})();