Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@SheepTester
Last active May 12, 2020 04:31
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 SheepTester/bd0db510aba903cb3723dc3eeb23c2c4 to your computer and use it in GitHub Desktop.
Save SheepTester/bd0db510aba903cb3723dc3eeb23c2c4 to your computer and use it in GitHub Desktop.
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