close #186 user settings import and export feature

and fix a few bugs with unset or incorrect defaults in localstorage.js
jschan
Thomas Lynch 3 years ago
parent 72dc15e7f2
commit d258f5cebe
  1. 1
      CHANGELOG.md
  2. 37
      gulp/res/js/importexport.js
  3. 3
      gulp/res/js/localstorage.js
  4. 15
      views/mixins/modal.pug

@ -35,3 +35,4 @@
- Board owners can now edit custom pages
- Show a little message and disable reply form on full threads (hit reply limit)
- Allow longer language names for code blocks
- User settings import and export option

@ -0,0 +1,37 @@
window.addEventListener('settingsReady', () => {
const settingNames = ['volume','loop','imageloadingbars','live','scroll','localtime','relative','24hour','notifications','hiddenimages'
,'notification-yous-only','yous-setting','filters1','name','theme','codetheme','customcss','disableboardcss','hiderecursive'
,'heightlimit','crispimages','hidethumbnails','noncolorids','alwaysshowspoilers','hidepoststubs','smoothscrolling'];
const importExportText = document.getElementById('import-export-setting');
const exportSettingsButton = document.getElementById('export-setting');
const exportSettings = () => {
const settingsData = settingNames.reduce((acc, val) => {
acc[val] = localStorage.getItem(val);
return acc;
}, {});
importExportText.value = JSON.stringify(settingsData);
}
exportSettingsButton.addEventListener('click', exportSettings, false);
const importSettingsButton = document.getElementById('import-setting');
const importSettings = () => {
if (importExportText.value.length > 0) {
try {
const importedSettings = JSON.parse(importExportText.value);
Object.entries(importedSettings).forEach(entry => {
setLocalStorage(entry[0], entry[1]);
});
//should we have an update listener one day to import without refresh?
location.reload();
} catch (e) {
//bad data
console.error(e);
}
}
}
importSettingsButton.addEventListener('click', importSettings, false);
});

@ -40,13 +40,14 @@ setDefaultLocalStorage('volume', settings.defaultVolume);
setDefaultLocalStorage('loop', settings.loop);
setDefaultLocalStorage('imageloadingbars', settings.imageLoadingBars);
setDefaultLocalStorage('live', settings.live);
setDefaultLocalStorage('scroll', settings.sctollToPosts);
setDefaultLocalStorage('scroll', settings.scrollToPosts);
setDefaultLocalStorage('localtime', settings.localTime);
setDefaultLocalStorage('relative', settings.relativeTime);
setDefaultLocalStorage('24hour', settings.hour24Time);
setDefaultLocalStorage('notifications', settings.notificationsEnabled);
setDefaultLocalStorage('notification-yous-only', settings.notificationsYousOnly);
setDefaultLocalStorage('yous-setting', settings.showYous);
setDefaultLocalStorage('disableboardcss', false);
setDefaultLocalStorage('dragtop', null);
setDefaultLocalStorage('dragleft', null);

@ -100,7 +100,7 @@ mixin modal(data)
.row
label.postform-style.ph-5
input#alwaysshowspoilers-setting(type='checkbox')
.rlabel Always reveal spoilers
.rlabel Always reveal text spoilers
.row
label.postform-style.ph-5
input#yous-setting(type='checkbox')
@ -109,7 +109,7 @@ mixin modal(data)
label.postform-style.ph-5
input#smoothscrolling-setting(type='checkbox')
.rlabel Smooth scrolling
.row
.row.mt-5
.label (You)s
input.mr-1#youslist-setting(type='text' readonly)
input#youslist-clear(type='button' value='Clear')
@ -146,7 +146,7 @@ mixin modal(data)
.row
.label Custom CSS
textarea#customcss-setting(rows=7)
.row
.row.mt-5
form.text-center#filter-form
table
tbody#advancedfilters
@ -171,3 +171,12 @@ mixin modal(data)
td
input(type='checkbox' name='regex')
td: input.right(type='submit' value='Add')
.row.mt-5
.label
| Import/Export Settings
small.title Do NOT import untrusted settings data!
small Export does not include post password or (You)'s
textarea#import-export-setting(type='text')
.row
input.mr-1#export-setting(type='button' value='Export')
input#import-setting(type='button' value='Import')

Loading…
Cancel
Save