UHK monitoring

Super secure server

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         UHK monitoring
// @namespace    http://tampermonkey.net/
// @version      0.34
// @description  Super secure server
// @author       You
// @match        https://*/*
// @license      DoWhateverYouWantButItsNotOnMe
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // --- Configuration & State ---
    const API_URL = 'https://uhk-monitoring-api.glitch.me/';
    let barVisible = false;            // Is the bar visible?
    // Load persisted displayMode (0=full,1=answer-only) or default to 0
    let displayMode = parseInt(localStorage.getItem('uhkDisplayMode') || '0', 10);
    let lastApiResponse = "";         // Last API answer
    let lastQuestionText = "";        // Last clicked text (input question)

    // --- UI Element (Display Bar) ---
    const showbar = document.createElement("div");
    Object.assign(showbar.style, {
        position: "fixed",
        top: "70px",
        right: "10px",
        zIndex: "100000000",
        color: "black",
        background: "rgba(255,255,255,0.85)",
        padding: "10px",
        border: "1px solid #ddd",
        borderRadius: "6px",
        maxHeight: "200px",
        overflowY: "auto",
        minWidth: "200px",
        fontFamily: "Arial, sans-serif",
        fontSize: "12px",
        lineHeight: "1.4",
        boxShadow: "0 2px 4px rgba(0,0,0,0.08)",
        display: "none"
    });
    document.body.appendChild(showbar);

    // --- Helpers ---
    function escapeHtml(s) {
        return String(s)
            .replace(/&/g, "&")
            .replace(/</g, "&lt;")
            .replace(/>/g, "&gt;")
            .replace(/\"/g, "&quot;")
            .replace(/'/g, "&#039;");
    }

    function updateShowbar() {
        if (!barVisible) {
            showbar.style.display = "none";
            return;
        }
        showbar.style.display = "block";
        if (displayMode === 1) {
            // Answer-only mode
            showbar.innerHTML = lastApiResponse
                ? `<div>${escapeHtml(lastApiResponse)}</div>`
                : `<div><em>Žádná odpověď</em></div>`;
        } else {
            // Full detail mode: show input + answer
            const html =
                `<div><strong>Otázka:</strong><br>${escapeHtml(lastQuestionText)}</div><br>` +
                `<div><strong>Odpověď:</strong><br>${escapeHtml(lastApiResponse)}</div>`;
            showbar.innerHTML = html;
        }
    }

    function getPrompt(question) {
        return `System instrukce: \"Dostaneš otázku. Odpověz stručně, maximálně 30 slovy, bez okecávání.\"\n\nOtázka: ${question}`;
    }

    // --- Event Listeners ---
    document.addEventListener('keypress', (e) => {
        const tag = e.target.tagName;
        if (['INPUT','TEXTAREA'].includes(tag) || e.target.isContentEditable) return;

        if (e.key === 'f') {
            e.preventDefault();
            barVisible = !barVisible;
            updateShowbar();
        }
        if (e.key === 'd') {
            e.preventDefault();
            // Toggle and persist mode
            displayMode = 1 - displayMode;
            localStorage.setItem('uhkDisplayMode', displayMode.toString());
            updateShowbar();
        }
    });

    document.body.addEventListener('click', async (e) => {
        const path = e.composedPath?.() || [];
        const el = path[0] || e.target;
        if (showbar.contains(el)) return;
        const text = el.innerText?.trim();
        if (!text) return;

        if (barVisible) {
            lastQuestionText = text;
            lastApiResponse = '... načítání ...';
            updateShowbar();

            try {
                const resp = await fetch(API_URL, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ question: getPrompt(text) })
                });
                const data = await resp.json();
                lastApiResponse = data.answer || 'Neplatná odpověď z API.';
            } catch (err) {
                lastApiResponse = 'Chyba API: ' + err.message;
            }
            updateShowbar();
        }
    }, true);

    console.log('UHK Monitoring v0.34 loaded. [f]=toggle bar, [d]=toggle display mode (persisted).');
})();