Play Stripchat via PotPlayer, VLC, nPlayer, etc

Play Stripchat videos using external players like PotPlayer, VLC, and nPlayer.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Play Stripchat via PotPlayer, VLC, nPlayer, etc
// @namespace   https://greasyfork.org/scripts/473187
// @version     1.3.0
// @description Play Stripchat videos using external players like PotPlayer, VLC, and nPlayer.
// @match       *://*.stripchat.com/*
// @grant       GM_setClipboard
// @license     MIT
// ==/UserScript==

(function () {
    'use strict';

    let live_url = '';

    // 📡 Bắt URL qua XHR
    const originalXHR = window.XMLHttpRequest.prototype.open;
    window.XMLHttpRequest.prototype.open = function (method, url) {
        this.addEventListener('readystatechange', function () {
            if (this.readyState === 4 && this.responseText) {
                try {
                    if (this.responseText.includes('.m3u8')) {
                        const match = this.responseText.match(/https?:\/\/[^\s"]+\.m3u8/);
                        if (match) {
                            live_url = match[0];
                            console.log('🎯 Found m3u8 URL via XHR:', live_url);
                        }
                    }
                } catch (e) {
                    console.warn('⚠️ XHR Error:', e);
                }
            }
        });
        originalXHR.apply(this, arguments);
    };

    // 📡 Bắt URL qua WebSocket
    const originalWebSocket = window.WebSocket;
    window.WebSocket = function (...args) {
        const ws = new originalWebSocket(...args);

        ws.addEventListener('message', (event) => {
            try {
                const data = event.data;
                if (typeof data === 'string' && data.includes('.m3u8')) {
                    const match = data.match(/https?:\/\/[^\s"]+\.m3u8/);
                    if (match) {
                        live_url = match[0];
                        console.log('🎯 Found m3u8 URL via WebSocket:', live_url);
                    }
                }
            } catch (e) {
                console.warn('⚠️ WebSocket Error:', e);
            }
        });

        return ws;
    };

    // 🎮 Tạo nút điều khiển
    function createButton(player_name, player_url, copy_url = false) {
        let button = document.createElement("button");
        button.innerHTML = player_name;
        button.style.cssText = `
            width: 100px;
            height: 35px;
            text-align: center;
            color: white;
            background: #e33e33;
            border: 1px solid #e33e33;
            border-radius: 8px;
            font-size: 14px;
            cursor: pointer;
            margin: 5px;
        `;

        button.onclick = function () {
            if (!live_url) {
                alert('❌ Không tìm thấy URL video. Hãy làm mới trang và thử lại.');
                return;
            }

            let final_url = `${player_url}${live_url}`;
            if (copy_url) {
                GM_setClipboard(final_url);
                alert(`✅ URL đã sao chép: ${final_url}`);
            } else {
                window.open(final_url);
            }
        };

        document.querySelector("#portal-root")?.prepend(button);
    }

    // Thêm nút phát video
    createButton("Copy Link", "", true);
    createButton("PotPlayer", "potplayer://");
    createButton("VLC", "vlc://");
    createButton("nPlayer", "nplayer-");
})();