CS Timer Auto-Enter (Violentmonkey + Edge Compatible)

Auto-generates and enters realistic times in CS Timer with Violentmonkey compatibility

Stan na 16-04-2025. Zobacz najnowsza wersja.

// ==UserScript==
// @name         CS Timer Auto-Enter (Violentmonkey + Edge Compatible)
// @namespace    http://tampermonkey.net/
// @version      2.9
// @description  Auto-generates and enters realistic times in CS Timer with Violentmonkey compatibility
// @author       YourName
// @license      MIT
// @match        https://cstimer.net/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    function simulateTyping(element, text, delay, callback) {
        let index = 0;
        element.value = "";

        function typeChar() {
            if (index < text.length) {
                element.value += text[index];
                index++;
                element.dispatchEvent(new Event('input')); // Trigger input event
                setTimeout(typeChar, delay);
            } else {
                if (callback) setTimeout(callback, 100); // Small delay before pressing Enter
            }
        }

        typeChar();
    }

    function generateTime() {
        let randomTime;
        let randomChance = Math.random();

        if (randomChance < 0.8) {
            randomTime = (Math.random() * (5.01 - 3.16) + 3.16).toFixed(2);
        } else {
            randomTime = (Math.random() * (6.06 - 1.84) + 1.84).toFixed(2);
        }

        document.getElementById("timeDisplay").innerText = `Generated Time: ${randomTime} seconds`;

        let timeInput = document.getElementById("inputTimer");
        if (timeInput) {
            timeInput.style.display = "inline-block";
            timeInput.focus();
            simulateTyping(timeInput, randomTime, 10, pressEnter);
        }
    }

    function pressEnter() {
        let timeInput = document.getElementById("inputTimer");
        if (timeInput) {
            timeInput.focus(); // Ensure focus before triggering event

            // Attempt multiple methods for Enter key submission
            ["keydown", "keyup"].forEach(eventType => {
                let enterKeyEvent = new KeyboardEvent(eventType, { key: "Enter", code: "Enter", bubbles: true });
                timeInput.dispatchEvent(enterKeyEvent);
            });

            // Backup method using traditional event initialization for Violentmonkey
            let legacyEnterEvent = document.createEvent("KeyboardEvent");
            legacyEnterEvent.initEvent("keydown", true, true);
            timeInput.dispatchEvent(legacyEnterEvent);

            // Alternative submission method using form event
            let form = document.querySelector("form");
            if (form) {
                form.dispatchEvent(new Event("submit", { bubbles: true }));
            }
        }
    }

    function startAutoGenerate() {
        setInterval(generateTime, 500); // Adjusted interval for Edge & Violentmonkey compatibility
    }

    function createUI() {
        let container = document.createElement("div");
        container.style = `
            position: fixed;
            bottom: 20px;
            right: 20px;
            padding: 15px;
            background: #f9f9f9;
            border: 2px solid #ccc;
            border-radius: 5px;
            z-index: 1000;
            box-shadow: 2px 2px 10px rgba(0,0,0,0.2);
            text-align: center;
        `;

        let title = document.createElement("h3");
        title.innerText = "CS Timer Auto-Enter (Edge & Violentmonkey)";
        container.appendChild(title);

        let timeDisplay = document.createElement("p");
        timeDisplay.id = "timeDisplay";
        timeDisplay.innerText = "Generated times will appear here...";
        container.appendChild(timeDisplay);

        document.body.appendChild(container);
    }

    createUI();
    startAutoGenerate();
})();