Custom GUI Dashboard

Persistent menu with custom keybinds and saved text

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Custom GUI Dashboard
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Persistent menu with custom keybinds and saved text
// @author       You
// @match        *://*/*
// @license      MIT
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    // --- 1. Load Saved Data ---
    let savedKey = GM_getValue("menuKey", "ShiftRight");
    let savedText = GM_getValue("userText", "");

    // --- 2. Create UI Elements ---
    const gui = document.createElement('div');
    gui.id = "tm-gui-wrapper";
    
    // Inject Styles
    const style = document.createElement('style');
    style.innerHTML = `
        #tm-gui-wrapper {
            position: fixed; bottom: 20px; right: 20px;
            background: #222; color: white; padding: 15px;
            border-radius: 8px; font-family: sans-serif;
            box-shadow: 0 4px 15px rgba(0,0,0,0.5);
            z-index: 999999; border: 1px solid #444;
            min-width: 200px; display: none; /* Hidden by default */
        }
        #tm-helper-tip {
            position: fixed; bottom: 10px; right: 10px;
            background: rgba(0,0,0,0.7); color: #fff;
            padding: 5px 10px; border-radius: 4px;
            font-size: 12px; z-index: 999998;
        }
        .tm-field { margin-bottom: 10px; }
        .tm-field label { display: block; font-size: 11px; color: #aaa; }
        .tm-field input, .tm-field textarea {
            width: 100%; background: #333; border: 1px solid #555;
            color: white; padding: 5px; border-radius: 3px;
        }
    `;
    document.head.appendChild(style);

    // GUI Content
    gui.innerHTML = `
        <div style="font-weight:bold; margin-bottom:10px; border-bottom:1px solid #444;">Settings Menu</div>
        <div class="tm-field">
            <label>Menu Keybind (e.g. ShiftRight, KeyM)</label>
            <input type="text" id="tm-keybind-input" value="${savedKey}">
        </div>
        <div class="tm-field">
            <label>Your Saved Notes</label>
            <textarea id="tm-text-input" rows="4">${savedText}</textarea>
        </div>
        <div style="font-size:10px; color: #888;">Data saves automatically.</div>
    `;

    // Helper Tip
    const tip = document.createElement('div');
    tip.id = "tm-helper-tip";
    tip.innerText = `Press ${savedKey} to Open Menu`;
    
    document.body.appendChild(gui);
    document.body.appendChild(tip);

    // --- 3. Logic & Events ---

    const keyInput = document.getElementById('tm-keybind-input');
    const textInput = document.getElementById('tm-text-input');

    // Toggle Menu
    window.addEventListener('keydown', (e) => {
        // Check if we are typing in an input (don't trigger menu while typing)
        if (document.activeElement.tagName === "INPUT" || document.activeElement.tagName === "TEXTAREA") {
            if (document.activeElement !== keyInput) return;
        }

        if (e.code === savedKey) {
            e.preventDefault();
            const isVisible = gui.style.display === 'block';
            gui.style.display = isVisible ? 'none' : 'block';
        }
    });

    // Save Text on change
    textInput.addEventListener('input', () => {
        GM_setValue("userText", textInput.value);
    });

    // Change Keybind Logic
    keyInput.addEventListener('keydown', (e) => {
        e.preventDefault();
        savedKey = e.code;
        keyInput.value = savedKey;
        tip.innerText = `Press ${savedKey} to Open Menu`;
        GM_setValue("menuKey", savedKey);
    });

})();