移动设备全屏浏览

长按右下角

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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;
        }
    });
})();