// ==UserScript== // @name 放大 Nodeseek 论坛字体 // @namespace http://tampermonkey.net/ // @version 0.3 // @license MIT // @description 将 Nodeseek 论坛上的字体放大一倍 // @author 你的名字 // @match https://www.nodeseek.com/* // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @downloadURL https://update.greasyfork.icu/scripts/500789/%E6%94%BE%E5%A4%A7%20Nodeseek%20%E8%AE%BA%E5%9D%9B%E5%AD%97%E4%BD%93.user.js // @updateURL https://update.greasyfork.icu/scripts/500789/%E6%94%BE%E5%A4%A7%20Nodeseek%20%E8%AE%BA%E5%9D%9B%E5%AD%97%E4%BD%93.meta.js // ==/UserScript== (function() { 'use strict'; // 默认放大倍率 const defaultScale = 1.5; let scale = GM_getValue('fontScale', defaultScale); // 添加菜单选项 GM_registerMenuCommand('设置字体放大倍率', () => { let newScale = prompt('请输入放大倍率 (例如 1.5 表示放大 1.5 倍):', scale); if (newScale !== null) { newScale = parseFloat(newScale); if (!isNaN(newScale) && newScale > 0) { GM_setValue('fontScale', newScale); location.reload(); // 重新加载页面以应用新设置 } else { alert('请输入一个有效的正数倍率。'); } } }); // 放大特定元素的字体大小 const elementsToEnlarge = [ '.post-title', // 帖子标题 '.post-content', // 帖子内容 '.reply-content', // 回复内容 '.forum-title', // 论坛标题 '.post-author', // 帖子作者 '.forum-description' // 论坛描述 ]; // 放大字体的函数 function enlargeElements() { elementsToEnlarge.forEach(selector => { const elements = document.querySelectorAll(selector); elements.forEach(element => { // 只处理未放大过的元素 if (!element.hasAttribute('data-enlarged')) { const style = window.getComputedStyle(element, null).getPropertyValue('font-size'); const currentSize = parseFloat(style); element.style.fontSize = (currentSize * scale) + 'px'; element.setAttribute('data-enlarged', 'true'); } }); }); } // 使用防抖函数来限制处理频率 function debounce(func, wait) { let timeout; return function executedFunction() { const later = () => { clearTimeout(timeout); func(); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } // 初始执行 enlargeElements(); // 创建观察器监听页面变化 const observer = new MutationObserver(debounce(() => { enlargeElements(); }, 200)); // 配置观察器,只监听需要的部分 const mainContent = document.querySelector('.main-content') || document.body; observer.observe(mainContent, { childList: true, subtree: true }); })();