Skip to content

Instantly share code, notes, and snippets.

@insin
Created January 8, 2024 15:18
Show Gist options
  • Save insin/aa5c3f1d169e0845c1eb15d9d8082229 to your computer and use it in GitHub Desktop.
Save insin/aa5c3f1d169e0845c1eb15d9d8082229 to your computer and use it in GitHub Desktop.
let $segments = document.querySelector('.ytd-transcript-search-panel-renderer #segments-container')
let sections = []
let parts = []
for (let $el of $segments.children) {
if ($el.tagName == 'YTD-TRANSCRIPT-SECTION-HEADER-RENDERER') {
if (parts.length > 0) {
sections.push(parts.join(' '))
parts = []
}
sections.push($el.querySelector('#title').innerText)
} else {
parts.push($el.querySelector('.segment-text').innerText.trim())
}
}
if (parts.length > 0) {
sections.push(parts.join(' '))
}
let $link = document.createElement('a')
let url = URL.createObjectURL(new Blob([sections.join('\n\n')], {type: "text/plain"}))
let title = document.querySelector('#above-the-fold #title')?.innerText ?? 'transcript'
$link.setAttribute('href', url)
$link.setAttribute('download', `${title}.txt`)
$link.click()
URL.revokeObjectURL(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment