Remove scrollbar-color for Notion

Remove scrollbar-color from Notion pages,ths Chatgpt.

  1. // ==UserScript==
  2. // @name Remove scrollbar-color for Notion
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.0
  5. // @description Remove scrollbar-color from Notion pages,ths Chatgpt.
  6. // @author Jw
  7. // @icon none
  8. // @include *://*.notion.*/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. console.log("等待DOM加载");
  17.  
  18. let style = document.createElement('style');
  19. style.innerHTML = "*::-webkit-scrollbar{display:none} /* Chrome and Safari */" +
  20. " scrollbar-width: none; /* firefox */\n" +
  21. " -ms-overflow-style: none; /* IE 10+ */\n" +
  22. " overflow-x: hidden;\n" +
  23. " overflow-y: auto;";
  24. document.head.appendChild(style);
  25. console.log("运行111111111111111111111111111111");
  26.  
  27. function removeScrollbarColor() {
  28. for (let i = 0; i < document.styleSheets.length; i++) {
  29. const styleSheet = document.styleSheets[i];
  30.  
  31. try {
  32. const rules = styleSheet.cssRules || styleSheet.rules;
  33. if (!rules) continue;
  34.  
  35. for (let j = 0; j < rules.length; j++) {
  36. const rule = rules[j];
  37. if (rule.style && rule.style.scrollbarColor) {
  38. rule.style.scrollbarColor = "";
  39. // 移除 scrollbar-color
  40. }
  41. }
  42. } catch (e) {
  43. console.log('Error accessing stylesheet:', e);
  44. }
  45. }
  46. }
  47.  
  48. // 使用 MutationObserver 来观察 DOM 变化
  49. const observer = new MutationObserver(function(mutations) {
  50. mutations.forEach(function(mutation) {
  51. if (mutation.addedNodes.length || mutation.type === 'childList') {
  52. removeScrollbarColor();
  53. }
  54. });
  55. });
  56.  
  57. // 配置 MutationObserver 观察整个文档
  58. observer.observe(document.documentElement, {
  59. childList: true,
  60. subtree: true
  61. });
  62.  
  63. // 初始运行,确保在脚本加载时已经加载的样式也被处理
  64. removeScrollbarColor();
  65.  
  66. })();
  67.