// ==UserScript== // @name 今日热榜优化 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.8 // @description 今日热榜优化:宽度减少,去除广告,添加侧边栏导航 // @author ZZW // @license MIT // @grant GM_addStyle // @run-at document-start // @match *://*.tophub.today/* // ==/UserScript== (function() { 'use strict'; // ====================== // 第一部分:全局样式优化 // ====================== const css = ` /* 内容隐藏 */ .cq, .alert-warning, .bb-TT { display: none !important; } /* 宽度调整 */ body { max-width: 80% !important; margin: auto !important; } /* 字体调整 */ .mp .aa .tt, .cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll { font-size: 14px !important; } /* 侧边栏样式 (添加在全局样式中) */ #scroll-sidebar { position: fixed !important; top: 64px !important; left: 0 !important; width: 130px !important; height: calc(100vh - 64px) !important; background: rgba(255,255,255,0.98) !important; display: flex !important; flex-direction: column !important; padding: 12px 0 !important; z-index: 99999 !important; overflow-y: auto !important; box-shadow: 2px 0 5px rgba(0,0,0,0.1) !important; } #scroll-sidebar button { flex: 0 0 auto !important; width: 100% !important; padding: 12px 0 !important; border: none !important; border-bottom: 1px solid #f0f0f0 !important; cursor: pointer !important; background: transparent !important; text-align: center !important; font-size: 14px !important; transition: background 0.3s !important; outline: none !important; } #scroll-sidebar button:hover { background: #f8f9fa !important; } `; // 注入CSS if (typeof GM_addStyle !== "undefined") { GM_addStyle(css); } else { const styleNode = document.createElement("style"); styleNode.textContent = css; (document.head || document.documentElement).appendChild(styleNode); } // ====================== // 第二部分:侧边栏功能 // ====================== // 检查是否为首页 const isHomePage = window.location.host === 'tophub.today' && window.location.pathname === '/'; if (isHomePage) { // 等待DOM加载完成 window.addEventListener('DOMContentLoaded', function() { const categories = [ '推荐', '综合', '科技', '人工智能', '娱乐', '社区', '购物', '财经', '大学', '日报', '地方门户', '影视', '阅读', '游戏', '音乐', '体育', '产品', '开发', '设计', '应用', '汽车', '安全', ' ' ]; // 创建侧边栏容器 const sidebar = document.createElement('div'); sidebar.id = 'scroll-sidebar'; // 创建导航按钮 categories.forEach(category => { const btn = document.createElement('button'); btn.textContent = category; btn.addEventListener('click', () => { scrollToCategory(category); }); sidebar.appendChild(btn); }); // 添加到文档 document.body.appendChild(sidebar); // 滚动功能 function scrollToCategory(target) { const targetIndex = categories.indexOf(target); if (targetIndex === -1) return; window.scrollTo({ top: targetIndex * 512.78, behavior: 'smooth' }); } }); } })();