// ==UserScript==
// @name Freundesliste & Info für AutoDarts
// @namespace Owl
// @version 4.2
// @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;
}
}
// Liste der Freunde im Popup anzeigen
function updateList(listElement) {
listElement.innerHTML = '';
friendList.sort((a, b) => {
return a.online === b.online ? a.name.localeCompare(b.name) : (a.online ? -1 : 1);
});
friendList.forEach(item => {
const li = document.createElement('li');
li.textContent = item.name;
li.style.color = item.online ? 'green' : 'gray';
// "Match anschauen"-Button hinzufügen
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);
// Entfernen-Button hinzufügen
const removeBtn = document.createElement('button');
removeBtn.textContent = 'X';
removeBtn.style.marginLeft = '10px';
removeBtn.style.backgroundColor = '#C53030';
removeBtn.style.color = '#fff';
removeBtn.style.border = 'none';
removeBtn.style.borderRadius = '4px';
removeBtn.style.padding = '2px 8px';
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);
});
}
// Freundesliste als Popup anzeigen
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';
addButton.style.padding = '4px 8px';
addButton.style.cursor = 'pointer';
addButton.style.backgroundColor = 'rgba(59, 182, 43, 1)';
addButton.style.color = '#fff';
addButton.style.border = 'none';
addButton.style.borderRadius = '4px';
inputWrapper.appendChild(addButton);
const listElement = document.createElement('ul');
listElement.style.listStyle = 'none';
listElement.style.paddingLeft = '0';
popupContainer.appendChild(listElement);
// Spieler zur Freundesliste hinzufügen
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);
}
// Popup ein- oder ausblenden
function togglePopup() {
if (!popupContainer) {
createPopup();
}
popupContainer.style.display = popupContainer.style.display === 'none' ? 'block' : 'none';
}
// Popup im Menü hinzufügen
function addFriendlistMenuItem() {
const menuContainer = document.querySelector('div.chakra-stack');
if (menuContainer) {
let friendlistLink = document.getElementById('autodarts-friendlist-menu-item');
if (!friendlistLink) {
friendlistLink = document.createElement('a');
friendlistLink.id = 'autodarts-friendlist-menu-item';
friendlistLink.textContent = 'Freundesliste';
friendlistLink.style.cursor = 'pointer';
friendlistLink.addEventListener('click', togglePopup);
menuContainer.appendChild(friendlistLink);
}
}
}
// Menüeintrag für Freundesliste hinzufügen
setInterval(addFriendlistMenuItem, 1000);
// Alle 5 Sekunden prüfen, ob Spieler online sind
setInterval(() => {
checkPlayers();
}, 5000);
})();