Freundesliste & Info für AutoDarts

Suche nach Spielernamen und zeige eine Info-Nachricht an, wenn sie gefunden werden.

当前为 2025-01-27 提交的版本,查看 最新版本

// ==UserScript==
// @name         Freundesliste & Info für AutoDarts
// @namespace    Owl
// @version      4.1
// @description  Suche nach Spielernamen und zeige eine Info-Nachricht an, wenn sie gefunden werden.
// @match        https://play.autodarts.io/*
// @run-at       document-idle
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    console.log("[Freundesliste Script] Starte...");

    let friendList = JSON.parse(localStorage.getItem('friendList')) || [];
    let infoDiv = null;

    // Speicher-Funktion für die Freundesliste
    function savePlayerList() {
        localStorage.setItem('friendList', JSON.stringify(friendList));
    }

    // Info-Balken anzeigen
    function showInfo(text) {
        if (!infoDiv) {
            infoDiv = document.createElement('div');
            Object.assign(infoDiv.style, {
                position: 'fixed',
                top: '0',
                left: '0',
                width: '100%',
                backgroundColor: 'blue',
                color: 'white',
                padding: '10px',
                textAlign: 'center',
                zIndex: '100000',
                fontSize: '16px'
            });
            document.body.appendChild(infoDiv);
        }
        infoDiv.textContent = `Online: ${text}`;
        setTimeout(() => removeInfo(), 25000);
    }

    // Info-Balken entfernen
    function removeInfo() {
        if (infoDiv) {
            infoDiv.remove();
            infoDiv = null;
        }
    }

    // Überprüfen, ob wir auf den richtigen Seiten sind
    function isOnSpecialPage() {
        const path = window.location.pathname;
        return path === '/matches' || path === '/lobbies' || path === '/tournaments' || path === '/boards';
    }

    // Namen in der Freundesliste anzeigen und die Farben aktualisieren
    function updateList(listElement) {
        listElement.innerHTML = '';

        // Liste alphabetisch sortieren, aber online Spieler nach oben verschieben
        friendList.sort((a, b) => {
            // Zuerst nach Online-Status sortieren: online (grün) nach oben
            if (a.online === b.online) {
                return a.name.localeCompare(b.name);  // Alphabetisch sortieren
            }
            return a.online ? -1 : 1; // Online-Spieler nach oben verschieben
        });

        friendList.forEach(item => {
            const li = document.createElement('li');
            li.textContent = item.name;

            // Farbe basierend auf dem Online-Status: Grün wenn online, Blau wenn im Match, Grau wenn offline
            Object.assign(li.style, {
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'space-between',
                padding: '4px 0',
                color: item.online === 'inLobby' ? 'green' :
                      item.online === 'inMatch' ? 'blue' : 'gray'
            });

            const followButton = document.createElement('a');
            followButton.href = `https://play.autodarts.io/boards/${item.boardId}/follow`;
            followButton.target = '_blank';
            followButton.textContent = 'Match anschauen';
            followButton.style.backgroundColor = '#4299E1';
            followButton.style.color = '#fff';
            followButton.style.border = 'none';
            followButton.style.padding = '4px 8px';
            followButton.style.borderRadius = '4px';
            li.appendChild(followButton);

            const removeBtn = document.createElement('button');
            removeBtn.textContent = 'X';
            Object.assign(removeBtn.style, {
                marginLeft: '10px',
                backgroundColor: '#C53030',
                color: '#fff',
                border: 'none',
                borderRadius: '4px',
                padding: '2px 8px',
                cursor: 'pointer'
            });

            removeBtn.addEventListener('click', () => {
                const confirmDelete = window.confirm(`Möchtest du ${item.name} wirklich aus der Freundesliste entfernen?`);
                if (confirmDelete) {
                    friendList = friendList.filter(player => player.name !== item.name);
                    savePlayerList();
                    updateList(listElement);
                }
            });

            li.appendChild(removeBtn);
            listElement.appendChild(li);
        });
    }

    // Spieler überprüfen und die Farben aktualisieren
    function checkPlayers() {
        const playerTags = document.querySelectorAll('p.chakra-text.css-0');
        let foundNames = [];

        playerTags.forEach(tag => {
            const name = tag.textContent.trim().toUpperCase();
            const friend = friendList.find(item => item.name === name);
            if (friend) {
                // Wenn Spieler gefunden wird, Blau markieren
                tag.style.backgroundColor = 'blue';
                tag.style.color = 'white';
                friend.online = 'inMatch'; // Markiere den Spieler als im Match
                foundNames.push(name);
            } else {
                tag.style.backgroundColor = '';
                tag.style.color = '';
            }
        });

        // Info-Balken nur auf den richtigen Seiten anzeigen
        if (isOnSpecialPage() && foundNames.length > 0) {
            showInfo(`Spieler online: ${foundNames.join(', ')}`);
        } else {
            removeInfo();
        }

        // Freundesliste nach Online-Status und alphabetisch aktualisieren
        updateFriendStatus(foundNames);
    }

    // Status in der Freundesliste aktualisieren (Grün für online, Blau für im Match, Grau für offline)
    function updateFriendStatus(onlineNames) {
        friendList.forEach(friend => {
            if (onlineNames.includes(friend.name.toUpperCase())) {
                friend.online = 'inMatch';
            } else {
                friend.online = 'offline';
            }
        });
        savePlayerList();
    }

    // Alle 5 Sekunden wird das Popup automatisch aktualisiert, wenn es geöffnet ist
    function updatePopup() {
        setInterval(() => {
            updateList(popupContainer.querySelector('ul'));
        }, 5000);  // Alle 5 Sekunden
    }

    // Rest des Codes bleibt wie gehabt...
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址