Path: blob/main/projects/doge2048/js/local_score_manager.js
4626 views
window.fakeStorage = {1_data: {},23setItem: function (id, val) {4return this._data[id] = String(val);5},67getItem: function (id) {8return this._data.hasOwnProperty(id) ? this._data[id] : undefined;9},1011removeItem: function (id) {12return delete this._data[id];13},1415clear: function () {16return this._data = {};17}18};1920function LocalScoreManager() {21this.key = "bestScore";2223var supported = this.localStorageSupported();24this.storage = supported ? window.localStorage : window.fakeStorage;25}2627LocalScoreManager.prototype.localStorageSupported = function () {28var testKey = "test";29var storage = window.localStorage;3031try {32storage.setItem(testKey, "1");33storage.removeItem(testKey);34return true;35} catch (error) {36return false;37}38};3940LocalScoreManager.prototype.get = function () {41return this.storage.getItem(this.key) || 0;42};4344LocalScoreManager.prototype.set = function (score) {45this.storage.setItem(this.key, score);46};474849