// ==UserScript==
// @name Freundesliste & Info für AutoDarts
// @namespace Owl
// @version 4.8
// @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, 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();
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 (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, Grau für offline)
function updateFriendStatus(onlineNames) {
friendList.forEach(friend => {
friend.online = onlineNames.includes(friend.name.toUpperCase());
});
savePlayerList();
}
// Funktion, um Resize für das Popup zu ermöglichen
function enableResize(popupElement) {
const resizer = document.createElement('div');
resizer.style.position = 'absolute';
resizer.style.right = '0';
resizer.style.bottom = '0';
resizer.style.width = '10px';
resizer.style.height = '10px';
resizer.style.cursor = 'se-resize';
resizer.style.backgroundColor = '#E2E8F0';
popupElement.appendChild(resizer);
let isResizing = false;
let lastX = 0;
let lastY = 0;
resizer.addEventListener('mousedown', (e) => {
isResizing = true;
lastX = e.clientX;
lastY = e.clientY;
document.addEventListener('mousemove', handleResize);
document.addEventListener('mouseup', () => {
isResizing = false;
document.removeEventListener('mousemove', handleResize);
});
});
function handleResize(e) {
if (isResizing) {
const width = popupElement.offsetWidth + (e.clientX - lastX);
const height = popupElement.offsetHeight + (e.clientY - lastY);
popupElement.style.width = `${Math.max(width, 200)}px`;
popupElement.style.height = `${Math.max(height, 150)}px`;
lastX = e.clientX;
lastY = e.clientY;
}
}
}
// Popup-Funktion für die Freundesliste
let popupContainer = null;
let isDragging = false;
let offsetX, offsetY;
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 dragBar = document.createElement('div');
dragBar.style.height = '20px';
dragBar.style.cursor = 'move';
dragBar.style.marginBottom = '10px';
popupContainer.appendChild(dragBar);
dragBar.addEventListener('mousedown', (e) => {
isDragging = true;
offsetX = e.clientX - popupContainer.getBoundingClientRect().left;
offsetY = e.clientY - popupContainer.getBoundingClientRect().top;
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', () => {
isDragging = false;
document.removeEventListener('mousemove', handleMouseMove);
});
});
function handleMouseMove(e) {
if (isDragging) {
popupContainer.style.left = `${e.clientX - offsetX}px`;
popupContainer.style.top = `${e.clientY - offsetY}px`;
}
}
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);
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 });
savePlayerList();
updateList(listElement);
}
inputName.value = '';
inputBoardId.value = '';
}
addButton.addEventListener('click', addFriend);
inputName.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
addFriend();
}
});
updateList(listElement);
// Hier wird der Resize-Handler aktiviert
enableResize(popupContainer);
document.body.appendChild(popupContainer);
}
function togglePopup(forceOpen) {
if (!popupContainer) {
createPopup();
}
popupContainer.style.display = forceOpen === undefined ? (popupContainer.style.display === 'none' ? 'block' : 'none') : forceOpen ? 'block' : 'none';
// Alle 5 Sekunden wird das Popup automatisch aktualisiert, wenn es geöffnet ist
if (popupContainer.style.display === 'block') {
setInterval(() => {
updateList(popupContainer.querySelector('ul'));
}, 5000); // Alle 5 Sekunden
}
}
// Menü für die Freundesliste hinzufügen
function addFriendlistMenuItem(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.className = 'chakra-button css-1nal3hj';
friendlistLink.style.cursor = 'pointer';
const icon = document.createElement('span');
icon.className = 'chakra-button__icon css-1wh2kri';
icon.style.marginRight = '0.5rem';
icon.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2C6.49 2 2 6.49 2 12s4.49
10 10 10 10-4.49 10-10S17.51
2 12 2zm3 14H9v-2h6v2zm2-4H7V8h10v4z"/>
</svg>`;
friendlistLink.prepend(icon);
menuContainer.appendChild(friendlistLink);
friendlistLink.addEventListener('click', () => togglePopup());
}
}
// Menü finden und Freundesliste hinzufügen
const intervalId = setInterval(() => {
const menuContainer = [...document.querySelectorAll('div.chakra-stack')]
.find(div => div.querySelector('a[href="/"]') && div.querySelector('a[href="/lobbies"]'));
if (menuContainer) {
addFriendlistMenuItem(menuContainer);
clearInterval(intervalId);
}
}, 1000);
// Alle 1 Sekunde die Spieler überprüfen und die Farben aktualisieren
setInterval(() => {
checkPlayers();
}, 5000); // Update alle 5 Sekunden
})();