豆沙绿护眼模式Plus

改网页背景色为豆沙绿,支持按域名禁用

  1. // ==UserScript==
  2. // @name 豆沙绿护眼模式Plus
  3. // @version 4.3
  4. // @description 改网页背景色为豆沙绿,支持按域名禁用
  5. // @author DeepSeek
  6. // @run-at document-start
  7. // @match *://*/*
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @namespace https://gf.qytechs.cn/users/452911
  12. // ==/UserScript==
  13.  
  14. // 初始化禁用域名列表
  15. let disabledDomains = GM_getValue('disabledDomains', []);
  16. const currentDomain = window.location.hostname;
  17. const isDisabled = disabledDomains.includes(currentDomain);
  18.  
  19. // 根据当前状态注册(不可用)单一菜单命令
  20. if (isDisabled) {
  21. GM_registerMenuCommand('在此域名启用护眼模式', () => {
  22. disabledDomains = disabledDomains.filter(domain => domain !== currentDomain);
  23. GM_setValue('disabledDomains', disabledDomains);
  24. location.reload();
  25. });
  26. } else {
  27. GM_registerMenuCommand('在此域名禁用护眼模式', () => {
  28. disabledDomains.push(currentDomain);
  29. GM_setValue('disabledDomains', disabledDomains);
  30. location.reload();
  31. });
  32. }
  33.  
  34. // 检查是否启用夜间模式
  35. function isNightMode() {
  36. return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
  37. }
  38.  
  39. if (!isNightMode() && !isDisabled) {
  40. function background() {
  41. let elementList = document.querySelectorAll('*');
  42. for (let i = 0; i < elementList.length; i++) {
  43. if (!(elementList[i].matches('[class*="player"] > *') ||
  44. elementList[i].matches('.video > *'))) {
  45. let srcBgColor = window.getComputedStyle(elementList[i]).backgroundColor;
  46. let splitArray = srcBgColor.match(/[\d\.]+/g);
  47. if (splitArray) {
  48. let r = parseInt(splitArray[0], 10),
  49. g = parseInt(splitArray[1], 10),
  50. b = parseInt(splitArray[2], 10);
  51. if (r > 150 && g > 150 && b > 150) {
  52. elementList[i].style.backgroundColor = '#C7EDCC';
  53. }
  54. }
  55. }
  56. }
  57. // 更改链接颜色
  58. let links = document.querySelectorAll("a[href^='http']:not(.button)");
  59. for (let i = 0; i < links.length; i++) {
  60. links[i].style.color = "#40933C";
  61. links[i].style.textDecoration = "none";
  62. }
  63. }
  64. background();
  65. window.onload = function() {
  66. background();
  67. };
  68.  
  69. setTimeout(function() {
  70. let observer = new MutationObserver(function(mutations) {
  71. background();
  72. window.setTimeout(background2, 50);
  73. });
  74. observer.observe(document.body, {
  75. childList: true,
  76. subtree: true
  77. });
  78. }, 5);
  79.  
  80. function background2() {
  81. let elements = document.querySelectorAll("DIV#gb-main,DIV.url.clearfix,DIV.nav-bar-v2-fixed > * > *:not(div.nav-bar-bottom),DIV.se-page-hd-content");
  82. elements.forEach(element => {
  83. element.style.backgroundColor = "#C7EDCC";
  84. });
  85. }
  86.  
  87. background2();
  88. window.setTimeout(background2, 100);
  89. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址