YouTubeの文字起こしを取得するブックマークレット
javascript:(async()=>{try{const sleep=ms=>new Promise(r=>setTimeout(r,ms));const findPanel=()=>Array.from(document.querySelectorAll('ytd-engagement-panel-section-list-renderer')).find(p=>p.getAttribute('target-id')==='engagement-panel-searchable-transcript'||p.textContent.includes('文字起こし'));let panel=findPanel();if(!panel||panel.getAttribute('visibility')!=='ENGAGEMENT_PANEL_VISIBILITY_EXPANDED'){const exp=document.querySelector('#expand');if(exp)exp.click();await sleep(400);const btn=Array.from(document.querySelectorAll('button')).find(b=>b.textContent.includes('文字起こしを表示')||b.getAttribute('aria-label')?.includes('文字起こし'));if(btn){btn.click();for(let i=0;i<15;i++){await sleep(300);panel=findPanel();if(panel&&panel.innerText.length>100)break;}}}if(!panel||panel.innerText.length<50){alert('文字起こしパネルが取得できません。手動で「文字起こしを表示」を開いてから実行してください。');return;}const raw=panel.innerText;const lines=raw.split('\n').map(l=>l.trim()).filter(l=>l&&!/^\d{1,2}:\d{2}(:\d{2})?$/.test(l)&&!/^(?:\d+\s*時間\s*)?(?:\d+\s*分\s*)?\d+\s*秒$/.test(l)&&!['文字起こし','文字起こしを検索','タイムスタンプを切り替える','日本語','自動生成','すべて'].includes(l)&&!l.includes('で検索'));const output='以下を要約してください。\n\n'+lines.join('\n');await navigator.clipboard.writeText(output);alert('コピー完了('+lines.length+'行)');}catch(e){alert('エラー: '+e.message);}})();