2016-06-14 08:31:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const events = require('../events.js');
|
|
|
|
|
|
|
|
const defaultSettings = {
|
|
|
|
listPosts: {
|
|
|
|
safe: true,
|
|
|
|
sketchy: true,
|
|
|
|
unsafe: false,
|
|
|
|
},
|
|
|
|
upscaleSmallPosts: false,
|
|
|
|
endlessScroll: false,
|
|
|
|
keyboardShortcuts: true,
|
|
|
|
transparencyGrid: true,
|
2016-06-29 16:54:49 +00:00
|
|
|
fitMode: 'fit-both',
|
2016-07-31 21:07:01 +00:00
|
|
|
tagSuggestions: true,
|
2016-08-27 14:16:50 +00:00
|
|
|
postsPerPage: 42,
|
2016-06-14 08:31:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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();
|