Fullscreen Button

A simple float button for entering fullscreen.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Fullscreen Button
// @name:zh-CN   全屏按钮
// @match        *://*/*
// @version      0.2
// @description  A simple float button for entering fullscreen.
// @description:zh-CN 一个简单的浮动按钮用于全屏显示网页。
// @noframes
// @license      CC0
// @namespace    https://greasyfork.org/users/123506
// ==/UserScript==
'use strict';

// Check if the fullscreen button already exists
var btn = document.getElementById("b0n");

// If it doesn't exist, create it
if (!btn) {
    document.body.insertAdjacentHTML("afterbegin", '<div id="b0n" style="background-color: rgb(209, 209, 209);position: fixed;display: flex;opacity: 0.66;margin: 1em;z-index: 2147483647" ><svg width="24" height="24"><path d="M7,14L5,14v5h5v-2L7,17v-3zM5,10h2L7,7h3L10,5L5,5v5zM17,17h-3v2h5v-5h-2v3zM14,5v2h3v3h2L19,5h-5z"/></svg></div>');
    btn = document.getElementById("b0n");
}

var reF = document.documentElement.requestFullscreen || document.documentElement.webkitRequestFullscreen;

var action = function () {
    reF.call(document.documentElement);
}

btn.onclick = action;

// Variables for long press and touch events
var longPressTimer;
var isTouching = false;
var touchOffsetX, touchOffsetY;

// Add touch event listeners
btn.addEventListener("touchstart", function (e) {
    isTouching = true;
    var touch = e.touches[0];
    touchOffsetX = touch.clientX - btn.getBoundingClientRect().left;
    touchOffsetY = touch.clientY - btn.getBoundingClientRect().top;

    // Set a long press timer for 500 milliseconds
    longPressTimer = setTimeout(function () {
        btn.style.cursor = "grabbing";
    }, 500);
});

btn.addEventListener("touchmove", function (e) {
    if (!isTouching) return;
    var touch = e.touches[0];
    var x = touch.clientX - touchOffsetX;
    var y = touch.clientY - touchOffsetY;
    btn.style.left = x + "px";
    btn.style.top = y + "px";
    e.preventDefault(); // Prevent page scrolling while dragging
});

btn.addEventListener("touchend", function () {
    isTouching = false;
    clearTimeout(longPressTimer);
    btn.style.cursor = "grab";
});