YouTube Subtitle Quick Copy

Quickly copy subtitles from YouTube and write them to the clipboard for easy analysis on GPT.

当前为 2024-07-09 提交的版本,查看 最新版本

// ==UserScript==
// @name               YouTube Subtitle Quick Copy
// @name:zh-TW         YouTube 字幕快速複製
// @namespace          wellstsai.com
// @version            20240709
// @license            BSD
// @description        Quickly copy subtitles from YouTube and write them to the clipboard for easy analysis on GPT.
// @description:zh-TW  快速複製 YouTube 字幕並將其寫入剪貼簿,以便在GPT上進行分析。
// @author             WellsTsai
// @match              https://*.youtube.com/*
// @icon               data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant              none
// ==/UserScript==

(function() {
    'use strict';

    const GPT_PROMPT = '使用"正體中文" 與 "臺灣詞彙",幫我消化時間軸後,我不需要直到詳細的時間,其中,如果影片有比較,請幫我列為表格,如果有方法,請幫我以條列式列出方法,請將影片的字幕檔轉換為詳細描述影片的重點與內容:';

    document.addEventListener('keydown', function(e) {
        if (e.ctrlKey && e.key === 'c') {
            const selectedText = window.getSelection().toString();
            if (!selectedText) {
                e.preventDefault(); // Prevent default copy behavior
                const segmentsContainer = document.querySelector('#segments-container');
                const transcriptButton = document.querySelector('ytd-video-description-transcript-section-renderer button');

                const copyText = () => {
                    const text = document.querySelector('#segments-container').innerText;
                    navigator.clipboard.writeText(text + "\n" + GPT_PROMPT);
                    console.log('RUN');
                };

                if (segmentsContainer) {
                    copyText();
                } else if (transcriptButton) {
                    transcriptButton.click();
                    setTimeout(copyText, 1000);
                }
            }
        }
    });

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址