网道文档助手

文档滚动时目录悬浮

// ==UserScript==
// @name         网道文档助手
// @namespace    http://tampermonkey.net/
// @version      1.0.0-2024-05-22
// @description  文档滚动时目录悬浮
// @author       cshaptx4869
// @match        https://wangdoc.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=wangdoc.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var tocElement = document.querySelector('.article-toc');
    var fixedElement = tocElement.cloneNode(true);
    var panelInfoElement = document.querySelector('.panel-info');
    fixedElement.style.display = 'none';
    fixedElement.style.position = 'sticky';
    fixedElement.style.top = '1.5rem';
    panelInfoElement.after(fixedElement);
    window.addEventListener('scroll', function() {
        var rect = panelInfoElement.getBoundingClientRect();
        if (rect.top < 0 || rect.bottom > window.innerHeight) {
            fixedElement.style.display = 'block';
        } else {
            fixedElement.style.display = 'none';
        }
    });
})();

QingJ © 2025

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