Change Background Color

A brief description of your script

  1. // ==UserScript==
  2. // @name Change Background Color
  3. // @namespace Change Background Color
  4. // @description A brief description of your script
  5. // @author RGB
  6. // @include *.*
  7. // @version 1.1
  8. // ==/UserScript==
  9. /*这是一个可以真正改变网页背景颜色的js脚本,这个脚本只改变网页中背景为白色(你也可以定义其他颜色)的部分
  10. */
  11.  
  12.  
  13. (function() {
  14. // your page initialization code here
  15. // the DOM will be available here
  16.  
  17. var Gr1 = 240; //RGB中的R值...当网页的背景颜色的rgb值分别大于Gr1,Gg1,Gb1时此脚本将把颜色改成目标颜色color
  18. var Gg1 = 240; //RGB中的G值
  19. var Gb1 = 240; //RGB中的B值
  20. var color = "#CDC9C9" //改变后的背景颜色,默认值为网上那个所谓的眼科专家说的对眼睛最好的颜色
  21. // var color = "#bed6c1"
  22.  
  23. //**********以下代码用户无需修改***********//
  24. var Gr, Gg, Gb; //全局变量记录当前标签的rgb值,用于比较
  25.  
  26. //以下函数用于分解获取的"rgb(255, 255, 255)"格式的rgb
  27. function FGrgb(Grgb) {
  28.  
  29. var kaisi = Grgb.indexOf(",");
  30. Gr = parseInt(Grgb.slice(4, kaisi));
  31.  
  32. var kaisi1 = Grgb.indexOf(",", kaisi + 1);
  33. Gg = parseInt(Grgb.slice(kaisi + 1, kaisi1));
  34.  
  35. Gb = parseInt(Grgb.slice(kaisi1 + 1, Grgb.length - 1));
  36.  
  37. //alert(Gr+"|"+Gb+"|"+Gg);
  38. }
  39.  
  40.  
  41. var Lcolor = ""; //用于记录网页中获取的背景颜色
  42. //获取并修改body的背景颜色.
  43. Lcolor = document.defaultView.getComputedStyle(document.body, "").getPropertyValue("background-Color");
  44. FGrgb(Lcolor);
  45.  
  46. if ((Gr > Gr1 && Gg > Gg1 && Gb > Gb1) || Lcolor == "transparent") //transparent表示透明
  47. {
  48. document.body.style.backgroundColor = color;
  49. }
  50.  
  51. //获取并修改所有标签的背景颜色
  52. var alltags = document.getElementsByTagName("*");
  53.  
  54. for (let x in alltags) {
  55. try {
  56. Lcolor = document.defaultView.getComputedStyle(alltags[x], "").getPropertyValue("background-Color");
  57. } catch (err) {
  58. //console.log(x);
  59. //console.log(alltags[x]);
  60. }
  61. FGrgb(Lcolor);
  62. if (Gr > Gr1 && Gg > Gg1 && Gb > Gb1) {
  63. alltags[x].style.backgroundColor = color;
  64. }
  65. }
  66. })();