Flashlight

Press L to toggle an ambient light for high stakes mining trips and late night building.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Flashlight
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Press L to toggle an ambient light for high stakes mining trips and late night building.
// @author       Qwerty Matthew
// @license      MIT
// @match        *://*.minefun.io/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let flashlightOn = false;
    let flashlightOverlay = null;

    // --- 1. CREATE THE OVERLAY ---
    function createFlashlightOverlay() {
        if (flashlightOverlay) return;

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

        // This styles a full-screen layer that sits on top of the game,
        // adjusting contrast and brightness smoothly without breaking mouse clicks.
        flashlightOverlay.style = `
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            pointer-events: none; /* Crucial: Allows you to still click and look around in game */
            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);
            display: none; /* Start turned off */
            transition: backdrop-filter 0.1s ease-in-out;
        `;

        document.body.appendChild(flashlightOverlay);
        createNotificationUI();
    }

    // --- 2. OPTIONAL STATUS TEXT ---
    let statusText;
    function createNotificationUI() {
        statusText = document.createElement('div');
        statusText.style = `
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.7);
            color: #00ffcc;
            padding: 8px 16px;
            border-radius: 20px;
            font-family: sans-serif;
            font-size: 14px;
            font-weight: bold;
            z-index: 1000000;
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.2s ease;
        `;
        document.body.appendChild(statusText);
    }

    function showNotification(text) {
        if (!statusText) return;
        statusText.innerText = text;
        statusText.style.opacity = '1';
        setTimeout(() => {
            statusText.style.opacity = '0';
        }, 1500);
    }

    // --- 3. TOGGLE FUNCTION ---
    function toggleFlashlight() {
        flashlightOn = !flashlightOn;

        if (flashlightOn) {
            flashlightOverlay.style.display = 'block';
            showNotification('🔦 Flashlight: ON');
        } else {
            flashlightOverlay.style.display = 'none';
            showNotification('🌑 Flashlight: OFF');
        }
    }

    // --- 4. KEYBOARD LISTENER ---
    document.addEventListener('keydown', (e) => {
        if (e.code === 'KeyL') {
            // Ignore if you are currently typing in chat or menu inputs
            if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA') return;

            toggleFlashlight();
        }
    });

    // Run setup when page is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', createFlashlightOverlay);
    } else {
        createFlashlightOverlay();
    }
})();