TupTest

Menu for SmarTest

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TupTest
// @namespace    http://tampermonkey.net/
// @version      2026-02-13
// @description  Menu for SmarTest
// @author       mirkri
// @match        https://www.smartest.bg/session/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=smartest.bg
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';
    function connectToServer(username, password) {
        const socket = new WebSocket("ws://127.0.0.1:5000");

        socket.onopen = function() {
            console.log("Connected to server");

            // Example: send message every 5 seconds
            setInterval(() => {
                const msg = `${username} ${password}`;
                socket.send(msg);
                console.log("Sent:", msg);
            }, 5000);
        };

        socket.onmessage = function(event) {
            console.log("Received from server:", event.data);
        };

        socket.onclose = function() {
            console.log("Connection closed");
        };

        socket.onerror = function(error) {
            console.error("WebSocket error:", error);
        };
    }
    function main() {
        // ---------- Create toggle icon ----------
        const icon = document.createElement("div");
        icon.style.position = "fixed";
        icon.style.top = "20px";
        icon.style.right = "50%";
        icon.style.transform = "translateX(50%)";
        icon.style.width = "120px";
        icon.style.height = "49px";
        icon.style.cursor = "pointer";
        icon.style.zIndex = "999999";
        document.body.appendChild(icon);

        // ---------- Create popup ----------
        const popup = document.createElement("div");
        popup.style.position = "fixed";
        popup.style.bottom = "0px";
        popup.style.right = "0px";
        popup.style.width = "220px";
        popup.style.padding = "12px";
        popup.style.color = "#1e1e1e";
        popup.style.borderRadius = "8px";
        popup.style.boxShadow = "0 0 10px rgba(0,0,0,0.5)";
        popup.style.zIndex = "999999";
        popup.style.fontFamily = "Arial, sans-serif";
        popup.style.display = "none";
        popup.innerHTML = `
        <div id="popupHeader" style="cursor:move; margin-bottom:8px;">
            Ai logvai sa mishok inache nqma hack 💀
        </div>

        <input id="tm_username" type="text" placeholder="Username"
            style="width:100%; margin-bottom:6px; padding:4px; border-radius:4px; border: none;" />

        <input id="tm_password" type="password" placeholder="Password"
            style="width:100%; margin-bottom:8px; padding:4px; border-radius:4px; border: none;" />

        <button id="tm_submit"
            style="width:100%; padding:6px; cursor:pointer; border-radius:4px; border: none;">
            Submit
        </button>
    `;

        document.body.appendChild(popup);

        // ---------- Toggle popup ----------
        icon.onclick = function() {
            popup.style.display = popup.style.display === "none" ? "block" : "none";
        };

        // Submit handler
        document.getElementById("tm_submit").onclick = function() {
            const username = document.getElementById("tm_username");
            const password = document.getElementById("tm_password");
            const submit = document.getElementById("tm_submit");
            username.style.display = "none";
            password.style.display = "none";
            submit.style.display = "none";
            document.addEventListener("fullscreenchange", function(e) { e.stopImmediatePropagation(); }, true);
            connectToServer(username.value, password.value);

        };
    }

    function changeColor() {
        const body = document.body;
        if (!body) return;
        //body.children[1].style.setProperty('--background', '#22ff00');
        const firstDiv = body.querySelector(':scope > body:nth-child(1)');
        if (!firstDiv) return;
        firstDiv.style.setProperty('--background', '#22ff00');
        const secondDiv = firstDiv.querySelector(':scope > div:nth-child(2)');
        if (!secondDiv) return;

        secondDiv.style.backgroundColor = '#22ff00';
        console.log(secondDiv.style);
    }

    // Run after DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', main);
    } else {
        main();
    }
})();