Xiangqi Game Chat Automator

Automatically pastes text into the chat dialogue on Xiangqi game pages

Size

2.3 KB

Version

1.0.3

Created

Mar 30, 2026

Updated

18 days ago

1// ==UserScript==
2// @name		Xiangqi Game Chat Automator
3// @description		Automatically pastes text into the chat dialogue on Xiangqi game pages
4// @version		1.0.3
5// @match		https://*.play.xiangqi.com/*
6// @icon		https://play.xiangqi.com/icon.svg
7// ==/UserScript==
8(function() {
9    'use strict';
10    
11    let toggle = false; // Variable to track which version of text to send
12    
13    // Function to paste text into chat
14    function pasteTextToChat() {
15        // Look for the chat input element with more specific selectors
16        // Updated to match the actual chat input element found on the page
17        const chatInput = document.querySelector('input.chat-input');
18        
19        // If chat input is found, paste the text
20        if (chatInput) {
21            // Focus the input first
22            chatInput.focus();
23            
24            // Alternate between "abc-test" and " abc-test"
25            const textToSend = toggle ? ' abc-test' : 'abc-test';
26            toggle = !toggle; // Flip the toggle for next time
27            
28            // Set the value
29            chatInput.value = textToSend;
30            
31            // Trigger input event to simulate typing
32            const inputEvent = new Event('input', { bubbles: true });
33            chatInput.dispatchEvent(inputEvent);
34            
35            // Small delay before submitting
36            setTimeout(() => {
37                // Trigger keydown and keyup events for Enter key to submit
38                const keydownEvent = new KeyboardEvent('keydown', {
39                    key: 'Enter',
40                    code: 'Enter',
41                    keyCode: 13,
42                    which: 13,
43                    bubbles: true
44                });
45                const keyupEvent = new KeyboardEvent('keyup', {
46                    key: 'Enter',
47                    code: 'Enter',
48                    keyCode: 13,
49                    which: 13,
50                    bubbles: true
51                });
52                
53                chatInput.dispatchEvent(keydownEvent);
54                chatInput.dispatchEvent(keyupEvent);
55                
56                console.log(`Text "${textToSend}" pasted to chat`);
57            }, 100);
58        } else {
59            console.log('Chat input not found');
60        }
61    }
62    
63    // Run the function every 5 seconds
64    setInterval(pasteTextToChat, 5000);
65})();