PlayerCam Auto

Aktiviert automatisch die vierte Webcam auf autodarts.io und überträgt das Bild an den Gegner.

目前為 2024-12-31 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
})();