mirror of
https://github.com/YunoHost-Apps/20euros_ynh.git
synced 2024-09-03 18:05:53 +02:00
48 lines
996 B
JavaScript
Executable file
48 lines
996 B
JavaScript
Executable file
window.fakeStorage = {
|
|
_data: {},
|
|
|
|
setItem: function (id, val) {
|
|
return this._data[id] = String(val);
|
|
},
|
|
|
|
getItem: function (id) {
|
|
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
|
|
},
|
|
|
|
removeItem: function (id) {
|
|
return delete this._data[id];
|
|
},
|
|
|
|
clear: function () {
|
|
return this._data = {};
|
|
}
|
|
};
|
|
|
|
function LocalScoreManager() {
|
|
this.key = "bestScore";
|
|
|
|
var supported = this.localStorageSupported();
|
|
this.storage = supported ? window.localStorage : window.fakeStorage;
|
|
}
|
|
|
|
LocalScoreManager.prototype.localStorageSupported = function () {
|
|
var testKey = "test";
|
|
var storage = window.localStorage;
|
|
|
|
try {
|
|
storage.setItem(testKey, "1");
|
|
storage.removeItem(testKey);
|
|
return true;
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
LocalScoreManager.prototype.get = function () {
|
|
return this.storage.getItem(this.key) || 0;
|
|
};
|
|
|
|
LocalScoreManager.prototype.set = function (score) {
|
|
this.storage.setItem(this.key, score);
|
|
};
|
|
|