2016-06-14 10:31:48 +02: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 18:54:49 +02:00
|
|
|
fitMode: 'fit-both',
|
2016-07-31 23:07:01 +02:00
|
|
|
tagSuggestions: true,
|
2016-11-11 23:14:51 +01:00
|
|
|
autoplayVideos: false,
|
2016-08-27 16:16:50 +02:00
|
|
|
postsPerPage: 42,
|
2019-05-22 23:08:26 +02:00
|
|
|
tagUnderscoresAsSpaces: false,
|
2016-06-14 10:31:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Settings extends events.EventTarget {
|
|
|
|
save(newSettings, silent) {
|
2016-09-10 11:22:09 +02:00
|
|
|
newSettings = Object.assign(this.get(), newSettings);
|
2016-06-14 10:31:48 +02:00
|
|
|
localStorage.setItem('settings', JSON.stringify(newSettings));
|
|
|
|
if (silent !== true) {
|
|
|
|
this.dispatchEvent(new CustomEvent('change', {
|
|
|
|
detail: {
|
|
|
|
settings: this.get(),
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get() {
|
2016-09-10 11:22:09 +02:00
|
|
|
let ret = Object.assign({}, defaultSettings);
|
2016-06-14 10:31:48 +02:00
|
|
|
try {
|
|
|
|
Object.assign(ret, JSON.parse(localStorage.getItem('settings')));
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = new Settings();
|