forked from scratchfoundation/scratchx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localstorage_extension.js
46 lines (36 loc) · 1.33 KB
/
localstorage_extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Extension using the JavaScript localStorage API */
/* Sayamindu Dasgupta <[email protected]>, April 2014 */
new (function() {
var ext = this;
ext.set_localstorage = function (data) {
localStorage.setItem(app.projectModel.id.toString(), data);
};
ext.change_localstorage = function(change) {
var data = localStorage.getItem(app.projectModel.id.toString());
if (!isNaN(parseFloat(data))) {
localStorage.setItem(app.projectModel.id.toString(), parseFloat(data) + change);
}
};
ext.get_localstorage = function () {
return localStorage.getItem(app.projectModel.id.toString());
};
ext._shutdown = function() {};
ext._getStatus = function() {
var test = 'test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
} catch(e) {
return {status: 1, msg: 'Your browser does not support the localStorage API'};
}
return {status: 2, msg: 'Ready'};
};
var descriptor = {
blocks: [
['', 'set local data to %s', 'set_localstorage', '0'],
['', 'change local data by %d', 'change_localstorage', 1],
['r', 'local data', 'get_localstorage'],
],
};
ScratchExtensions.register('Local Storage', descriptor, ext);
})();