54e3099c56
- Controller lifetime is bound to route lifetime - View lifetime is bound to controller lifetime - Control lifetime is bound to view lifetime - Enhanced event dispatching - Enhanced responsiveness in some places - Views communicate user input to controllers via new event system
40 lines
913 B
JavaScript
40 lines
913 B
JavaScript
'use strict';
|
|
|
|
const events = require('../events.js');
|
|
|
|
const defaultSettings = {
|
|
listPosts: {
|
|
safe: true,
|
|
sketchy: true,
|
|
unsafe: false,
|
|
},
|
|
upscaleSmallPosts: false,
|
|
endlessScroll: false,
|
|
keyboardShortcuts: true,
|
|
transparencyGrid: true,
|
|
};
|
|
|
|
class Settings extends events.EventTarget {
|
|
save(newSettings, silent) {
|
|
localStorage.setItem('settings', JSON.stringify(newSettings));
|
|
if (silent !== true) {
|
|
this.dispatchEvent(new CustomEvent('change', {
|
|
detail: {
|
|
settings: this.get(),
|
|
},
|
|
}));
|
|
}
|
|
}
|
|
|
|
get() {
|
|
let ret = {};
|
|
Object.assign(ret, defaultSettings);
|
|
try {
|
|
Object.assign(ret, JSON.parse(localStorage.getItem('settings')));
|
|
} catch (e) {
|
|
}
|
|
return ret;
|
|
}
|
|
};
|
|
|
|
module.exports = new Settings();
|