Zeigt eine vierte Webcam und sendet das Bild bei aktivem Spiel an den Gegner.
当前为
// ==UserScript==
// @name PlayerCam
// @namespace http://tampermonkey.net/
// @version 3.0
// @description Zeigt eine vierte Webcam und sendet das Bild bei aktivem Spiel an den Gegner.
// @author YourName
// @match *://autodarts.io/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Dropdown für Kameraauswahl erstellen
const cameraSelect = document.createElement('select');
cameraSelect.id = 'cameraSelect';
cameraSelect.style.position = 'fixed';
cameraSelect.style.top = '20px';
cameraSelect.style.right = '20px';
cameraSelect.style.zIndex = '1000';
cameraSelect.style.padding = '10px';
const activateButton = document.createElement('button');
activateButton.textContent = 'Activate PlayerCam';
activateButton.style.position = 'fixed';
activateButton.style.top = '60px';
activateButton.style.right = '20px';
activateButton.style.zIndex = '1000';
activateButton.style.padding = '10px 20px';
activateButton.style.backgroundColor = '#007BFF';
activateButton.style.color = '#FFFFFF';
activateButton.style.border = 'none';
activateButton.style.borderRadius = '5px';
activateButton.style.cursor = 'pointer';
document.body.appendChild(cameraSelect);
document.body.appendChild(activateButton);
// Videoelement für lokale Ansicht erstellen
const videoElement = document.createElement('video');
videoElement.style.position = 'fixed';
videoElement.style.bottom = '20px';
videoElement.style.right = '20px';
videoElement.style.width = '320px';
videoElement.style.height = '240px';
videoElement.style.border = '1px solid #000';
videoElement.style.zIndex = '1000';
videoElement.style.display = 'none';
document.body.appendChild(videoElement);
let selectedDeviceId = null;
let matchId = null;
// Funktion zur Ermittlung der Kameras
async function getCameras() {
try {
const devices = await navigator.mediaDevices.enumerateDevices();
const videoDevices = devices.filter(device => device.kind === 'videoinput');
cameraSelect.innerHTML = '';
videoDevices.forEach((device, index) => {
const option = document.createElement('option');
option.value = device.deviceId;
option.textContent = device.label || `Camera ${index + 1}`;
cameraSelect.appendChild(option);
});
if (videoDevices.length > 0) {
selectedDeviceId = videoDevices[0].deviceId;
} else {
alert('Keine Kameras gefunden.');
}
} catch (error) {
console.error('Fehler beim Abrufen der Kameras:', error);
}
}
// Kameraauswahl-Event
cameraSelect.addEventListener('change', (event) => {
selectedDeviceId = event.target.value;
});
// Webcam aktivieren und streamen
async function activateWebcam() {
if (!selectedDeviceId) {
alert('Keine Kamera ausgewählt.');
return;
}
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: {
deviceId: { exact: selectedDeviceId },
width: { exact: 320 },
height: { exact: 240 },
frameRate: { max: 10 }
},
audio: false
});
videoElement.srcObject = stream;
videoElement.play();
videoElement.style.display = 'block';
// Externes Fenster öffnen für Gegneransicht
const opponentWindow = window.open('', '_blank', 'width=340,height=260');
if (opponentWindow) {
const opponentVideo = opponentWindow.document.createElement('video');
opponentVideo.style.width = '320px';
opponentVideo.style.height = '240px';
opponentVideo.autoplay = true;
opponentVideo.srcObject = stream;
opponentWindow.document.body.appendChild(opponentVideo);
} else {
alert('Pop-up Blocker deaktivieren, um Gegneransicht zu ermöglichen.');
}
} catch (error) {
console.error('Konnte die Webcam nicht aktivieren:', error);
alert('Fehler beim Zugriff auf die ausgewählte Kamera.');
}
}
// Klick-Event für Aktivierungsbutton
activateButton.addEventListener('click', activateWebcam);
// Match-ID prüfen und Kamera aktivieren, wenn ein Spiel läuft
function checkMatch() {
const matchElement = document.querySelector('.match-id'); // Beispiel für Match-ID-Element
if (matchElement) {
matchId = matchElement.textContent;
if (matchId) {
console.log(`Spiel aktiv mit Match-ID: ${matchId}`);
}
} else {
console.log('Kein Spiel aktiv.');
}
}
// Kameras laden und Match überprüfen
getCameras();
setInterval(checkMatch, 5000); // Alle 5 Sekunden prüfen
})();