Skip to content

Instantly share code, notes, and snippets.

@DavidBuchanan314
Last active April 8, 2022 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidBuchanan314/be42ae5e5e508dc1902f6f6844f80a59 to your computer and use it in GitHub Desktop.
Save DavidBuchanan314/be42ae5e5e508dc1902f6f6844f80a59 to your computer and use it in GitHub Desktop.
// edit this path according to your needs!
var projFile = "/Users/david/Sync/programming/python/boiga/test.sb3";
var fs = require("fs");
var vm = document.querySelector("#app")._reactRootContainer.current.child.child.child.stateNode.store.getState().scratchGui.vm;
var loading = false;
var watcher = fs.watch(projFile, async (event, filename) => {
if (!filename || loading) return;
var fileContents = await fs.promises.readFile(projFile);
if (!fileContents.length) return;
console.log("Reloading!");
if (loading) return;
loading = true;
try {
await vm.loadProject(fileContents);
} catch (e) {
console.log(e);
}
loading = false;
console.log("Done!");
vm.greenFlag();
});
// keep the stage on-screen when the window is narrowed
window.onresize = () => {document.body.parentElement.scrollLeft = 999999};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment