1
0
mirror of https://github.com/danog/2048.git synced 2024-12-14 10:17:34 +01:00
2048/js/local_score_manager.js
Tim Petricola 664546ef9a Store best score in localStorage
Dependency injection and hide best score for incompatible browsers
2014-03-10 16:21:05 -04:00

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;
};