YouTubeの文字起こしを取得するブックマークレット|リンクコード付き

YouTubeの文字起こしを取得するブックマークレット|リンクコード付き

動画を見て情報を得るのはタイパが悪い|文字起こしをAIに要約してもらうのがよい

■Global Speed: 動画速度制御 - Chrome ウェブストア

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 h=window.location.href,t=document.title;const titleClean=t.normalize('NFC').replace(/ヨドバシ\.com - (.*?) 通販【全品無料配達】/g,'$1').replace(/ - YouTube/g,'').replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF]/g,'').replace(/[\r\n]/g,'▼');var u=h;if(u.indexOf('youtube.com/watch')!==-1||u.indexOf('youtu.be/')!==-1){var vMatch=u.match(/[?&]v=([^&]+)/)||u.match(/youtu\.be\/([^?&]+)/);var tMatch=u.match(/[?&]t=([^&]+)/);var tStr='00h00m00s';if(tMatch){tStr=tMatch[1];}u='https://www.youtube.com/watch?v='+(vMatch?vMatch[1]:'')+'&t='+tStr;}const escapedTitle=titleClean.replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/'/g,'&apos;').replace(/</g,'&lt;').replace(/>/g,'&gt;');const linkHtml='■<a href="'+u+'" target="_blank" rel="nofollow">'+escapedTitle+'</a><br>\n\n';const output=linkHtml+'以下を要約してください。\n\n'+lines.join('\n');await navigator.clipboard.writeText(output);alert('コピー完了('+lines.length+'行)');}catch(e){alert('エラー: '+e.message);}})();