PlayerCam

Zeigt eine vierte Webcam und sendet das Bild bei aktivem Spiel 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
// @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
})();