Notion Fix

Fix bugs in Notion

当前为 2021-08-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Notion Fix
  3. // @namespace https://github.com/alanleungcn/notion-fix
  4. // @version 1.2
  5. // @author Alan Leung
  6. // @description Fix bugs in Notion
  7. // @match https://www.notion.so/*
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. let preView = null;
  15. let curView = null;
  16. const checkInterval = 100;
  17. const viewList = [
  18. 'table',
  19. 'board',
  20. 'timeline',
  21. 'calendar',
  22. 'gallery',
  23. 'list',
  24. ];
  25.  
  26. const init = setInterval(() => {
  27. queryView();
  28. if (curView) {
  29. clearInterval(init);
  30. applyFix();
  31. }
  32. }, checkInterval);
  33.  
  34. window.addEventListener('click', () => {
  35. applyFix();
  36. });
  37.  
  38. // function fixTimelineDividerPosition() {
  39. // document.querySelector('.pseudoSelection').style.position = '';
  40. // }
  41.  
  42. function fixScrollbarPosition() {
  43. document.querySelector(
  44. '.notion-scroller.vertical.horizontal'
  45. ).scrollLeft = 0;
  46. }
  47.  
  48. function fixFirefoxScrollbarWidth() {
  49. const scroller = document.querySelectorAll('.notion-scroller');
  50. scroller.forEach((e) => {
  51. e.style.scrollbarWidth = 'thin';
  52. });
  53. }
  54.  
  55. function queryView() {
  56. viewList.forEach((view, i) => {
  57. if (document.querySelector(`.notion-${view}-view`)) {
  58. curView = viewList[i];
  59. }
  60. });
  61. }
  62.  
  63. function applyFix() {
  64. requestAnimationFrame(() => {
  65. queryView();
  66. // if (curView === 'timeline') {
  67. // fixTimelineDividerPosition();
  68. // }
  69. if (curView !== preView && preView === 'timeline') {
  70. fixScrollbarPosition();
  71. }
  72. fixFirefoxScrollbarWidth();
  73. preView = curView;
  74. });
  75. }
  76. })();