iq.com Subtitle

자막만 가져오기

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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;

})();