一键默哀

Turn the entire page black and white on mobile devices

// ==UserScript==
// @name         一键默哀
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Turn the entire page black and white on mobile devices
// @author       YourName
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Function to apply grayscale filter to the entire page
    function makePageGrayscale() {
        document.documentElement.style.filter = 'grayscale(100%)';
        document.documentElement.style.transition = 'filter 0.3s';
    }

    // Apply grayscale to the entire page immediately
    makePageGrayscale();

    // Observe DOM changes to ensure the filter remains applied
    const observer = new MutationObserver(() => {
        makePageGrayscale();
    });

    observer.observe(document.body, { childList: true, subtree: true });

    // Function to apply grayscale filter to video elements
    function makeVideosGrayscale(video) {
        video.style.filter = 'grayscale(100%)';
        video.style.transition = 'filter 0.3s';
    }

    // Observe DOM changes to detect new video elements
    const videoObserver = new MutationObserver(() => {
        const videos = document.querySelectorAll('video');
        videos.forEach((video) => {
            if (!video.hasAttribute('data-grayscale-enabled')) {
                video.setAttribute('data-grayscale-enabled', 'true');
                makeVideosGrayscale(video);
            }
        });
    });

    videoObserver.observe(document.body, { childList: true, subtree: true });

    // Apply grayscale to existing videos on the page
    document.querySelectorAll('video').forEach((video) => {
        if (!video.hasAttribute('data-grayscale-enabled')) {
            video.setAttribute('data-grayscale-enabled', 'true');
            makeVideosGrayscale(video);
        }
    });
})();