iq.com Subtitle

자막만 가져오기

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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;

})();