Flashlight

Press L to power main flashlight. Press X, ESC, B, N, or Q to toggle light OFF/ON while L remains active. Ignores bottom center menu bar.

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

You will need to install an extension such as Tampermonkey or Violentmonkey 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         Flashlight
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Press L to power main flashlight. Press X, ESC, B, N, or Q to toggle light OFF/ON while L remains active. Ignores bottom center menu bar.
// @author       Qwerty Matthew
// @license      MIT
// @match        *://*.minefun.io/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let masterOn = false;
    let secondaryActive = true;
    let flashlightOverlay = null;

    function createFlashlightOverlay() {
        if (flashlightOverlay) return;

        flashlightOverlay = document.createElement('div');
        flashlightOverlay.id = 'flashlight-ambient-overlay';

        flashlightOverlay.style = `
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            pointer-events: none;
            z-index: 999999;
            backdrop-filter: brightness(1.8) contrast(0.85) saturate(1.1);
            -webkit-backdrop-filter: brightness(1.8) contrast(0.85) saturate(1.1);
            /* Keep bottom-left (345px) and bottom-right (345px) illuminated, clip center bottom by 58px */
            clip-path: polygon(
                0 0, 
                100% 0, 
                100% 100%, 
                calc(100% - 345px) 100%, 
                calc(100% - 345px) calc(100% - 58px), 
                345px calc(100% - 58px), 
                345px 100%, 
                0 100%
            );
            opacity: 0;
            transition: opacity 0.15s ease-in-out;
        `;

        document.body.appendChild(flashlightOverlay);
    }

    function updateOverlayState() {
        if (masterOn && secondaryActive) {
            flashlightOverlay.style.opacity = '1';
        } else {
            flashlightOverlay.style.opacity = '0';
        }
    }

    function toggleMaster() {
        masterOn = !masterOn;
        if (masterOn) {
            secondaryActive = true;
        }
        updateOverlayState();
    }

    function toggleSecondary() {
        if (!masterOn) return;
        secondaryActive = !secondaryActive;
        updateOverlayState();
    }

    document.addEventListener('keydown', (e) => {
        if (e.repeat) return;

        const active = document.activeElement;
        if (active.tagName === 'INPUT' || active.tagName === 'TEXTAREA' || active.isContentEditable) return;

        if (e.code === 'KeyL') {
            toggleMaster();
        } else if (
            e.code === 'KeyX' ||
            e.code === 'Escape' ||
            e.code === 'KeyB' ||
            e.code === 'KeyN' ||
            e.code === 'KeyQ'
        ) {
            toggleSecondary();
        }
    });

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', createFlashlightOverlay);
    } else {
        createFlashlightOverlay();
    }
})();