Last active
July 3, 2022 06:59
-
-
Save gijigae/8d5e6d59214736dc8ac5f170b208b899 to your computer and use it in GitHub Desktop.
Bookmarklet script to extract YT transcript for Logseq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:void%20function(){(function(){const%20a=()=%3Edocument.querySelectorAll(%22ytd-transcript-renderer%20ytd-transcript-segment-renderer%20%3E%20div%22),b=a=%3E{const%20b=Array.from(a),c=b.map(a=%3E{const%20b=Array.from(a.querySelectorAll(%22div%22)).slice(0,2),c=Array.from(a.querySelectorAll(%22yt-formatted-string%22)).slice(0,1);let%20d=b[0].textContent.trim();4===d.length%3Fd=`00:0${d}`:5===d.length%3Fd=`00:${d}`:7===d.length%26%26(d=`0${d}`);const%20e=%22{{youtube-timestamp%20%22+d+%22}}%22,f=c[0].textContent.trim().replace(/(\r\n|\n|\r)/gm,%22%20%22);return{timestamp:e,transcript:f}});let%20d=%22%22;c.forEach(a=%3E{d+=[`-%20${a.timestamp}`,`${a.transcript}\n`].join(%22%20%22)}),navigator.clipboard.writeText(d)};let%20c=a();if(0!==c.length)return%20void%20b(c);const%20d=setInterval(()=%3E{try{document.querySelector(%22ytd-menu-service-item-renderer.style-scope:nth-child(2)%20%3E%20tp-yt-paper-item:nth-child(1)%20%3E%20yt-formatted-string:nth-child(2)%22).click()}catch(a){return%20void%20console.log(%22WARN:%20failed%20to%20click%20button%20opening%20a%20transcript%22)}clearInterval(d);const%20c=setInterval(()=%3E{const%20d=a();0===d.length||(b(d),clearInterval(c))},100)},100)})()}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment