IPTV Content Extractor

提取并复制IPTV源列表、源地址

目前為 2024-09-24 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         IPTV Content Extractor
// @namespace    http://tampermonkey.net/
// @version      3.0
// @description  提取并复制IPTV源列表、源地址
// @author       zephyr
// @match        http://www.foodieguide.com/iptvsearch*
// @match        http://foodieguide.com/iptvsearch*
// @match        http://tonkiang.us/*
// @match        https://www.foodieguide.com/iptvsearch*
// @match        https://foodieguide.com/iptvsearch*
// @grant        GM_setClipboard
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // 添加样式
    GM_addStyle(`
        #copyButton {
            position: fixed;
            top: 40px;
            right: 20px;
            padding: 10px 15px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            z-index: 1000;
        }
        #copyButton:hover {
            background-color: #45a049;
        }
    `);

    // 创建并插入按钮
    const button = document.createElement('button');
    button.id = 'copyButton';
    button.innerText = '一键复制提取内容';
    document.body.appendChild(button);

    // 按钮点击事件
    button.addEventListener('click', function() {
        // 创建一个Set来保存提取的数据
        let extractedData = new Set();

        // 获取所有 resultplus 或 result 元素
        document.querySelectorAll('div.resultplus, div.result').forEach(resultDiv => {

            // 提取频道名称
            const channelDiv = resultDiv.querySelector('div.channel a div');
            const title = channelDiv ? channelDiv.textContent.trim() : '未知频道';

            // 提取地址: 优先定位到 b 标签的文本(用于提取 IP 地址或其他文本),跳过 <img>
            const aTag = resultDiv.querySelector('div.channel > a');
            let address = '';

            if (aTag) {
                const bTag = aTag.querySelector('b');
                if (bTag) {
                    address = [...bTag.childNodes]
                        .filter(node => node.nodeType === Node.TEXT_NODE)  // 只保留文本节点
                        .map(node => node.textContent.trim())  // 去除空格
                        .join('');  // 合并所有文本
                }
            }

            // 提取第二个 tba 或第二个 td
            let secondValue = '';
            const tbaElements = resultDiv.querySelectorAll('tba');
            if (tbaElements.length >= 2) {
                secondValue = tbaElements[1].textContent.trim();
            } else {
                const tdElements = resultDiv.querySelectorAll('td');
                if (tdElements.length >= 2) {
                    secondValue = tdElements[1].textContent.trim();
                }
            }

            // 如果频道名称和URL都存在,则按指定格式添加到Set中
            if (title && (address || secondValue)) {
                extractedData.add(`${title},${address || secondValue}`);
            }
        });

        // 将Set中的数据拼接成最终的字符串,每行一个频道
        const finalData = Array.from(extractedData).join('\n');

        // 复制到剪贴板
        GM_setClipboard(finalData);

        // 通知用户
        alert('提取内容已复制到剪贴板!');
    });

})();