蓝狐左侧滚动条自动滚动

蓝狐左侧滚动条自动滚动--产品页面

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name 蓝狐左侧滚动条自动滚动
// @description 蓝狐左侧滚动条自动滚动--产品页面
// @require    https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @match        https://lanhuapp.com/web/#/item/project/product*
// @grant       ao
// @run-at document-end
// @version 1.0.1.20160102053326
// @namespace https://greasyfork.org/users/25818
// @license MIT
// ==/UserScript==

$(function(){
    // 开始


  const observer = new MutationObserver((mutations) => {
    const elementCheck = document.querySelector('.lan-dnd-item-box');
          let element = $('.tree-item-wrapper.active');

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


      setTimeout(function (){

                // 执行操作
console.log('开始滚动')
        element = element.get(0)
  console.log('element', element)
// 获取元素相对于文档顶部的位置
const elementTop = element.getBoundingClientRect().top + window.scrollY;
const elementHeight = element.getBoundingClientRect().height;
const windowHeight = window.innerHeight;

$('.vertical.lan-tree-list').get(0).scrollTo({
  top: elementTop - windowHeight / 2 + elementHeight / 2,
  behavior: 'smooth'
});


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

      }, 1000)


    }
});

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

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





})