Download:
child 41:7a3b9afbfb82
parent 39:e50cac3a27e6
40:a83c7e621ae6
Anton Shestakov <av6@dwimlabs.net>, Wed, 11 Jul 2018 23:54:30 +0800
index: save/restore settings using localStorage

1 files changed, 20 insertions(+), 0 deletions(-) [+]
index.html file | annotate | diff | comparison | revisions
--- a/index.html Sun Jul 08 16:53:08 2018 +0800
+++ b/index.html Wed Jul 11 23:54:30 2018 +0800
@@ -111,6 +111,26 @@
$(function() {
var player = window.player = new Player();
+ var storageKey = 'gme-player-settings';
+ var saveKeys = ['autoplay', 'repeat', 'random'];
+ var changeEvents = _(saveKeys).map(function(key) { return 'change:' + key; }).join(' ');
+ var settings = window.localStorage.getItem(storageKey);
+ if (settings) {
+ try {
+ settings = JSON.parse(settings);
+ } catch(e) {
+ window.localStorage.removeItem(storageKey);
+ settings = null;
+ }
+ }
+ if (settings) {
+ player.set(_(settings).pick(saveKeys));
+ }
+ player.on(changeEvents, function() {
+ settings = _(player.toJSON()).pick(saveKeys);
+ window.localStorage.setItem(storageKey, JSON.stringify(settings));
+ });
+
player.on('change:track', function() {
$('title').text(player.get('track').get('song'));
});