Greasy Fork

任意网站去黑白

去除任意网站的黑白样式

目前为 2022-12-03 提交的版本。查看 最新版本

作者
share121
评分
0 0 0
版本
3.0
创建于
2022-12-02
更新于
2022-12-03
大小
2.1 KB
许可证
MIT
适用于
所有网站

可以去除 任意网站 的黑白样式、灰色样式、灰度滤镜

🔥超 的代码,超 的速度

仅仅 1.22 KB 的代码大小,运行起来如闪电一样快

🔥准确击杀 ,只去除指定元素的灰度滤镜,避免误伤

原理

<body> 加载时向 <head> 元素添加以下 <style> 元素,避免闪屏

<style id="grayToColorful">
    * {
        filter: grayscale(0) !important;
        -webkit-filter: grayscale(0) !important;
        -moz-filter: grayscale(0) !important;
        -ms-filter: grayscale(0) !important;
        -o-filter: grayscale(0) !important;
        filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=0) !important;
    }
</style>

当纯 HTML 被完全加载以及解析时,移除 <style id="grayToColorful">
<head> 元素添加以下 <style> 元素。再遍历每个元素,若使用了灰度滤镜,则给它的 class 属性添加 grayToColorful

<style>
    .grayToColorful {
        filter: grayscale(0) !important;
        -webkit-filter: grayscale(0) !important;
        -moz-filter: grayscale(0) !important;
        -ms-filter: grayscale(0) !important;
        -o-filter: grayscale(0) !important;
        filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=0) !important;
    }
</style>

常见问题

Q:这个脚本有什么过人之处吗?
A:此脚本仅去除 包含灰度滤镜的元素的灰度滤镜 ,不会影响其他滤镜,和其他元素。例如:一个元素既有高斯模糊,又有灰度滤镜,我们 只会去除其中的灰度滤镜,而不影响高斯模糊

Q:为何百度首页的 logo 和搜索按钮还是灰色?
A:因为百度 logo 并不是简单的加了一个灰度滤镜,而是图片本身就换成黑白了,bilibili 首页的轮播图也是如此。而搜索按钮是把按钮颜色改为 #222 ,所以本身就是黑白的了。 解决办法只有一个个的单独适配,然而我没有这么多时间。

标签

  • 祭奠
  • 奠祭
  • 默哀
  • 灰色
  • 黑白
  • 灰度
  • 彩色