diff --git a/docs/local-storage.md b/docs/local-storage.md index 0151ef86a2..bf830338c7 100644 --- a/docs/local-storage.md +++ b/docs/local-storage.md @@ -44,6 +44,12 @@ Or delete everything stored in the namespace: delete storage :: #0FBD8C ``` +If you ever loose track of what variables you previously set in storage, you can use the below block. It will return an array of all variables (or 'keys') in storage. + +```scratch +(all keys from storage :: #0FBD8C) +``` + ## Performance The local storage extension is inevitably slower than regular variables. diff --git a/extensions/local-storage.js b/extensions/local-storage.js index 85e02b635e..3a67b4935b 100644 --- a/extensions/local-storage.js +++ b/extensions/local-storage.js @@ -199,6 +199,12 @@ }, }, }, + { + opcode: "getAll", + blockType: Scratch.BlockType.REPORTER, + text: Scratch.translate("all keys from storage"), + disableMonitor: true, + }, { opcode: "removeAll", blockType: Scratch.BlockType.COMMAND, @@ -258,6 +264,14 @@ saveToLocalStorage(); } + getAll() { + if (!validNamespace()) { + return ""; + } + + return JSON.stringify(Object.keys(namespaceValues)); + } + removeAll() { if (!validNamespace()) { return "";