Page Zoom Controller

快速控制页面缩放:缩到最小/还原默认

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Page Zoom Controller
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  快速控制页面缩放:缩到最小/还原默认
// @author       onionycs
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 1. 缩放到最小(模拟持续按 Cmd+-/Ctrl+-)
    function zoomToMinimum() {
        // 浏览器最小缩放比例通常是 25%,循环减小直到达到最小值
        const minZoom = 0.25;
        let currentZoom = document.body.style.zoom || 1;

        // 方式1:直接设置到最小(高效)
        document.body.style.zoom = minZoom;

        // 方式2(备选):模拟按键递减(和手动按Cmd+-效果一致)
        // while (parseFloat(currentZoom) > minZoom) {
        //     currentZoom = parseFloat(currentZoom) - 0.05;
        //     document.body.style.zoom = currentZoom.toFixed(2);
        // }

        alert(`页面已缩放到最小值:${minZoom * 100}%`);
    }

    // 2. 还原缩放(重置为100%)
    function resetZoom() {
        document.body.style.zoom = 1;
        alert(`页面缩放已还原:100%`);
    }

    // 注册油猴菜单项
    GM_registerMenuCommand("🔍 缩放到最小", zoomToMinimum);
    GM_registerMenuCommand("🔄 缩放还原", resetZoom);
})();