Skip to content

Instantly share code, notes, and snippets.

@belmarca
Created March 13, 2023 17:24
Show Gist options
  • Save belmarca/b6686547676ec4bcf9afe9df9cf6c5c4 to your computer and use it in GitHub Desktop.
Save belmarca/b6686547676ec4bcf9afe9df9cf6c5c4 to your computer and use it in GitHub Desktop.
Download files from a codeBoot VM from a browser console
// 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