Emerald Auto Next

Auto-start new chat on disconnect and keep chat input focused.

当前为 2024-12-10 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            Emerald Auto Next
// @namespace       https://greasyfork.org/
// @version         1.2
// @description     Auto-start new chat on disconnect and keep chat input focused.

// @author          Zach
// @license         Apache-2.0
// @icon            https://emeraldchat.com/logo7.svg

// @match           https://emeraldchat.com/app

// @grant           none

// @compatible      Firefox
// @compatible      Violentmonkey

// ==/UserScript==

'use strict';

function randomTimeout(min, max) {
    const minMs = min * 1000;
    const maxMs = max * 1000;
    return Math.floor(Math.random() * (maxMs - minMs + 1)) + minMs;
}

function simulateClick(element) {
    const mouseDown = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
    const mouseUp = new MouseEvent('mouseup', { bubbles: true, cancelable: true });
    const clickEvent = new MouseEvent('click', { bubbles: true, cancelable: true });

    element.dispatchEvent(mouseDown);
    element.dispatchEvent(mouseUp);
    element.dispatchEvent(clickEvent);
}

function giveKarma() {
    const [good, bad] = document.querySelectorAll("a.ui-button-match-mega");
    if (!good || !bad) return;

    const messages = document.querySelectorAll("#messages > .room-component-message-container").length;
    if (messages > 3) {
        simulateClick(good);
    }
    else {
        simulateClick(bad);
    }
}

function nextChat() {
    const startButton = document.querySelector(".ui-button-match");
    if (!startButton) return;

    if (startButton.textContent === "Start") {
        setTimeout(() => simulateClick(startButton), 1500);
    }
}

function focusChat() {
    const chatInput = document.getElementById("room-input");
    if (!chatInput) return;

    document.body.addEventListener("keydown", () => {
        if (!document.querySelector("#ui-hatch > *, #ui-hatch-2 > *, #interests")) {
            chatInput.focus();
        }
    }, { once: true });
}

function observeChanges() {
    const container = document.getElementById("container");
    if (!container) return;

    const observer = new MutationObserver(() => {
        giveKarma();
        nextChat();
        focusChat();
    });

    observer.observe(container, { childList: true, subtree: true });
}

window.onload = () => {
    observeChanges();
};