Created
March 13, 2023 17:24
-
-
Save belmarca/b6686547676ec4bcf9afe9df9cf6c5c4 to your computer and use it in GitHub Desktop.
Download files from a codeBoot VM from a browser console
This file contains 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
// Download files from a codeBoot VM from a browser console | |
// https://stackoverflow.com/a/18197341 | |
function download(filename, text) { | |
var element = document.createElement('a'); | |
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | |
element.setAttribute('download', filename); | |
element.style.display = 'none'; | |
document.body.appendChild(element); | |
element.click(); | |
document.body.removeChild(element); | |
} | |
let vms = Object.keys(localStorage).filter(e => e.startsWith("#cb-vm-")); | |
for (vm of vms) { | |
console.log(`Downloading files for ${vm} ...`); | |
const vmState = JSON.parse(localStorage[vm]); | |
for (file of vmState.files) { | |
console.log(`Downloading ${file.filename} ...`); | |
download(file.filename, file.content); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment