Text Zoom Only - 只放大文字大小

网页文字放大

Fra 19.06.2025. Se den seneste versjonen.

// ==UserScript==
// @name         Text Zoom Only - 只放大文字大小
// ==UserScript==
// @name         115Master
// @namespace    115Master
// @version      1.0
// @author       tanoak
// @description  网页文字放大
// @license      MIT
// @include      *zhihu.com/*
// @include      *baidu.com/*
// ==/UserScript==

(function () {
    'use strict';

    // 配置项:你可以在这里修改默认字体大小
    const MIN_FONT_SIZE_PX = 20; // 最小字体大小,可改为 16、20 等

    // 递归设置文字大小,避免影响图片、布局
    function adjustFontSize(el) {
        const excludedTags = ['SCRIPT', 'STYLE', 'IMG', 'CANVAS', 'SVG'];
        if (excludedTags.includes(el.tagName)) return;

        const computed = window.getComputedStyle(el);
        if (computed && computed.fontSize) {
            const currentSize = parseFloat(computed.fontSize);
            if (currentSize < MIN_FONT_SIZE_PX) {
                el.style.fontSize = MIN_FONT_SIZE_PX + 'px';
            }
        }

        // 遍历子元素
        for (let child of el.children) {
            adjustFontSize(child);
        }
    }

    // 页面加载完成后执行
    window.addEventListener('load', () => {
        adjustFontSize(document.body);
        console.log('✅ Text zoom applied.');
    });
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。