Quick Copy YouTube Subtitles

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

  1. // ==UserScript==
  2. // @name Quick Copy YouTube Subtitles
  3. // @name:zh-TW YouTube 字幕快速複製
  4. // @namespace wellstsai.com
  5. // @version v20241128.2
  6. // @license BSD
  7. // @description Quickly copy subtitles from YouTube and write them to the clipboard for easy analysis on GPT.
  8. // @description:zh-TW 快速複製 YouTube 字幕並將其寫入剪貼簿,以便在GPT上進行分析。
  9. // @author WellsTsai
  10. // @match https://*.youtube.com/*
  11. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. const GPT_PROMPT = '使用"正體中文" 與 "臺灣詞彙",幫我消化時間軸後,我不需要知道詳細的時間,其中,如果影片有比較,請幫我列為表格,如果有方法,請幫我以條列式列出方法,請將影片的字幕檔轉換為詳細描述影片的重點與內容:';
  19. const COPY_NOTIFICATION_TEXT = '已複製';
  20.  
  21. const copyToClipboard = text => {
  22. navigator.clipboard.writeText(text + "\n" + GPT_PROMPT).then(showCopyNotification);
  23. };
  24.  
  25. const showCopyNotification = () => {
  26. const notification = document.createElement('div');
  27. notification.innerText = COPY_NOTIFICATION_TEXT;
  28. Object.assign(notification.style, {
  29. 'font-size': '2em',
  30. position: 'fixed',
  31. bottom: '20px', right: '20px', padding: '10px',
  32. backgroundColor: 'rgba(0, 0, 0, 0.7)',
  33. color: 'white',
  34. borderRadius: '5px',
  35. zIndex: '1000'
  36. });
  37. document.body.appendChild(notification);
  38. setTimeout(() => document.body.removeChild(notification), 1500);
  39. };
  40.  
  41. document.addEventListener('keydown', e => {
  42. if (!(e.ctrlKey && e.key === 'c') || window.getSelection().toString()) return; // Detect if Ctrl + C is pressed and no text is selected.
  43. e.preventDefault();
  44.  
  45. const segmentsContainer = document.querySelector('#segments-container');
  46. const transcriptButton = document.querySelector('ytd-video-description-transcript-section-renderer button');
  47.  
  48. if (segmentsContainer) {
  49. copyToClipboard(segmentsContainer.innerText);
  50. } else if (transcriptButton) {
  51. transcriptButton.click();
  52. setTimeout(() => {
  53. const newSegmentsContainer = document.querySelector('#segments-container');
  54. if (newSegmentsContainer) copyToClipboard(newSegmentsContainer.innerText);
  55. }, 1000);
  56. }
  57. });
  58. })();

QingJ © 2025

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