一键默哀

Turn the entire page black and white on mobile devices

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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);
        }
    });
})();