-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
It will be more functional if you put backup buttons on the configuration page.
A simple example, maybe it will help.
(function() {
'use strict';
// Export Button
let exportButton = document.createElement("button");
exportButton.innerHTML = "Export";
exportButton.style.position = "fixed";
exportButton.style.top = "10px";
exportButton.style.right = "10px";
exportButton.style.zIndex = "1000";
exportButton.onclick = function() {
let data = JSON.stringify(localStorage);
let blob = new Blob([data], { type: 'application/json' });
let url = URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = 'localStorageData.json';
a.click();
URL.revokeObjectURL(url);
};
document.body.appendChild(exportButton);
// Import Button
let importButton = document.createElement("button");
importButton.innerHTML = "Import";
importButton.style.position = "fixed";
importButton.style.top = "50px";
importButton.style.right = "10px";
importButton.style.zIndex = "1000";
importButton.onclick = function() {
let input = document.createElement('input');
input.type = 'file';
input.accept = 'application/json';
input.onchange = function(event) {
let file = event.target.files[0];
let reader = new FileReader();
reader.onload = function(e) {
let data = JSON.parse(e.target.result);
for (let key in data) {
localStorage.setItem(key, data[key]);
}
alert('Imported!');
};
reader.readAsText(file);
};
input.click();
};
document.body.appendChild(importButton);
})();
Metadata
Metadata
Assignees
Labels
No labels