Created
June 20, 2026 22:41
-
-
Save n8henrie/89f3d5a44585f947adcb4ffe7c2f39b2 to your computer and use it in GitHub Desktop.
Save data from a JavaScript session in your browser console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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