韩网辅助输入

Suggests specific text input on kiosk.ac and nahida.live password inputs

// ==UserScript==
// @name         韩网辅助输入
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Suggests specific text input on kiosk.ac and nahida.live password inputs
// @author       Henry W
// @author       zzx114
// @match        https://kiosk.ac/*
// @match        https://nahida.live/mods*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let suggestionBox = null;
    const suggestions = ['gayshin', 'ㅎ묘노ㅑㅜ', 'GAYSHIN', '0731', '第16行添加修改密码'];

    function createSuggestions(input, buttonSelector) {
        if (suggestionBox) {
            suggestionBox.remove();
        }

        suggestionBox = document.createElement('div');
        suggestionBox.style.cssText = `
            position: absolute;
            background: #2b2b2b;
            border: 2px solid #4a4a4a;
            padding: 10px;
            border-radius: 4px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.3);
            z-index: 99999;
            font-size: 14px;
            min-width: 120px;
            margin-top: 5px;
        `;

        suggestions.forEach(text => {
            const item = document.createElement('div');
            item.textContent = text;
            item.style.cssText = `
                padding: 8px 12px;
                margin: 4px 0;
                color: #ffffff;
                background: #3a3a3a;
                border-radius: 3px;
                cursor: pointer;
                user-select: none;
                transition: all 0.2s ease;
            `;

            item.addEventListener('mouseenter', () => {
                item.style.backgroundColor = '#4a4a4a';
                item.style.transform = 'translateX(5px)';
            });

            item.addEventListener('mouseleave', () => {
                item.style.backgroundColor = '#3a3a3a';
                item.style.transform = 'translateX(0)';
            });

            item.addEventListener('mousedown', (e) => {
                e.preventDefault();
                e.stopPropagation();

                // 设置输入框的值
                input.value = text;
                input.dispatchEvent(new Event('input', { bubbles: true }));

                // 查找并点击特定按钮
                const button = buttonSelector(input);
                if (button) {
                    button.click();
                }

                // 移除建议框
                suggestionBox.remove();
                suggestionBox = null;
            });

            suggestionBox.appendChild(item);
        });

        // 将建议框放入输入框的父容器中
        input.parentElement.appendChild(suggestionBox);
    }

    function initializeKiosk() {
        const input = document.querySelector('input[placeholder="Password"]');
        if (input) {
            input.addEventListener('focus', () => createSuggestions(input, (input) => input.closest('div').querySelector('button.btn-ghost')));
        }
    }

    function initializeNahida() {
    const observer = new MutationObserver((mutations) => {
        console.log('Mutation detected:', mutations);
        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                if (node.nodeType === 1) {
                    const dialog = node.querySelector('[role=dialog]') || node.closest('.modal') || node;
                    if (dialog) {
                        console.log('Dialog found:', dialog);
                        const input = dialog.querySelector('input[placeholder=Password]') || dialog.querySelector('input.block.w-full.rounded-lg');
                        if (input) {
                            console.log('Input found:', input);
                            setTimeout(() => createSuggestions(input, (input) => dialog.querySelector('button svg.lucide-download')?.closest('button')), 500);
                        }
                    }
                }
            }
        }
    });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    // 初始化
    window.addEventListener('load', () => {
        if (window.location.hostname === 'kiosk.ac') {
            initializeKiosk();
        } else if (window.location.hostname === 'nahida.live') {
            initializeNahida();
        }
    });

    // 清理函数
    function cleanup() {
        if (suggestionBox) {
            suggestionBox.remove();
        }
    }

    // 页面卸载时清理
    window.addEventListener('unload', cleanup);
})();