mirror of
https://github.com/danog/2048.git
synced 2024-12-14 10:17:34 +01:00
664546ef9a
Dependency injection and hide best score for incompatible browsers
25 lines
443 B
JavaScript
25 lines
443 B
JavaScript
function LocalScoreManager() {
|
|
this.key = 'bestScore';
|
|
}
|
|
|
|
LocalScoreManager.prototype.get = function () {
|
|
if (!this.isSupported()) {
|
|
return 0;
|
|
}
|
|
|
|
return localStorage.getItem(this.key);
|
|
};
|
|
|
|
LocalScoreManager.prototype.set = function (score) {
|
|
if (!this.isSupported()) {
|
|
return false;
|
|
}
|
|
|
|
localStorage.setItem(this.key, score);
|
|
};
|
|
|
|
LocalScoreManager.prototype.isSupported = function () {
|
|
return !!window.localStorage;
|
|
};
|
|
|