Remove scrollbar-color for Notion

Remove scrollbar-color from Notion pages,ths Chatgpt.

当前为 2024-09-20 提交的版本,查看 最新版本

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