语雀评论目录导航

try to take over the world!

  1. // ==UserScript==
  2. // @name 语雀评论目录导航
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description try to take over the world!
  6. // @author logeast
  7. // @match https://www.yuque.com/logeast/dots/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. "use strict";
  13.  
  14. // Your code here...
  15. window.onload = () => {
  16. const header = document.querySelector(".header");
  17. header.setAttribute("style", "position: fixed; top: 0;");
  18. header.parentNode.setAttribute("style", "height: 60px");
  19.  
  20. const getTargetName = () => {
  21. let _h4List = [];
  22. const parent = document.querySelector(".ant-list-items");
  23. const floors =
  24. parent && parent.querySelectorAll(".comment-list-item-inner");
  25. Array.from(floors).map((item, index) => {
  26. _h4List.push(item.querySelector("h4").innerText);
  27. });
  28. return _h4List;
  29. };
  30.  
  31. const renderSidebarDom = () => {
  32. const ul = document.createElement("ul");
  33. ul.setAttribute(
  34. "class",
  35. "ant-menu aside-container menu-site ant-menu-light ant-menu-root ant-menu-inline"
  36. );
  37. ul.setAttribute(
  38. "style",
  39. "padding-top: 80px;height: 100%; overflow-y: auto"
  40. );
  41.  
  42. const fragment = document.createDocumentFragment();
  43. getTargetName().forEach((item, index) => {
  44. const li = document.createElement("li");
  45. li.setAttribute("class", `ant-menu-item ant-menu-item-only-child`);
  46. li.setAttribute("style", "padding-left: 24px;");
  47. li.innerHTML = `<a href="#floor-${
  48. index + 1
  49. }" title="${item}" style="overflow: hidden;text-overflow: ellipsis;">${item}</a>`;
  50. fragment.appendChild(li);
  51. });
  52. ul.appendChild(fragment);
  53.  
  54. const container = document.createElement("div");
  55. container.setAttribute(
  56. "style",
  57. "overflow: hidden; position: fixed; top: 0; left: 0; width: 240px; height: 100%; max-height: 100vh; z-index: 998;"
  58. );
  59. container.appendChild(ul);
  60.  
  61. document.body.appendChild(container);
  62. };
  63.  
  64. renderSidebarDom();
  65. };
  66. })();

QingJ © 2025

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