腾讯codesign左侧滚动条自动滚动

腾讯codesign左侧滚动条自动滚动--左侧目录

当前为 2025-07-23 提交的版本,查看 最新版本

// ==UserScript==
// @name 腾讯codesign左侧滚动条自动滚动
// @description 腾讯codesign左侧滚动条自动滚动--左侧目录
// @require    https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @match        https://codesign.qq.com/app/s*
// @grant       ao
// @run-at document-end
// @version 1.0.2.20160102053326
// @license MIT
// @namespace https://gf.qytechs.cn/users/25818
// ==/UserScript==

$(function(){
    
        // 处理锚点定位和点击
    function handleAnchorNavigation(anchor) {
        if (!anchor) return;
        
        console.log(`尝试定位锚点: ${anchor}`);
        // 查找具有对应data-value的元素
        const targetElement = $(`.t-tree__list [data-value="${anchor}"]`).first();
        
        if (targetElement.length) {
            console.log(`找到元素: ${anchor}`);
            
            // 滚动到元素位置
            targetElement[0].scrollIntoView({
                behavior: 'smooth',
                block: 'center'
            });
            
            // 延迟点击,确保滚动完成
            setTimeout(() => {
                console.log(`点击元素: ${anchor}`);
                targetElement.trigger('click');
            }, 500);
        } else {
            console.log(`未找到锚点对应的元素: ${anchor}`);
        }
    }
    
    
    // 开始
    // 从URL获取当前锚点
    const currentAnchor = window.location.hash.substring(1);

  const observer = new MutationObserver((mutations) => {
    const elementCheck = document.querySelector('.t-tree__list');
          let elementClick = $('.t-tree__list data-value[47pfhj]');

   // if (elementCheck && element.length > 0) {
    if (elementCheck) {
        console.log('搜索栏已加载');
        observer.disconnect(); // 停止观察


      setTimeout(function (){

                // 执行操作
console.log('开始滚动')
            // 如果有锚点,进行定位
            if (currentAnchor) {
                handleAnchorNavigation(currentAnchor);
            }

            // 为目录项添加点击事件,存储锚点
            $('.t-tree__list').on('click', '[data-value]', function(e) {
                const dataValue = $(this).attr('data-value');
                if (dataValue) {
                    console.log(`存储锚点: ${dataValue}`);
                    // 更新URL锚点,不刷新页面
                    window.location.hash = dataValue;
                }
            });

  console.log('elementClick', elementClick)



	console.log('滚动条自动滚动完成');

      }, 1000)


    }
});

// 开始观察DOM变化
observer.observe(document.body, {
    childList: true,      // 监听子节点变化
    subtree: true         // 监听所有后代节点
});

// 超时处理(可选)
setTimeout(() => {
    observer.disconnect();
    if (!document.querySelector('.t-tree__list')) {
        console.error('搜索栏加载超时');
    }
}, 100000); // 10秒超时





})

QingJ © 2025

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