// ==UserScript==
// @name Freundesliste & Info für AutoDarts
// @namespace Owl
// @version 4.0
// @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;
}
}
// 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) => {
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, Grau wenn offline
Object.assign(li.style, {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '4px 0',
color: item.online ? 'green' : 'gray' // Grün für online, grau für offline
});
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();
console.log("Überprüfe Spieler:", name); // Debugging-Ausgabe
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 = true; // Markiere den Spieler als online
foundNames.push(name);
} else {
tag.style.backgroundColor = '';
tag.style.color = '';
}
});
// Info-Balken nur auf den richtigen Seiten anzeigen
if (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, Grau für offline)
function updateFriendStatus(onlineNames) {
friendList.forEach(friend => {
const wasOnline = friend.online;
friend.online = onlineNames.includes(friend.name.toUpperCase());
if (friend.online !== wasOnline) {
console.log(`${friend.name} ist jetzt ${friend.online ? 'online' : 'offline'}`);
}
});
savePlayerList();
}
// Popup-Funktion für die Freundesliste
let popupContainer = null;
function createPopup() {
if (popupContainer) return;
popupContainer = document.createElement('div');
popupContainer.id = 'autodarts-friendlist-popup';
Object.assign(popupContainer.style, {
position: 'fixed',
left: '50%',
top: '50%',
transform: 'translate(-50%, -50%)',
padding: '20px',
backgroundColor: '#1A202C',
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'
});
const title = document.createElement('h2');
title.textContent = 'FREUNDESLISTE';
title.style.marginTop = '0';
title.style.fontSize = '1.4rem';
title.style.fontWeight = 'bold';
popupContainer.appendChild(title);
const inputWrapper = document.createElement('div');
inputWrapper.style.display = 'flex';
inputWrapper.style.marginBottom = '10px';
popupContainer.appendChild(inputWrapper);
const inputName = document.createElement('input');
inputName.type = 'text';
inputName.placeholder = 'Spielername';
Object.assign(inputName.style, {
flex: '1',
marginRight: '5px',
padding: '4px 8px'
});
inputWrapper.appendChild(inputName);
const inputBoardId = document.createElement('input');
inputBoardId.type = 'text';
inputBoardId.placeholder = 'Board ID';
Object.assign(inputBoardId.style, {
flex: '1',
marginRight: '5px',
padding: '4px 8px'
});
inputWrapper.appendChild(inputBoardId);
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);
const listElement = document.createElement('ul');
listElement.style.listStyle = 'none';
listElement.style.paddingLeft = '0';
popupContainer.appendChild(listElement);
function addFriend() {
const name = inputName.value.trim();
const boardId = inputBoardId.value.trim();
if (name && boardId) {
friendList.push({ name: name.toUpperCase(), boardId, online: false });
savePlayerList();
updateList(listElement);
}
inputName.value = '';
inputBoardId.value = '';
}
addButton.addEventListener('click', addFriend);
inputName.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
addFriend();
}
});
updateList(listElement);
document.body.appendChild(popupContainer);
}
function togglePopup(forceOpen = null) {
if (forceOpen === null) {
forceOpen = popupContainer.style.display === 'none';
}
popupContainer.style.display = forceOpen ? 'block' : 'none';
}
// Popup bei Seitenaufruf anzeigen
createPopup();
// Alle 5 Sekunden überprüfen, ob Spieler online sind
setInterval(() => {
checkPlayers();
}, 5000);
})();