Greasy Fork镜像 还支持 简体中文。

Freundesliste & Benachrichtigungen für AutoDarts

Überwacht den Online-Status von Freunden und zeigt Benachrichtigungen an

目前為 2025-01-28 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Freundesliste & Benachrichtigungen für AutoDarts
// @namespace    Owl
// @version      3.3
// @description  Überwacht den Online-Status von Freunden und zeigt Benachrichtigungen an
// @match        https://play.autodarts.io/*
// @run-at       document-idle
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

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

    let freundeListe = JSON.parse(localStorage.getItem('freundeListe')) || [];

    function saveFreundeListe() {
        localStorage.setItem('freundeListe', JSON.stringify(freundeListe));
    }

    // Popup-Variablen
    let popupVisible = false;
    let popupContainer = null;
    const MENU_ITEM_ID = 'autodarts-freundesliste-menu-item';

    // Überprüfung des Spielerstatus
    let checkTimeout = null;
    function triggerCheckWithDebounce() {
        if (checkTimeout) {
            clearTimeout(checkTimeout);
        }
        checkTimeout = setTimeout(() => {
            checkPlayers();
            checkTimeout = null;
        }, 5000);  // Alle 5 Sekunden
    }

    // Funktion zur Überprüfung von Spielern
    function checkPlayers() {
        const playerTags = document.querySelectorAll('p.chakra-text.css-0');
        let foundNames = [];

        playerTags.forEach(tag => {
            const name = tag.textContent.trim().toUpperCase();
            const friend = freundeListe.find(friend => friend.name.toUpperCase() === name);

            if (friend) {
                // Farbcodierung: Online (Grün), Im-Match (Blau), Offline (Grau)
                if (friend.status === 'online') {
                    tag.style.backgroundColor = 'green';
                    tag.style.color = 'white';
                } else if (friend.status === 'match') {
                    tag.style.backgroundColor = 'blue';
                    tag.style.color = 'white';
                } else {
                    tag.style.backgroundColor = 'grey';
                    tag.style.color = 'white';
                }
                foundNames.push(name);
            }
        });

        if (foundNames.length > 0) {
            showNotification(`Freunde online: ${foundNames.join(', ')}`);
        } else {
            removeNotification();
        }
    }

    // Benachrichtigung bei Statusänderung
    let notificationDiv = null;

    function showNotification(text) {
        if (!notificationDiv) {
            notificationDiv = document.createElement('div');
            Object.assign(notificationDiv.style, {
                position: 'fixed',
                top: '0',
                left: '0',
                width: '100%',
                backgroundColor: 'yellow',
                color: 'black',
                padding: '10px',
                textAlign: 'center',
                zIndex: '100000',
                fontSize: '16px'
            });
            document.body.appendChild(notificationDiv);
        }
        notificationDiv.textContent = `Freund online: ${text}`;
    }

    function removeNotification() {
        if (notificationDiv) {
            notificationDiv.remove();
            notificationDiv = null;
        }
    }

    // Popup zum Hinzufügen und Verwalten von Freunden
    function createPopup() {
        if (popupContainer) return;

        popupContainer = document.createElement('div');
        popupContainer.id = 'autodarts-freundesliste-popup';

        Object.assign(popupContainer.style, {
            position: 'fixed',
            left: '50%',
            top: '50%',
            transform: 'translate(-50%, -50%)',
            padding: '20px',
            backgroundColor: '#1A202C', // Dunkelgrau
            color: '#E2E8F0',
            border: '1px solid #2D3748',
            borderRadius: '8px',
            boxShadow: '0 0 10px rgba(0,0,0,0.5)',
            zIndex: '99999',
            fontFamily: 'sans-serif',
            width: 'auto',
            minWidth: '300px',
            maxWidth: '80vw',
            maxHeight: '80vh',
            overflowY: 'auto',
            display: 'none'
        });

        // Drag-Bar
        const dragBar = document.createElement('div');
        dragBar.style.height = '20px';
        dragBar.style.cursor = 'move';
        dragBar.style.marginBottom = '10px';
        popupContainer.appendChild(dragBar);

        // Schließen "X"-Button
        const closeXButton = document.createElement('button');
        closeXButton.textContent = '×';
        Object.assign(closeXButton.style, {
            position: 'absolute',
            top: '4px',
            right: '8px',
            background: 'transparent',
            border: 'none',
            color: '#E2E8F0',
            fontSize: '20px',
            lineHeight: '20px',
            cursor: 'pointer'
        });
        closeXButton.addEventListener('click', () => {
            togglePopup(false);
        });
        popupContainer.appendChild(closeXButton);

        // Titel
        const title = document.createElement('h2');
        title.textContent = 'Freundesliste';
        title.style.marginTop = '0';
        title.style.fontSize = '1.4rem';
        title.style.fontWeight = 'bold';
        popupContainer.appendChild(title);

        // Eingabebereich
        const inputWrapper = document.createElement('div');
        inputWrapper.style.display = 'flex';
        inputWrapper.style.marginBottom = '10px';
        popupContainer.appendChild(inputWrapper);

        const nameInput = document.createElement('input');
        nameInput.type = 'text';
        nameInput.placeholder = 'Name des Freundes';
        Object.assign(nameInput.style, {
            flex: '1',
            marginRight: '5px',
            padding: '4px 8px'
        });
        inputWrapper.appendChild(nameInput);

        const idInput = document.createElement('input');
        idInput.type = 'text';
        idInput.placeholder = 'Board-ID des Freundes';
        Object.assign(idInput.style, {
            flex: '1',
            marginRight: '5px',
            padding: '4px 8px'
        });
        inputWrapper.appendChild(idInput);

        const addButton = document.createElement('button');
        addButton.textContent = 'Hinzufügen';
        Object.assign(addButton.style, {
            padding: '4px 8px',
            cursor: 'pointer',
            backgroundColor: 'rgba(59, 182, 43, 1)',
            color: '#fff',
            border: 'none',
            borderRadius: '4px'
        });
        inputWrapper.appendChild(addButton);

        // Liste der Freunde
        const listElement = document.createElement('ul');
        listElement.style.listStyle = 'none';
        listElement.style.paddingLeft = '0';
        popupContainer.appendChild(listElement);

        // Freunde hinzufügen
        function addFriend() {
            const name = nameInput.value.trim();
            const id = idInput.value.trim();

            if (name && id && !freundeListe.some(friend => friend.name.toUpperCase() === name.toUpperCase())) {
                const newFriend = { name, id, status: 'offline' };
                freundeListe.push(newFriend);
                saveFreundeListe();
                updateFriendList(listElement);
            }

            nameInput.value = '';
            idInput.value = '';
        }
        addButton.addEventListener('click', addFriend);

        // Freunde aktualisieren
        function updateFriendList(listElement) {
            listElement.innerHTML = '';
            freundeListe.forEach(friend => {
                const li = document.createElement('li');
                li.textContent = friend.name;

                Object.assign(li.style, {
                    display: 'flex',
                    alignItems: 'center',
                    justifyContent: 'space-between',
                    padding: '4px 0'
                });

                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', () => {
                    if (confirm(`Möchten Sie ${friend.name} wirklich entfernen?`)) {
                        freundeListe = freundeListe.filter(f => f.name !== friend.name);
                        saveFreundeListe();
                        updateFriendList(listElement);
                    }
                });

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

        updateFriendList(listElement);

        document.body.appendChild(popupContainer);
    }

    function togglePopup(forceOpen) {
        if (!popupContainer) {
            createPopup();
        }
        popupVisible = (typeof forceOpen === 'boolean') ? forceOpen : !popupVisible;
        popupContainer.style.display = popupVisible ? 'block' : 'none';
    }

    // Menüpunkt "Freundesliste"
    function addMenuItem(menuContainer) {
        let menuItem = document.getElementById(MENU_ITEM_ID);
        if (!menuItem) {
            menuItem = document.createElement('a');
            menuItem.id = MENU_ITEM_ID;
            menuItem.textContent = 'Freundesliste';
            menuItem.style.cursor = 'pointer';
            menuContainer.appendChild(menuItem);
            menuItem.addEventListener('click', () => togglePopup());
        }
    }

    // Beobachter für das Menü
    const intervalId = setInterval(() => {
        const menuContainer = document.querySelector('div.chakra-stack');
        if (menuContainer) {
            addMenuItem(menuContainer);
            clearInterval(intervalId);
        }
    }, 1000);

    // Initiale Überprüfung
    checkPlayers();

})();

QingJ © 2025

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