Pekora WineD3D Command Grabber

Intercepts pekora-player links and formats them with WineD3D and OpenGL overrides.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Pekora WineD3D Command Grabber
// @namespace    http://tampermonkey.net
// @version      2.6
// @description  Intercepts pekora-player links and formats them with WineD3D and OpenGL overrides.
// @author       You
// @match        *://*.pekora.zip/*
// @grant        GM_setClipboard
// @grant        GM_addStyle
// @run-at       document-start
// @license me
// ==/UserScript==

(function() {
    'use strict';

    const capturedLinks = [];

    // 1. Intercept protocol launch attempts
    const originalOpen = window.open;
    window.open = function(url, ...args) {
        if (url && url.includes('pekora-player:')) {
            saveLink(url);
        }
        return originalOpen.apply(this, [url, ...args]);
    };

    function saveLink(url) {
        const time = new Date().toLocaleTimeString();
        // Extract the raw protocol link if it's part of a larger string
        const match = url.match(/pekora-player:[^'"]+/);
        const rawLink = match ? match[0] : url;

        // Format for WineD3D + OpenGL
        const formattedCommand = `WINEDLLOVERRIDES="d3d11,dxgi=b" wine start '${rawLink}' --force-opengl`;

        capturedLinks.push(formattedCommand);
        console.log("%c[Pekora Grabber] Wine command generated!", "color: #00ff00; font-weight: bold;");
    }

    // 2. Observer for Dynamic "Play" Buttons
    const observer = new MutationObserver(() => {
        const links = document.querySelectorAll('a[href^="pekora-player:"]');
        links.forEach(link => {
            if (!link.dataset.grabbed) {
                saveLink(link.href);
                link.dataset.grabbed = "true";
            }
        });
    });
    observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true });

    // 3. Persistent Pink Button UI
    const container = document.createElement('div');
    container.id = 'pekora-ui-container';
    container.innerHTML = `<button id="copy-log-btn">Copy Join Link</button>`;
    document.documentElement.appendChild(container);

    document.getElementById('copy-log-btn').onclick = () => {
        if (capturedLinks.length > 0) {
            const latest = capturedLinks[capturedLinks.length - 1];
            GM_setClipboard(latest);

            // Visual feedback
            const btn = document.getElementById('copy-log-btn');
            btn.innerText = 'Copied Command!';
            setTimeout(() => { btn.innerText = 'Copy Join Link'; }, 2000);
        } else {
            alert('No link detected yet. Click "Play" on the site to capture it.');
        }
    };

    GM_addStyle(`
        #pekora-ui-container { position:fixed; top:10px; right:10px; z-index:2147483647; }
        #pekora-ui-container button {
            padding:12px 18px; background:#ff66aa; color:#fff; border:none;
            border-radius:5px; cursor:pointer; font-weight:bold; font-family:sans-serif;
            box-shadow: 0 4px 10px rgba(0,0,0,0.3);
        }
        #pekora-ui-container button:hover { background:#ff4499; }
    `);
})();