Youtube transcript copy

9/10/2025, 8:56:08 PM

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        Youtube transcript copy
// @namespace   Violentmonkey Scripts
// @match       https://www.youtube.com/watch?v=*
// @grant       none
// @run-at      document-idle
// @version     1.0.0
// @author      Sue Smith MD
// @license     AGPL-3.0; https://www.gnu.org/licenses/agpl-3.0.html#license-text
// @description 9/10/2025, 8:56:08 PM
// ==/UserScript==

(()=>{let G=()=>{if(document.getElementById("ytb-copy-transcript-style"))return;let k=document.createElement("style");k.id="ytb-copy-transcript-style",k.textContent=`
.ytb-copy-transcript-btn { font-family: "YouTube Sans","Roboto",sans-serif; font-size: 1.5rem; line-height: 2.8rem; font-weight: 700; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 12px; border-radius: 18px; background: transparent; color: currentColor; border: 1px solid rgba(255,255,255,0.2); cursor: pointer; gap: 6px; }
.ytb-copy-transcript-btn:hover { background: rgba(255,255,255,0.06); }
.ytb-copy-transcript-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: rgba(28,28,28,0.92); color: #fff; padding: 8px 12px; border-radius: 8px; font: 500 12px/16px Roboto, sans-serif; z-index: 2147483647; opacity: 0; transition: opacity 120ms ease-out; }
`,document.head.appendChild(k)},U=(k,z)=>{let A;return(...D)=>{if(A!==void 0)window.clearTimeout(A);A=window.setTimeout(()=>k(...D),z)}},V=(k)=>{if("requestIdleCallback"in window)window.requestIdleCallback(k);else setTimeout(k,0)},X=(k)=>{return Array.from(k.querySelectorAll(".segment-text")).map((D)=>D.textContent?.trim()).filter((D)=>Boolean(D&&D.length>0)).join(`
`)},Y=async(k)=>{try{return await navigator.clipboard.writeText(k),!0}catch(z){let A=document.createElement("textarea");A.value=k,A.style.position="fixed",A.style.top="0",A.style.left="0",A.style.opacity="0",document.body.appendChild(A),A.focus(),A.select();try{return document.execCommand("copy")}finally{A.remove()}}},Z=async()=>{let k=document.querySelector("#segments-container");if(!k){console.warn("No transcript container found; open transcript first.");return}let z=X(k);if(!z){console.warn("No transcript text found in #segments-container");return}let A=await Y(z.replaceAll("[Music]",""));if(j(A?"Copied transcript":"Copy failed"),!A)console.warn("Copy failed. Transcript follows:",z)},J=()=>{let k=["ytd-engagement-panel-title-header-renderer #menu ytd-menu-renderer #top-level-buttons-computed","ytd-engagement-panel-title-header-renderer #top-level-buttons-computed","#panel ytd-engagement-panel-title-header-renderer #top-level-buttons-computed"];for(let z of k){let A=document.querySelector(z);if(A)return A}return null},_=()=>{G();let k=J();if(!k)return;if(k.querySelector('[data-ytb-copy-transcript="true"]'))return;let z=document.createElement("button");z.setAttribute("data-ytb-copy-transcript","true"),z.type="button",z.title="Copy transcript",z.textContent="Copy",z.className="ytb-copy-transcript-btn",z.addEventListener("click",()=>{Z()}),k.appendChild(z)},$=()=>{let k=document.querySelector('ytd-engagement-panel-section-list-renderer[target-id="engagement-panel-searchable-transcript"]');if(k)return k;return document.querySelector("ytd-engagement-panel-section-list-renderer")},F=U(()=>V(_),50),B=()=>{let z=document.querySelector("#primary-button > ytd-button-renderer > yt-button-shape > button");if(z)z.addEventListener("click",()=>{requestAnimationFrame(()=>{F()})});let A=()=>{let N=$();if(!N)return!1;let Q=new MutationObserver(()=>{F()});Q.observe(N,{childList:!0,subtree:!0});let q=()=>{if(J()?.querySelector('[data-ytb-copy-transcript="true"]'))return Q.disconnect(),!0;return!1},R=setInterval(()=>{if(q())clearInterval(R)},300);return!0};F();let D=0,K=setInterval(()=>{if(D+=1,A())clearInterval(K);if(D>=10)clearInterval(K)},400),L=()=>{F(),setTimeout(()=>void A(),600)};window.addEventListener("yt-navigate-finish",L),window.addEventListener("yt-page-data-updated",L)},j=(k)=>{G();let z=document.createElement("div");z.className="ytb-copy-transcript-toast",z.textContent=k,document.body.appendChild(z),requestAnimationFrame(()=>{z.style.opacity="1"}),setTimeout(()=>{z.style.opacity="0",setTimeout(()=>z.remove(),150)},1200)};if(!window.__ytb_copy_transcript_bound)window.__ytb_copy_transcript_bound=!0,document.querySelector("#expand")?.click(),document.querySelector("#primary-button > ytd-button-renderer > yt-button-shape > button")?.click(),B()})();