您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
侧边栏滚动到顶部时固定
// ==UserScript== // @name 微博侧边栏Sticky效果 // @namespace https://github.com/YishenTu/tampermonkey-scripts // @version 1.0 // @description 侧边栏滚动到顶部时固定 // @author YT // @match https://weibo.com/* // @match https://www.weibo.com/* // @match https://s.weibo.com/* // @grant none // @run-at document-idle // @license MIT // ==/UserScript== (function () { 'use strict'; const sidebarSelector = '.Main_sideMain_263ZF'; // 顶部导航栏高度偏移量 const topOffset = 56; function applyStickyEffect() { const sidebar = document.querySelector(sidebarSelector); if (!sidebar || sidebar.hasAttribute('data-sticky')) return; // 使用原生CSS sticky定位 sidebar.style.position = 'sticky'; sidebar.style.top = topOffset + 'px'; sidebar.style.height = 'fit-content'; sidebar.style.maxHeight = `calc(100vh - ${topOffset + 20}px)`; sidebar.style.overflowY = 'auto'; sidebar.setAttribute('data-sticky', 'true'); } // 初始化脚本 function init() { // 监听DOM变化以处理动态加载的内容 const observer = new MutationObserver(() => { applyStickyEffect(); }); observer.observe(document.body, { childList: true, subtree: true }); // 立即尝试应用sticky效果 applyStickyEffect(); } init(); })();