一键默哀

Turn the entire page black and white on mobile devices

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);
        }
    });
})();