iq.com Subtitle

자막만 가져오기

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل 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;

})();