iq.com Subtitle

자막만 가져오기

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         iq.com Subtitle
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  자막만 가져오기
// @author       yongyong
// @match        *://*.iq.com/play/*
// @run-at       document-start
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict';

    console.log("%c[Subtitle Hunter] 엔진 가동 중...", "color: #fffa00; font-weight: bold;");

    const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;

    function parseResponse(data) {
        try {
            const program = data?.data?.program;
            if (program && program.stl) {
                const basePath = data.data.dstl || "";
                console.log(program.stl)
                // 한국어 자막 필터링
                const korSub = program.stl.find(s =>
                    s._name?.includes("한국어") ||
                    s.name?.includes("한국어") ||
                    s.lid === 4
                );

                if (korSub && korSub.srt) {
                    const fullUrl = korSub.srt.startsWith('http') ? korSub.srt : basePath + korSub.srt;
                    console.log("%c[데이터 포착] 자막 URL:", "color: #00ecff;", fullUrl);
                    createDownloadButton(korSub._name || "한국어", fullUrl);
                } else {
                    console.log("[알림] 자막 목록은 찾았으나 한국어를 발견하지 못했습니다.");
                }
            }
        } catch (e) {
            console.error("[오류] 데이터 파싱 실패:", e);
        }
    }

    const orgFetch = win.fetch;
    win.fetch = async (...args) => {
        const response = await orgFetch(...args);
        const url = args[0] instanceof Request ? args[0].url : args[0];

        if (url.includes('dash?') || url.includes('tmts?') || url.includes('play?')) {
            const clone = response.clone();
            clone.json().then(data => parseResponse(data)).catch(() => {});
        }
        return response;
    };

    const oldSend = win.XMLHttpRequest.prototype.send;
    win.XMLHttpRequest.prototype.send = function() {
        this.addEventListener('load', function() {
            if (this.responseURL.includes('dash?') || this.responseURL.includes('tmts?')) {
                try {
                    const res = JSON.parse(this.responseText);
                    parseResponse(res);
                } catch (e) {}
            }
        });
        return oldSend.apply(this, arguments);
    };

    win.WebAssembly = undefined;

})();