移动设备全屏浏览

长按右下角

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         移动设备全屏浏览
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  长按右下角
// @author       Gemini
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 全屏切换
    function isFullscreen() {
        return document.fullscreenElement ||
            document.webkitFullscreenElement ||
            document.mozFullScreenElement ||
            document.msFullscreenElement;
    }
    function toggleFullscreen() {
        if (!isFullscreen()) {
            if (document.documentElement.requestFullscreen) document.documentElement.requestFullscreen();
            else if (document.documentElement.webkitRequestFullscreen) document.documentElement.webkitRequestFullscreen();
            else if (document.documentElement.mozRequestFullScreen) document.documentElement.mozRequestFullScreen();
            else if (document.documentElement.msRequestFullscreen) document.documentElement.msRequestFullscreen();
        } else {
            if (document.exitFullscreen) document.exitFullscreen();
            else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
            else if (document.mozCancelFullScreen) document.mozCancelFullScreen();
            else if (document.msExitFullscreen) document.msExitFullscreen();
        }
    }

    // 长按屏幕右下角切换全屏
    let timer = null;
    const PRESS_MS = 500; // 长按时间,毫秒
    const AREA_SIZE = 60; // 右下角热区的大小(像素)

    function inRightBottomCorner(x, y) {
        return (
            x > window.innerWidth - AREA_SIZE &&
            y > window.innerHeight - AREA_SIZE
        );
    }

    document.addEventListener('touchstart', function(e) {
        const t = e.touches[0];
        if (inRightBottomCorner(t.clientX, t.clientY)) {
            timer = setTimeout(() => {
                toggleFullscreen();
                timer = null;
            }, PRESS_MS);
        }
    }, {passive:true});

    document.addEventListener('touchend', function() {
        if (timer) {
            clearTimeout(timer);
            timer = null;
        }
    });
    document.addEventListener('touchmove', function(e) {
        if (!timer) return;
        const t = e.touches[0];
        if (!inRightBottomCorner(t.clientX, t.clientY)) {
            clearTimeout(timer);
            timer = null;
        }
    });
})();