Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Uvacoder/efdfd50d63f736ede48f09b32686db56 to your computer and use it in GitHub Desktop.
Save Uvacoder/efdfd50d63f736ede48f09b32686db56 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