Hacker News new | past | comments | ask | show | jobs | submit login

As a userscript https://github.com/madacol/web-automation/blob/master/usersc...

    // ==UserScript==
    // @name        Always show transcript
    // @match       https://www.youtube.com/watch*
    // @grant       none
    // @version     1.0
    // @author      madacol
    // @description show transcript on all youtube videos
    // @run-at      document-idle
    // ==/UserScript==
    (async ()=>{
        (await getElementNotYetRendered(()=>document.querySelector('button[aria-label="Show transcript"]'))).click()

        function getElementNotYetRendered(elementGetter, delay = 200, timeout = 10000) {
            let retries = Math.ceil(timeout / delay);
            return new Promise((resolve, reject) => {
                (function resolveIfElementFound() {
                    setTimeout(() => {
                        const element = elementGetter()
                        if (element?.toString().includes("Element")) return resolve(element)
                        if (element?.toString().includes("NodeList") && element.length > 0) return resolve(element)

                        if (retries-- <= 0) return console.error(`Max retries reached: element was not found
                        element: "${element}"
                        elementGetter: "${elementGetter}"
                        `);
                        resolveIfElementFound()
                    }, delay);
                })()
            })
        }
    })();



Vastly simplified userscript to only show transcript when pressing Ctrl+f

https://github.com/madacol/web-automation/blob/master/usersc...

    // ==UserScript==
    // @name        Show transcript on Ctrl+f
    // @match       https://www.youtube.com/watch*
    // @grant       none
    // @version     1.0
    // @author      madacol
    // ==/UserScript==
    document.addEventListener('keydown', event => {
        if (event.ctrlKey && event.key === 'f')
            document.querySelector('button[aria-label="Show transcript"]').click()
    })




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: