Created
July 15, 2017 19:33
-
-
Save webdestroya/e2bb0104b912b7684db825136882a9c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MemoryStorage, e, | |
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | |
hasProp = {}.hasOwnProperty; | |
MemoryStorage = (function(superClass) { | |
extend(MemoryStorage, superClass); | |
function MemoryStorage() { | |
this.db = {}; | |
} | |
MemoryStorage.prototype.getItem = function(key) { | |
if (this.db.hasOwnProperty(key)) { | |
return this.db[key]; | |
} else { | |
return void 0; | |
} | |
}; | |
MemoryStorage.prototype.setItem = function(key, value) { | |
this.db[key] = value; | |
return true; | |
}; | |
MemoryStorage.prototype.clear = function() { | |
return this.db = {}; | |
}; | |
MemoryStorage.prototype.removeItem = function(key) { | |
delete this.db[key]; | |
}; | |
return MemoryStorage; | |
})(Storage); | |
Object.defineProperty(MemoryStorage.prototype, "length", { | |
get: function() { | |
return Object.keys(this.db).length; | |
} | |
}); | |
window.MemoryStorage = MemoryStorage; | |
try { | |
window.localStorage.setItem("enabled", "true"); | |
window.localStorage.removeItem("enabled"); | |
window.pubgStorage = window.localStorage; | |
} catch (error) { | |
e = error; | |
window.pubgStorage = new MemoryStorage(); | |
} | |
// then you can just use `window.pubgStorage` for everything |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment