Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
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
You can’t perform that action at this time.