Online Settings Persistence #253
-
Hi! I absolutely love Bonjourr and use it across several browsers and devices. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @98h398hrpohpoai ! The online version is using localStorage and not cookies, which is fairly simple to get / update. However because of that, the settings are only accessible from the page. I can look into the File System API, but because of security reasons it is kind of hard to work with. So no promises ! In the meantime, you could add some sort of function in your server - maybe in PHP - that can store a text file, then add this script on top of <!-- index.html -->
<script>
// Apply settings before Bonjourr does
fetch("http://localhost:8888/somefunction/get").then(data => {
for (const [key, val] of Object.entries(JSON.parse(data))) {
localStorage.setItem(key, val)
}
})
// Listen to changes and send them to your server
window.addEventListener('storage', () => {
fetch("http://localhost:8888/somefunction/set", {
body: JSON.stringify(localStorage),
method: "POST",
})
})
</script>
<script src="src/scripts/main.js" defer="defer"></script> To get the settings from the console for reference: // Get settings
JSON.stringify(localStorage)
// Update settings
for (const [key, val] of Object.entries("... your settings")) {
localStorage.setItem(key, val)
} Let me know if it helps ! |
Beta Was this translation helpful? Give feedback.
Hello @98h398hrpohpoai !
The online version is using localStorage and not cookies, which is fairly simple to get / update. However because of that, the settings are only accessible from the page. I can look into the File System API, but because of security reasons it is kind of hard to work with. So no promises !
In the meantime, you could add some sort of function in your server - maybe in PHP - that can store a text file, then add this script on top of
main.js
inindex.html
to store the settings every time you save: