Universal Movable GUI

Draggable GUI with O-key toggle on all websites

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         Universal Movable GUI
// @namespace    https://greasyfork.org/
// @version      1.0
// @description  Draggable GUI with O-key toggle on all websites
// @author       You
// @match        *://*/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    if (document.getElementById('universalGui')) return;

    const gui = document.createElement('div');
    gui.id = 'universalGui';

    Object.assign(gui.style, {
        position: 'fixed',
        top: '20px',
        left: '20px',
        width: '300px',
        background: '#1e1e1e',
        color: '#fff',
        padding: '15px',
        borderRadius: '12px',
        fontFamily: 'Arial, sans-serif',
        zIndex: '2147483647',
        boxShadow: '0 0 20px rgba(0,0,0,.5)',
        userSelect: 'none'
    });

    gui.innerHTML = `
        <div id="guiHeader" style="
            cursor:move;
            font-size:18px;
            font-weight:bold;
            margin-bottom:10px;
            border-bottom:1px solid #444;
            padding-bottom:8px;
        ">
            Universal GUI
        </div>

        <div>
            <p>Status: Ready</p>
            <p>Press <b>O</b> to show/hide</p>
            <p>Drag the title bar to move</p>
        </div>
    `;

    document.body.appendChild(gui);

    let visible = true;

    document.addEventListener('keydown', (e) => {
        if (
            e.target.tagName === 'INPUT' ||
            e.target.tagName === 'TEXTAREA' ||
            e.target.isContentEditable
        ) {
            return;
        }

        if (e.key.toLowerCase() === 'o') {
            visible = !visible;
            gui.style.display = visible ? 'block' : 'none';
        }
    });

    const header = document.getElementById('guiHeader');

    let dragging = false;
    let offsetX = 0;
    let offsetY = 0;

    header.addEventListener('mousedown', (e) => {
        dragging = true;
        offsetX = e.clientX - gui.offsetLeft;
        offsetY = e.clientY - gui.offsetTop;
    });

    document.addEventListener('mousemove', (e) => {
        if (!dragging) return;

        gui.style.left = (e.clientX - offsetX) + 'px';
        gui.style.top = (e.clientY - offsetY) + 'px';
    });

    document.addEventListener('mouseup', () => {
        dragging = false;
    });

})();