WikiGacha BOT

Automatically open packs and watch ad to refil (made with AI)

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         WikiGacha BOT
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Automatically open packs and watch ad to refil (made with AI)
// @name:ru         Wiki Gacha Бот
// @description:ru  Автоматизация открытия паков и рефилла для Wiki Gacha. Меню на Material You.
// @author       Darknifus339
// @match        https://wikigacha.com/*
// @license      MIT
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // --- 1. ПЕРЕХВАТ ALERT ---
    const killAlert = (win) => {
        try { win.alert = (msg) => { console.log("-> [WikiGachaBot] Alert blocked:", msg); }; } catch(e) {}
    };
    killAlert(window);
    if (typeof unsafeWindow !== 'undefined') killAlert(unsafeWindow);
    setInterval(() => { if (window.alert.toString().includes('[native code]')) killAlert(window); }, 100);

    // --- 2. КОНФИГ И ЛОКАЛИЗАЦИЯ ---
    let config = {
        enabled: GM_getValue('wg_enabled', true),
        delay: GM_getValue('wg_delay', 1800),
        autoAd: GM_getValue('wg_autoAd', true),
        lang: GM_getValue('wg_lang', 'RU')
    };

    const i18n = {
        RU: {
            header: "WikiGacha Бот",
            farm: "Включить фарм",
            delay: "Задержка (мс)",
            refill: "Авто-рефилл",
            status_on: "Работает",
            status_off: "Остановлен",
            status_ad: "Смотрю рекламу...",
            status_back: "Возвращаюсь..."
        },
        EN: {
            header: "WikiGacha Bot",
            farm: "Enable Farm",
            delay: "Delay (ms)",
            refill: "Auto-Refill",
            status_on: "Running",
            status_off: "Stopped",
            status_ad: "Watching Ad...",
            status_back: "Going back..."
        }
    };

    const save = () => {
        GM_setValue('wg_enabled', config.enabled);
        GM_setValue('wg_delay', config.delay);
        GM_setValue('wg_autoAd', config.autoAd);
        GM_setValue('wg_lang', config.lang);
    };

    // --- 3. GUI ---
    const setupGUI = () => {
        if (document.getElementById('wg-dark-gui')) return;

        const gui = document.createElement('div');
        gui.id = 'wg-dark-gui';
        updateGUIText(gui);
        document.body.appendChild(gui);

        const style = document.createElement('style');
        style.innerHTML = `
            #wg-dark-gui {
                position: fixed; top: 20px; right: 20px;
                width: 260px; background: #1a1c1e; color: #e2e2e6;
                border-radius: 24px; padding: 16px; z-index: 100000;
                font-family: 'Segoe UI', Roboto, sans-serif;
                box-shadow: 0 8px 32px rgba(0,0,0,0.4);
                letter-spacing: normal !important; cursor: grab;
                user-select: none; border: 1px solid #44474e;
            }
            .wg-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
            .wg-header { font-size: 16px; font-weight: 600; color: #d1e4ff; letter-spacing: 0 !important; }
            .wg-lang-btn {
                background: #2f3033; border: 1px solid #44474e; color: #d1e4ff;
                padding: 2px 8px; border-radius: 8px; font-size: 11px; cursor: pointer;
                transition: 0.2s;
            }
            .wg-lang-btn:hover { background: #3f4043; }
            .wg-item {
                display: flex; justify-content: space-between; align-items: center;
                margin-bottom: 12px; padding: 10px 14px; background: #2f3033; border-radius: 16px;
            }
            .wg-item span { font-size: 13px; font-weight: 500; letter-spacing: 0 !important; color: #c2c7cf; }
            .switch { position: relative; display: inline-block; width: 40px; height: 22px; }
            .switch input { opacity: 0; width: 0; height: 0; }
            .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #44474e; transition: .3s; border-radius: 20px; }
            .slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: #c2c7cf; transition: .3s; border-radius: 50%; }
            input:checked + .slider { background-color: #004977; }
            input:checked + .slider:before { transform: translateX(18px); background-color: #d1e4ff; }
            input[type="number"] { width: 65px; border: 1px solid #44474e; background: #1a1c1e; border-radius: 8px; padding: 4px; font-size: 13px; text-align: center; color: #d1e4ff; }
            .wg-status { text-align: center; font-size: 11px; margin-top: 8px; color: #8e9199; font-style: italic; letter-spacing: 0 !important; }
        `;
        document.head.appendChild(style);

        addEventListeners();
    };

    function updateGUIText(targetEl) {
        const t = i18n[config.lang];
        const html = `
            <div class="wg-header-row">
                <div class="wg-header">${t.header}</div>
                <button id="wg-lang-toggle" class="wg-lang-btn">${config.lang === 'RU' ? 'EN' : 'RU'}</button>
            </div>
            <div class="wg-content">
                <div class="wg-item">
                    <span>${t.farm}</span>
                    <label class="switch">
                        <input type="checkbox" id="wg-enabled" ${config.enabled ? 'checked' : ''}>
                        <span class="slider"></span>
                    </label>
                </div>
                <div class="wg-item">
                    <span>${t.delay}</span>
                    <input type="number" id="wg-delay" value="${config.delay}" step="100" min="500">
                </div>
                <div class="wg-item">
                    <span>${t.refill}</span>
                    <label class="switch">
                        <input type="checkbox" id="wg-autoAd" ${config.autoAd ? 'checked' : ''}>
                        <span class="slider"></span>
                    </label>
                </div>
                <div id="wg-status" class="wg-status">${config.enabled ? t.status_on : t.status_off}</div>
            </div>
        `;
        targetEl.innerHTML = html;
    }

    function addEventListeners() {
        const gui = document.getElementById('wg-dark-gui');

        gui.querySelector('#wg-lang-toggle').onclick = () => {
            config.lang = config.lang === 'RU' ? 'EN' : 'RU';
            save();
            updateGUIText(gui);
            addEventListeners(); // перепривязываем события после перерисовки
        };

        const updateStatus = (textKey) => {
            const statusEl = document.getElementById('wg-status');
            if (statusEl) statusEl.textContent = i18n[config.lang][textKey];
        };

        gui.querySelector('#wg-enabled').onchange = e => {
            config.enabled = e.target.checked;
            save();
            updateStatus(config.enabled ? 'status_on' : 'status_off');
        };
        gui.querySelector('#wg-autoAd').onchange = e => { config.autoAd = e.target.checked; save(); };
        gui.querySelector('#wg-delay').onchange = e => { config.delay = e.target.value; save(); restart(); };

        // DRAG
        let isDragging = false, offset = { x: 0, y: 0 };
        gui.onmousedown = e => {
            if (e.target.tagName === 'INPUT' || e.target.tagName === 'BUTTON' || e.target.closest('.switch')) return;
            isDragging = true; offset.x = e.clientX - gui.offsetLeft; offset.y = e.clientY - gui.offsetTop;
        };
        document.onmousemove = e => { if (isDragging) { gui.style.left = (e.clientX - offset.x) + 'px'; gui.style.top = (e.clientY - offset.y) + 'px'; gui.style.right = 'auto'; } };
        document.onmouseup = () => isDragging = false;
    }

    // --- 4. ЛОГИКА ---
    let interval;
    const restart = () => {
        clearInterval(interval);
        interval = setInterval(() => {
            if (!config.enabled) return;
            const pack = document.querySelector('img[alt="Wiki Pack"]');
            const btns = Array.from(document.querySelectorAll('button'));
            const back = btns.find(b => b.innerText.includes('BACK TO PACKS'));
            const refill = btns.find(b => b.innerText.includes('Watch Ad to Refill'));
            const close = btns.find(b => b.innerText.includes('Close Ad'));

            if (close) close.click();
            else if (refill && config.autoAd) refill.click();
            else if (pack) pack.click();
            else if (back) back.click();
        }, config.delay);
    };

    const init = () => {
        if (document.body) { setupGUI(); restart(); }
        else { setTimeout(init, 100); }
    };
    init();
})();