Greasy Fork is available in English.
为任意网站(默认支持 Nodeseek, DeepFlood)提供独立的字体放大、开关和重置功能,优化阅读体验。
当前为
// ==UserScript==
// @name 放大Nodeseek论坛字体
// @namespace http://tampermonkey.net/
// @version 0.6
// @license MIT
// @description 为任意网站(默认支持 Nodeseek, DeepFlood)提供独立的字体放大、开关和重置功能,优化阅读体验。
// @author 你的名字
// @match https://www.nodeseek.com/*
// @match https://www.deepflood.com/*
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
'use strict';
const hostname = window.location.hostname;
const defaultScale = 1.5;
// 根据域名生成独立的存储键
const scaleKey = `fontScale_${hostname}`;
const enabledKey = `fontEnabled_${hostname}`;
let scale = GM_getValue(scaleKey, defaultScale);
let isEnabled = GM_getValue(enabledKey, true);
const styleElementId = 'custom-font-styler';
// 需要放大字体的元素选择器列表
const elementsToEnlarge = [
// Nodeseek
'.post-title', '.post-content', '.reply-content', '.forum-title', '.post-author', '.forum-description',
'.post-info', // <--- 我在这里添加了新的目标!
// DeepFlood & Common
'.article-title', '.article-content', '.comment-content', 'h1', 'h2', 'p', 'article', '.prose'
];
// 动态更新或创建样式
function applyStyles() {
const existingStyleElement = document.getElementById(styleElementId);
if (!isEnabled) {
if (existingStyleElement) {
existingStyleElement.remove();
}
return;
}
let styleContent = '';
elementsToEnlarge.forEach(selector => {
// 使用 CSS em 单位进行相对缩放,更灵活
styleContent += `
${selector} {
font-size: ${scale}em !important;
line-height: 1.6em !important;
}
`;
});
if (existingStyleElement) {
existingStyleElement.innerHTML = styleContent;
} else {
const styleEl = document.createElement('style');
styleEl.id = styleElementId;
styleEl.innerHTML = styleContent;
document.head.appendChild(styleEl);
}
}
// 更新菜单状态
function registerCommands() {
GM_registerMenuCommand(`${isEnabled ? '✅' : '❌'} 字体放大 (点击切换)`, () => {
isEnabled = !isEnabled;
GM_setValue(enabledKey, isEnabled);
location.reload();
});
GM_registerMenuCommand(`设置字体放大倍率 (当前: ${scale}x)`, () => {
let newScale = prompt(`为 ${hostname} 设置放大倍率 (例如 1.5):`, scale);
if (newScale !== null) {
newScale = parseFloat(newScale);
if (!isNaN(newScale) && newScale > 0) {
GM_setValue(scaleKey, newScale);
location.reload();
} else {
alert('请输入一个有效的正数倍率。');
}
}
});
GM_registerMenuCommand('恢复默认设置', () => {
GM_setValue(scaleKey, defaultScale);
GM_setValue(enabledKey, true);
location.reload();
});
}
// --- Main Execution ---
registerCommands();
if (isEnabled) {
applyStyles();
}
})();