黑白网页颜色还原

移除灰度滤镜,还你一个五彩斑斓的网页(支持所有使用 CSS filter 的站点)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

/*!
// ==UserScript==
// @name          黑白网页颜色还原
// @namespace     https://github.com/maomao1996/tampermonkey-scripts
// @version       0.2.0
// @description   移除灰度滤镜,还你一个五彩斑斓的网页(支持所有使用 CSS filter 的站点)
// @author        maomao1996
// @include       *
// @grant         none
// ==/UserScript==
*/
;
(function () {
    'use strict';
    var observerChildList = function (callback, selector) {
        var observer = new MutationObserver(function (_a) {
            var mutation = _a[0];
            mutation.type === 'childList' && callback(observer, mutation);
        });
        observer.observe(selector, { childList: true, subtree: true });
        return observer;
    };
    var style = document.documentElement.style;
    var filterKey = [
        'filter',
        '-webkit-filter',
        '-moz-filter',
        '-ms-filter',
        '-o-filter'
    ].find(function (prop) { return typeof style[prop] === 'string'; });
    var restore = function () {
        Array.prototype.forEach.call(document.querySelectorAll('*'), function (el) {
            var filterValue = document.defaultView.getComputedStyle(el)[filterKey];
            if (filterValue.match('grayscale')) {
                el.style.setProperty(filterKey, 'initial', 'important');
            }
        });
    };
    observerChildList(restore, document.querySelector('body'));
    restore();
})();