'Can I use a javascript bookmarklet to copy a Youtube transcript without timestamps, now that they removed this option?

There used to be an option on Youtube to remove timestamps from the transcript, which I often used to copy it to the clipboard. No longer. Now my solution is to go into the Code Inspector, and set the class property to display:none. It works, but I'd like to automate it with a bookmarklet. This is as far as I've gone:

function() {
    var trans = '';
    const captions = document.querySelectorAll("ytd-transcript-segment-renderer > div > yt-formatted-string");
    for (let i = 0; i < captions.length; i++) {
        trans += ' ' + captions[i].textContent
    };
    navigator.clipboard.writeText(trans)
}

Help?



Solution 1:[1]

Nailed it!

javascript: (function() {
    var captions = "";
    document.querySelector("ytd-menu-service-item-renderer.style-scope:nth-child(2) > tp-yt-paper-item:nth-child(1) > yt-formatted-string:nth-child(2)").click();
    [].slice.call(document.querySelectorAll("ytd-transcript-segment-renderer > div > yt-formatted-string")).forEach(caption => captions += caption.textContent + " ");
    navigator.clipboard.writeText(captions)
})()

Can it be improved?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1