Export Stream Link to .m3u from Context Menu

Auto-clicks "Copy stream link", grabs clipboard, saves .m3u

当前为 2025-07-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         Export Stream Link to .m3u from Context Menu
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Auto-clicks "Copy stream link", grabs clipboard, saves .m3u
// @author       heapsofjoy
// @match        https://web.stremio.com/*
// @grant        clipboardRead
// ==/UserScript==

(function () {
    'use strict';

    // Keep track of right-click events
    document.addEventListener('contextmenu', (e) => {
        // Slight delay to let context menu render
        setTimeout(() => {
            const copyButton = [...document.querySelectorAll('div[title="Copy stream link"]')]
                .find(el => el?.innerText?.toLowerCase().includes('copy stream link'));

            if (!copyButton) {
                console.warn('No "Copy stream link" button found');
                return;
            }

            // Simulate click
            copyButton.click();

            // Try reading from clipboard shortly after click
            setTimeout(async () => {
                try {
                    const text = await navigator.clipboard.readText();
                    if (!text.startsWith('http')) {
                        alert('❌ Invalid stream URL in clipboard');
                        return;
                    }

                    const m3u = `#EXTM3U\n${text}`;
                    const blob = new Blob([m3u], { type: 'audio/x-mpegurl' });
                    const a = document.createElement('a');
                    a.href = URL.createObjectURL(blob);
                    a.download = 'stream.m3u';
                    a.click();
                    URL.revokeObjectURL(a.href);
                    console.log('✅ Stream link saved as .m3u:', text);
                } catch (err) {
                    alert('❌ Failed to access clipboard. Permissions may be blocked.\n' + err);
                }
            }, 500); // allow clipboard to update
        }, 150); // allow menu to appear
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址