Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mamayaya1
GitHub Repository: mamayaya1/game
Path: blob/main/projects/9007199254740992/js/local_score_manager.js
4626 views
1
window.fakeStorage = {
2
_data: {},
3
4
setItem: function (id, val) {
5
return this._data[id] = String(val);
6
},
7
8
getItem: function (id) {
9
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
10
},
11
12
removeItem: function (id) {
13
return delete this._data[id];
14
},
15
16
clear: function () {
17
return this._data = {};
18
}
19
};
20
21
function LocalScoreManager() {
22
var localSupported = !!window.localStorage;
23
24
this.key = "bestScore_9007199254740992";
25
this.storage = localSupported ? window.localStorage : window.fakeStorage;
26
}
27
28
LocalScoreManager.prototype.get = function () {
29
return this.storage.getItem(this.key) || 0;
30
};
31
32
LocalScoreManager.prototype.set = function (score) {
33
this.storage.setItem(this.key, score);
34
};
35
36