Real Chat Overlay

Chat with your friends on local host

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Real Chat Overlay
// @version      1.0
// @match        *://*/*
// @grant        none
// @namespace https://greasyfork.org/users/1594941
// @description Chat with your friends on local host
// ==/UserScript==

(function () {

    const ws = new WebSocket("ws://localhost:3000");

    const box = document.createElement("div");
    box.style = `
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 260px;
        height: 320px;
        background: rgba(0,0,0,0.85);
        color: white;
        z-index: 999999;
        font-family: Arial;
        display: flex;
        flex-direction: column;
        border-radius: 10px;
        padding: 8px;
    `;

    const log = document.createElement("div");
    log.style = `
        flex: 1;
        overflow-y: auto;
        font-size: 12px;
        margin-bottom: 6px;
    `;

    const input = document.createElement("input");
    input.placeholder = "Type message...";
    input.style = `
        padding: 6px;
        border: none;
        outline: none;
        border-radius: 5px;
    `;

    function addMsg(text) {
        const div = document.createElement("div");
        div.textContent = text;
        log.appendChild(div);
        log.scrollTop = log.scrollHeight;
    }

    ws.onmessage = (event) => {
        addMsg("Friend: " + event.data);
    };

    input.addEventListener("keydown", (e) => {
        if (e.key === "Enter" && input.value.trim()) {
            const msg = input.value;

            addMsg("You: " + msg);
            ws.send(msg);

            input.value = "";
        }
    });

    box.appendChild(log);
    box.appendChild(input);
    document.body.appendChild(box);

})();