Aktiviert automatisch die vierte Webcam auf autodarts.io und überträgt das Bild an den Gegner.
当前为
// ==UserScript==
// @name PlayerCam Auto
// @namespace http://tampermonkey.net/
// @version 4.0
// @description Aktiviert automatisch die vierte Webcam auf autodarts.io und überträgt das Bild an den Gegner.
// @author YourName
// @match *://autodarts.io/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 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;
// Funktion zur Ermittlung der Kameras
async function getCameras() {
try {
const devices = await navigator.mediaDevices.enumerateDevices();
const videoDevices = devices.filter(device => device.kind === 'videoinput');
if (videoDevices.length > 3) {
selectedDeviceId = videoDevices[3].deviceId; // Vierte Kamera auswählen
} else {
alert('Nicht genug Kameras angeschlossen.');
}
} catch (error) {
console.error('Fehler beim Abrufen der Kameras:', error);
}
}
// Webcam aktivieren und streamen
async function activateWebcam() {
if (!selectedDeviceId) {
console.log('Keine vierte Kamera verfügbar.');
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);
}
}
// 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) {
const matchId = matchElement.textContent;
if (matchId) {
console.log(`Spiel aktiv mit Match-ID: ${matchId}`);
activateWebcam();
}
} else {
console.log('Kein Spiel aktiv.');
}
}
// Kameras laden und Match überprüfen
getCameras();
setInterval(checkMatch, 5000); // Alle 5 Sekunden prüfen
})();