Skip to content

Instantly share code, notes, and snippets.

@wkgcass
Last active December 4, 2022 21:21
Show Gist options
  • Save wkgcass/24b1913c3a21107047c2742f2dfcbf1b to your computer and use it in GitHub Desktop.
Save wkgcass/24b1913c3a21107047c2742f2dfcbf1b to your computer and use it in GitHub Desktop.
油猴脚本-把灰色网页变回彩色
// ==UserScript==
// @name setgrayscale
// @version 0.1
// @description x
// @author wkgcass
// @match *://*/*
// ==/UserScript==
(function() {
'use strict';
var exceptions = [
"message.bilibili.com",
"message.acfun.cn",
];
var url = window.location.href;
for (var e of exceptions) {
if (url.indexOf(e) != -1) {
return;
}
}
function setGrayScale(node, scale) {
if (!node) return;
var style = node.getAttribute("style");
if (style) {
style += "; "
} else {
style = ""
}
style += "filter: grayscale(" + scale + ") !important;";
node.setAttribute("style", style);
// special handling:
// for baidu
(function() {
var cls = node.getAttribute("class");
if (!cls) return;
var idx = cls.indexOf("big-event-gray");
if (idx == -1) return;
var newcls = cls.substring(0, idx);
newcls += cls.substring(idx + "big-event-gray".length);
node.setAttribute("class", newcls);
})();
}
var html = document.documentElement;
setGrayScale(html, 0.0);
var body = document.body;
setGrayScale(body, 0.0);
// special handling:
// for weibo
(function() {
var nodes = document.getElementsByClassName("grayTheme");
for (var node of nodes) {
setGrayScale(node, 0.0);
}
})();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment