Last active
May 12, 2020 04:31
-
-
Save SheepTester/bd0db510aba903cb3723dc3eeb23c2c4 to your computer and use it in GitHub Desktop.
Scratch 3.0 version of https://jgames101.github.io/scratch-extensions/js/localstorage.js
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
const ArgumentType = require('../../extension-support/argument-type') | |
const BlockType = require('../../extension-support/block-type') | |
class LocalStorage { | |
constructor () {} | |
getInfo () { | |
return { | |
id: 'localstorage', | |
name: 'LocalStorage', | |
blocks: [ | |
{ | |
opcode: 'readLocalStorage', | |
blockType: BlockType.REPORTER, | |
text: '[NAME]', | |
arguments: { | |
NAME: { | |
type: ArgumentType.STRING, | |
defaultValue: 'highscore' | |
} | |
} | |
}, | |
{ | |
opcode: 'setLocalStorage', | |
blockType: BlockType.COMMAND, | |
text: 'set [NAME] to [VALUE]', | |
arguments: { | |
NAME: { | |
type: ArgumentType.STRING, | |
defaultValue: 'highscore' | |
}, | |
VALUE: { | |
type: ArgumentType.STRING, | |
defaultValue: '12' | |
} | |
} | |
} | |
] | |
} | |
} | |
readLocalStorage ({ NAME }) { | |
return localStorage.getItem(NAME) | |
} | |
setLocalStorage ({ NAME, VALUE }) { | |
return localStorage.setItem(NAME, VALUE) | |
} | |
} | |
module.exports = LocalStorage |
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
importScripts('https://cdnjs.cloudflare.com/ajax/libs/localforage/1.7.3/localforage.min.js') | |
class LocalStorage { | |
constructor () {} | |
getInfo () { | |
return { | |
id: 'localstorage', | |
name: 'LocalStorage', | |
blocks: [ | |
{ | |
opcode: 'readLocalStorage', | |
blockType: Scratch.BlockType.REPORTER, | |
text: '[NAME]', | |
arguments: { | |
NAME: { | |
type: Scratch.ArgumentType.STRING, | |
defaultValue: 'highscore' | |
} | |
} | |
}, | |
{ | |
opcode: 'setLocalStorage', | |
blockType: Scratch.BlockType.COMMAND, | |
text: 'set [NAME] to [VALUE]', | |
arguments: { | |
NAME: { | |
type: Scratch.ArgumentType.STRING, | |
defaultValue: 'highscore' | |
}, | |
VALUE: { | |
type: Scratch.ArgumentType.STRING, | |
defaultValue: '12' | |
} | |
} | |
} | |
] | |
} | |
} | |
readLocalStorage ({ NAME }) { | |
return localforage.getItem(NAME) | |
} | |
setLocalStorage ({ NAME, VALUE }) { | |
return localforage.setItem(NAME, VALUE) | |
} | |
} | |
Scratch.extensions.register(new LocalStorage()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try it on E羊icques: https://sheeptester.github.io/scratch-gui/?extension=https://sheeptester.github.io/hello-world/localStorage-extension.js
From the forums