Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Created June 20, 2026 22:41
Show Gist options
  • Select an option

  • Save n8henrie/89f3d5a44585f947adcb4ffe7c2f39b2 to your computer and use it in GitHub Desktop.

Select an option

Save n8henrie/89f3d5a44585f947adcb4ffe7c2f39b2 to your computer and use it in GitHub Desktop.
Save data from a JavaScript session in your browser console
// Example:
// var data = Array.from(document.querySelectorAll('a[href*="youtu"]')).map(a => a.href)
// console.save(data.join("\n"), "urls.txt")
console.save = function (data, filename) {
if (!data) {
console.error('Console.save: No data')
return
}
if (!filename) {
console.error('Console.save: No filename')
return
}
if (typeof data === "object") {
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {
type: 'text/json'
}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment