Greasy Fork is available in English.

任意网站去黑白

去除任意网站的黑白样式

< 任意网站去黑白についてのフィードバック

レート:良 – スクリプトは良好に動作する

§
投稿日: 2022/12/07

做了简易改造,让间隔可以自定义,降低cpu占用:

// ==UserScript==
// @name 任意网站去黑白
// @namespace http://tampermonkey.net/
// @version 8.5
// @description 去除任意网站的黑白样式
// @author share121
// @match *://*/*
// @match *
// @license MIT
// @grant none
// @homepageURL https://greasyfork.org/zh-CN/scripts/455866
// @supportURL https://greasyfork.org/zh-CN/scripts/455866/feedback
// @run-at document-start
// ==/UserScript==

(function() {
    const GAP = 10;  // 间隔10秒

    function colorful() {
         document.querySelectorAll("*").forEach(e => {
             var s = getComputedStyle(e);
             var f = s.filter,
                 w = s.webkitFilter;
             /grayscale\(.*?\)/g.test(f) &&
                 e.style.setProperty(
                 "filter",
                 f.replace(/grayscale\(.*?\)/g, "grayscale(0)"),
                 "important"
             );
             /grayscale\(.*?\)/g.test(w) &&
                 e.style.setProperty(
                 "-webkit-filter",
                 w.replace(/grayscale\(.*?\)/g, "grayscale(0)"),
                 "important"
             );
             /grayscale=(\+|\-)?(\d+\.\d+|\.\d+|\d+\.|\d+)/g.test(f) &&
                 e.style.setProperty(
                 "filter",
                 f.replace(
                     /grayscale=(\+|\-)?(\d+\.\d+|\.\d+|\d+\.|\d+)/g,
                     "grayscale=0"
                 ),
                 "important"
             );
         });
    }

    function main() {
        colorful();
        let _ = setInterval(colorful, GAP * 1000);
        window["colorful"] = _;
        console.log(`window.colorful: ${_}`);
    }

    setTimeout(main, 500);
})();
share121作者
§
投稿日: 2022/12/07

我有点不明白,为何要这样写,实际上只要更改 setInterval 的第二个参数即可改变间隔时间

// ==UserScript==
// @name 任意网站去黑白
// @namespace http://tampermonkey.net/
// @version 8.5
// @description 去除任意网站的黑白样式
// @author share121
// @match *://*/*
// @match *
// @license MIT
// @grant none
// @homepageURL https://greasyfork.org/zh-CN/scripts/455866
// @supportURL https://greasyfork.org/zh-CN/scripts/455866/feedback
// @run-at document-start
// ==/UserScript==

setInterval(function () {
  document.querySelectorAll("*").forEach(function (e) {
    var s = getComputedStyle(e);
    var f = s.filter,
      w = s.webkitFilter;
    /grayscale\(.*?\)/g.test(f) &&
      e.style.setProperty(
        "filter",
        f.replace(/grayscale\(.*?\)/g, "grayscale(0)"),
        "important"
      );
    /grayscale\(.*?\)/g.test(w) &&
      e.style.setProperty(
        "-webkit-filter",
        w.replace(/grayscale\(.*?\)/g, "grayscale(0)"),
        "important"
      );
    /grayscale=(\+|\-)?(\d+\.\d+|\.\d+|\d+\.|\d+)/g.test(f) &&
      e.style.setProperty(
        "filter",
        f.replace(
          /grayscale=(\+|\-)?(\d+\.\d+|\.\d+|\d+\.|\d+)/g,
          "grayscale=0"
        ),
        "important"
      );
  });
}, 5000); // 更改这个值即可改变间隔,单位:毫秒

返信を投稿

返信を投稿するにはログインしてください。