Notion TOC

try to take over the world!

当前为 2020-12-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Notion TOC
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://www.notion.so/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. "use strict";
  13. const initToc = () => {
  14. const toc = document.querySelector(".notion-table_of_contents-block").cloneNode(true);
  15. toc.style.boxSizing = "border-box";
  16. toc.style.width = "auto";
  17. toc.style.height = "calc(100% - 160px)";
  18. toc.style.overflowY = "scroll";
  19. toc.style.position = "fixed";
  20. toc.style.top = "50%";
  21. toc.style.left = "50%";
  22. toc.style.zIndex = 1;
  23. toc.style.transform = "translate(400px, -50%)";
  24. document.body.appendChild(toc);
  25. };
  26.  
  27. const observer = new MutationObserver((mutations, self) => {
  28. var el = document.querySelector(".notion-table_of_contents-block");
  29. if (el) {
  30. initToc();
  31. self.disconnect();
  32. }
  33. });
  34.  
  35. observer.observe(document, {
  36. childList: true,
  37. subtree: true,
  38. });
  39. })();