Path: blob/main/projects/meme2048/js/local_storage_manager.js
1836 views
function LocalStorageManager(){this.bestScoreKey="bestScore",this.gameStateKey="gameState";var t=this.localStorageSupported();this.storage=t?window.localStorage:window.fakeStorage}window.fakeStorage={_data:{},setItem:function(t,e){return this._data[t]=String(e)},getItem:function(t){return this._data.hasOwnProperty(t)?this._data[t]:void 0},removeItem:function(t){return delete this._data[t]},clear:function(){return this._data={}}},LocalStorageManager.prototype.localStorageSupported=function(){var t=window.localStorage;try{return t.setItem("test","1"),t.removeItem("test"),!0}catch(t){return!1}},LocalStorageManager.prototype.getBestScore=function(){return this.storage.getItem(this.bestScoreKey)||0},LocalStorageManager.prototype.setBestScore=function(t){this.storage.setItem(this.bestScoreKey,t)},LocalStorageManager.prototype.getGameState=function(){var t=this.storage.getItem(this.gameStateKey);return t?JSON.parse(t):null},LocalStorageManager.prototype.setGameState=function(t){this.storage.setItem(this.gameStateKey,JSON.stringify(t))},LocalStorageManager.prototype.clearGameState=function(){this.storage.removeItem(this.gameStateKey)};123