The West - Kocsma Tömeges Suttogás

Tömeges privát üzenet küldése a Kocsma chaten lévő összes online játékosnak

Size

16.2 KB

Version

1.1.1

Created

Feb 4, 2026

Updated

about 1 month ago

1// ==UserScript==
2// @name		The West - Kocsma Tömeges Suttogás
3// @description		Tömeges privát üzenet küldése a Kocsma chaten lévő összes online játékosnak
4// @version		1.1.1
5// @match		https://*.hu13.the-west.hu/*
6// @icon		https://hu13.the-west.hu/favicon.ico
7// @grant		GM.getValue
8// @grant		GM.setValue
9// ==/UserScript==
10(function() {
11    'use strict';
12
13    console.log('Kocsma Tömeges Suttogás betöltve');
14
15    // Debounce függvény
16    function debounce(func, wait) {
17        let timeout;
18        return function executedFunction(...args) {
19            const later = () => {
20                clearTimeout(timeout);
21                func(...args);
22            };
23            clearTimeout(timeout);
24            timeout = setTimeout(later, wait);
25        };
26    }
27
28    // Várakozás függvény
29    function wait(ms) {
30        return new Promise(resolve => setTimeout(resolve, ms));
31    }
32
33    // UI panel létrehozása
34    function createUI() {
35        // Ellenőrizzük, hogy már létezik-e
36        if (document.getElementById('kocsma-whisper-panel')) {
37            return;
38        }
39
40        const panel = document.createElement('div');
41        panel.id = 'kocsma-whisper-panel';
42        panel.innerHTML = `
43            <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 15px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.3); color: white; font-family: Arial, sans-serif; min-width: 300px;">
44                <h3 style="margin: 0 0 15px 0; font-size: 16px; text-align: center; text-shadow: 1px 1px 2px rgba(0,0,0,0.3);">🗨️ Tömeges Suttogás</h3>
45                
46                <div style="margin-bottom: 12px;">
47                    <label style="display: block; margin-bottom: 5px; font-size: 13px; font-weight: bold;">Üzenet:</label>
48                    <textarea id="whisper-message" style="width: 100%; padding: 8px; border: none; border-radius: 4px; font-size: 13px; resize: vertical; min-height: 60px; box-sizing: border-box;" placeholder="Írd be az üzenetet..."></textarea>
49                </div>
50                
51                <div style="margin-bottom: 12px;">
52                    <label style="display: block; margin-bottom: 5px; font-size: 13px; font-weight: bold;">Késleltetés (másodperc):</label>
53                    <input type="number" id="whisper-delay" value="2" min="1" max="10" style="width: 100%; padding: 8px; border: none; border-radius: 4px; font-size: 13px; box-sizing: border-box;">
54                </div>
55                
56                <div style="margin-bottom: 12px;">
57                    <button id="start-whisper-btn" style="width: 100%; padding: 10px; background: #48bb78; color: white; border: none; border-radius: 4px; font-size: 14px; font-weight: bold; cursor: pointer; transition: all 0.3s;">
58                        ▶️ Küldés Indítása
59                    </button>
60                </div>
61                
62                <div style="margin-bottom: 12px;">
63                    <button id="stop-whisper-btn" style="width: 100%; padding: 10px; background: #f56565; color: white; border: none; border-radius: 4px; font-size: 14px; font-weight: bold; cursor: pointer; transition: all 0.3s; display: none;">
64                        ⏹️ Leállítás
65                    </button>
66                </div>
67                
68                <div id="whisper-status" style="background: rgba(0,0,0,0.2); padding: 10px; border-radius: 4px; font-size: 12px; min-height: 40px; max-height: 100px; overflow-y: auto;">
69                    <div style="opacity: 0.8;">Várakozás...</div>
70                </div>
71                
72                <div style="margin-top: 10px; text-align: center; font-size: 11px; opacity: 0.7;">
73                    Összesen: <span id="total-players">0</span> játékos | Elküldve: <span id="sent-count">0</span>
74                </div>
75            </div>
76        `;
77
78        panel.style.cssText = `
79            position: fixed;
80            top: 100px;
81            right: 20px;
82            z-index: 99999;
83            box-shadow: 0 8px 32px rgba(0,0,0,0.4);
84        `;
85
86        document.body.appendChild(panel);
87
88        // Hover effektek
89        const startBtn = document.getElementById('start-whisper-btn');
90        const stopBtn = document.getElementById('stop-whisper-btn');
91        
92        startBtn.addEventListener('mouseenter', () => {
93            startBtn.style.background = '#38a169';
94            startBtn.style.transform = 'scale(1.02)';
95        });
96        startBtn.addEventListener('mouseleave', () => {
97            startBtn.style.background = '#48bb78';
98            startBtn.style.transform = 'scale(1)';
99        });
100        
101        stopBtn.addEventListener('mouseenter', () => {
102            stopBtn.style.background = '#e53e3e';
103            stopBtn.style.transform = 'scale(1.02)';
104        });
105        stopBtn.addEventListener('mouseleave', () => {
106            stopBtn.style.background = '#f56565';
107            stopBtn.style.transform = 'scale(1)';
108        });
109
110        console.log('UI panel létrehozva');
111    }
112
113    // Státusz frissítése
114    function updateStatus(message, type = 'info') {
115        const statusDiv = document.getElementById('whisper-status');
116        if (!statusDiv) return;
117
118        const colors = {
119            info: '#60a5fa',
120            success: '#48bb78',
121            error: '#f56565',
122            warning: '#f59e0b'
123        };
124
125        const timestamp = new Date().toLocaleTimeString('hu-HU');
126        const statusMessage = document.createElement('div');
127        statusMessage.style.cssText = `
128            margin-bottom: 5px;
129            padding: 5px;
130            background: rgba(0,0,0,0.2);
131            border-radius: 3px;
132            border-left: 3px solid ${colors[type]};
133        `;
134        statusMessage.innerHTML = `<span style="opacity: 0.7;">[${timestamp}]</span> ${message}`;
135        
136        statusDiv.insertBefore(statusMessage, statusDiv.firstChild);
137        
138        // Maximum 10 üzenet megjelenítése
139        while (statusDiv.children.length > 10) {
140            statusDiv.removeChild(statusDiv.lastChild);
141        }
142    }
143
144    // Online játékosok összegyűjtése
145    function getOnlinePlayers() {
146        const players = [];
147        const contactElements = document.querySelectorAll('.chat_contacts .contact_client');
148        
149        console.log(`Talált contact elemek: ${contactElements.length}`);
150        
151        contactElements.forEach(element => {
152            // Ellenőrizzük, hogy online-e a játékos
153            const statusElement = element.querySelector('.client_status');
154            const nameElement = element.querySelector('.client_name');
155            
156            if (nameElement) {
157                const playerName = nameElement.textContent.trim();
158                const isOnline = statusElement && statusElement.getAttribute('title') === 'Online';
159                
160                // Csak az online játékosokat adjuk hozzá
161                if (isOnline) {
162                    // Megkeressük a parent div-et, ami tartalmazza a client ID-t
163                    const parentDiv = element.closest('[class*="contact_client_"]');
164                    if (parentDiv) {
165                        const classMatch = parentDiv.className.match(/contact_client_(\d+)/);
166                        if (classMatch) {
167                            const clientId = classMatch[1];
168                            players.push({
169                                name: playerName,
170                                element: element,
171                                clientId: clientId
172                            });
173                            console.log(`Online játékos hozzáadva: ${playerName} (ID: ${clientId})`);
174                        }
175                    }
176                }
177            }
178        });
179        
180        console.log(`Összesen ${players.length} online játékos találva`);
181        return players;
182    }
183
184    // Üzenet küldése egy játékosnak
185    async function sendWhisperToPlayer(player, message) {
186        try {
187            console.log(`Suttogás küldése: ${player.name}`);
188            
189            // Kattintás a játékosra a privát chat megnyitásához - több eseményt triggerelünk
190            const clickEvent = new MouseEvent('click', {
191                bubbles: true,
192                cancelable: true,
193                view: window,
194                detail: 1
195            });
196            player.element.dispatchEvent(clickEvent);
197            
198            // Dupla kattintás is próbáljuk
199            const dblClickEvent = new MouseEvent('dblclick', {
200                bubbles: true,
201                cancelable: true,
202                view: window
203            });
204            player.element.dispatchEvent(dblClickEvent);
205            
206            await wait(1500); // Várunk, hogy megnyíljon a chat tab
207            
208            // Megkeressük a megfelelő chat tab-ot
209            const chatTab = document.querySelector(`#tab_title_client_${player.clientId}`);
210            if (chatTab) {
211                console.log(`Chat tab megtalálva: ${player.name}`);
212                chatTab.click();
213                await wait(500);
214            } else {
215                console.log(`Chat tab NEM található: ${player.name}`);
216                // Ha nem nyílt meg a tab, próbáljuk a játékos nevére kattintani
217                const playerNameElement = player.element.querySelector('.client_name');
218                if (playerNameElement) {
219                    playerNameElement.click();
220                    await wait(1500);
221                }
222            }
223            
224            // Megkeressük a chat input mezőt
225            const chatInput = document.querySelector('.chat_room.client_' + player.clientId + ' .chat_input input.message');
226            if (!chatInput) {
227                // Ha nem találjuk a specifikus input-ot, próbáljuk az általánost
228                const generalInput = document.querySelector('.chat_input input.message');
229                if (generalInput) {
230                    generalInput.value = message;
231                    generalInput.focus();
232                    
233                    // Enter billentyű szimulálása
234                    const enterEvent = new KeyboardEvent('keydown', {
235                        key: 'Enter',
236                        code: 'Enter',
237                        keyCode: 13,
238                        which: 13,
239                        bubbles: true
240                    });
241                    generalInput.dispatchEvent(enterEvent);
242                    
243                    await wait(300);
244                    
245                    console.log(`Üzenet elküldve: ${player.name}`);
246                    return true;
247                }
248                console.error(`Chat input mező nem található: ${player.name}`);
249                throw new Error('Chat input mező nem található');
250            }
251            
252            // Üzenet beírása
253            chatInput.value = message;
254            chatInput.focus();
255            
256            // Enter billentyű szimulálása
257            const enterEvent = new KeyboardEvent('keydown', {
258                key: 'Enter',
259                code: 'Enter',
260                keyCode: 13,
261                which: 13,
262                bubbles: true
263            });
264            chatInput.dispatchEvent(enterEvent);
265            
266            await wait(300);
267            
268            console.log(`Üzenet elküldve: ${player.name}`);
269            return true;
270            
271        } catch (error) {
272            console.error(`Hiba történt ${player.name} játékosnál:`, error);
273            return false;
274        }
275    }
276
277    // Tömeges suttogás indítása
278    let isRunning = false;
279    let shouldStop = false;
280
281    async function startMassWhisper() {
282        if (isRunning) {
283            updateStatus('Már fut egy küldési folyamat!', 'warning');
284            return;
285        }
286
287        const message = document.getElementById('whisper-message').value.trim();
288        const delay = parseInt(document.getElementById('whisper-delay').value) * 1000;
289
290        if (!message) {
291            updateStatus('Kérlek, adj meg egy üzenetet!', 'error');
292            return;
293        }
294
295        // Ellenőrizzük, hogy nyitva van-e a Kocsma chat
296        const kocsmaChatWindow = document.querySelector('.chat_room.room_general_1');
297        if (!kocsmaChatWindow) {
298            updateStatus('Nyisd meg a Kocsma chat ablakot!', 'error');
299            return;
300        }
301
302        // Ellenőrizzük, hogy látható-e a játékosok listája
303        const chatSide = kocsmaChatWindow.querySelector('.chat_side.contact_open');
304        if (!chatSide) {
305            updateStatus('Nyisd meg a játékosok listáját a chat ablakban!', 'error');
306            return;
307        }
308
309        const players = getOnlinePlayers();
310        
311        if (players.length === 0) {
312            updateStatus('Nem található online játékos!', 'error');
313            return;
314        }
315
316        isRunning = true;
317        shouldStop = false;
318        
319        // UI frissítése
320        document.getElementById('start-whisper-btn').style.display = 'none';
321        document.getElementById('stop-whisper-btn').style.display = 'block';
322        document.getElementById('total-players').textContent = players.length;
323        document.getElementById('sent-count').textContent = '0';
324        
325        updateStatus(`Küldés indítása ${players.length} játékosnak...`, 'info');
326
327        let sentCount = 0;
328
329        for (let i = 0; i < players.length; i++) {
330            if (shouldStop) {
331                updateStatus('Küldés leállítva a felhasználó által', 'warning');
332                break;
333            }
334
335            const player = players[i];
336            updateStatus(`Küldés: ${player.name} (${i + 1}/${players.length})`, 'info');
337            
338            const success = await sendWhisperToPlayer(player, message);
339            
340            if (success) {
341                sentCount++;
342                document.getElementById('sent-count').textContent = sentCount;
343                updateStatus(`✓ Elküldve: ${player.name}`, 'success');
344            } else {
345                updateStatus(`✗ Sikertelen: ${player.name}`, 'error');
346            }
347
348            // Várunk a következő üzenet előtt (kivéve az utolsónál)
349            if (i < players.length - 1 && !shouldStop) {
350                await wait(delay);
351            }
352        }
353
354        if (!shouldStop) {
355            updateStatus(`✓ Befejezve! ${sentCount}/${players.length} üzenet elküldve`, 'success');
356        }
357
358        // UI visszaállítása
359        isRunning = false;
360        document.getElementById('start-whisper-btn').style.display = 'block';
361        document.getElementById('stop-whisper-btn').style.display = 'none';
362    }
363
364    function stopMassWhisper() {
365        shouldStop = true;
366        updateStatus('Leállítás folyamatban...', 'warning');
367    }
368
369    // Inicializálás
370    async function init() {
371        console.log('Inicializálás...');
372        
373        // Várunk, amíg betöltődik az oldal
374        await wait(2000);
375        
376        // UI létrehozása
377        createUI();
378        
379        // Mentett értékek betöltése
380        const savedMessage = await GM.getValue('whisper_message', '');
381        const savedDelay = await GM.getValue('whisper_delay', 2);
382        
383        if (savedMessage) {
384            document.getElementById('whisper-message').value = savedMessage;
385        }
386        document.getElementById('whisper-delay').value = savedDelay;
387        
388        // Event listenerek
389        document.getElementById('start-whisper-btn').addEventListener('click', startMassWhisper);
390        document.getElementById('stop-whisper-btn').addEventListener('click', stopMassWhisper);
391        
392        // Értékek mentése változáskor
393        document.getElementById('whisper-message').addEventListener('input', debounce(async (e) => {
394            await GM.setValue('whisper_message', e.target.value);
395        }, 500));
396        
397        document.getElementById('whisper-delay').addEventListener('change', async (e) => {
398            await GM.setValue('whisper_delay', parseInt(e.target.value));
399        });
400        
401        updateStatus('Kész! Állítsd be az üzenetet és indítsd el a küldést.', 'success');
402        console.log('Inicializálás befejezve');
403    }
404
405    // Indítás, amikor az oldal betöltődött
406    if (document.readyState === 'loading') {
407        document.addEventListener('DOMContentLoaded', init);
408    } else {
409        init();
410    }
411
412})();