mirror of
https://github.com/danog/2048.git
synced 2024-12-13 17:57:42 +01:00
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;
|
||
|
};
|
||
|
|