mirror of https://gitgud.io/fatchan/jschan.git
close #186 user settings import and export feature
and fix a few bugs with unset or incorrect defaults in localstorage.jsjschan
parent
72dc15e7f2
commit
d258f5cebe
4 changed files with 52 additions and 4 deletions
@ -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); |
||||||
|
|
||||||
|
}); |
Loading…
Reference in new issue