reworked import/export to support files instead of clipboard
This commit is contained in:
+44
-48
@@ -415,21 +415,6 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="expandableMenuToggle" onclick="toggleExpandableMenu(this)">
|
|
||||||
<p>sharing / backing up (import/export tab)</p>
|
|
||||||
<p class="expandedMenuIndicator">+</p>
|
|
||||||
</div>
|
|
||||||
<div class="expandableMenu">
|
|
||||||
<p>
|
|
||||||
you can export your current page's entire setup to your clipboard in the
|
|
||||||
"import / export" tab. save the contents somewhere on your computer to store
|
|
||||||
your theme for later or for sharing with others.<br /><br />
|
|
||||||
|
|
||||||
to load in a theme, simply paste exported data into the "import" input,
|
|
||||||
and refresh the page (ignore the warning that saved data will be lost).
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="containerPage" class="tabContent">
|
<div id="containerPage" class="tabContent">
|
||||||
@@ -482,16 +467,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="ioPage" class="tabContent">
|
<div id="ioPage" class="tabContent">
|
||||||
<div style="margin-top: 2.5rem">
|
<div style="display: flex; flex-direction: column; margin: 2rem 0; gap: 1rem;align-items:center;">
|
||||||
<button style="height: 3rem; width: 100%; margin-bottom: 2.5rem;" onclick="exportData()">export data</button>
|
<p class="menuHeader">import theme file</p>
|
||||||
|
<input id="import-input" type="file" accept".txt" style="width: 45%; align-self: center" />
|
||||||
|
|
||||||
|
<button style="width: 100%; height: 3rem;" onclick="importData()" >
|
||||||
|
set new theme
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
<div style="display: flex; flex-direction: column; margin-top: 2.5rem; gap: 1rem;align-items:center;">
|
<div style="margin-top:1rem;">
|
||||||
<input id="importDataInput" style="width: 90%; align-self: center" placeholder="paste theme data to import here"/>
|
<p class="menuHeader">export current page as theme</p>
|
||||||
<button style="width: 100%; height: 3rem;" onclick="importData()" >
|
<a id="export-button" download="startpage_theme_export.txt" href="">
|
||||||
import data
|
<button style="height: 3rem; width: 100%; margin-bottom: 2.5rem;">export data</button>
|
||||||
</button>
|
</a>
|
||||||
<span style="font-size: .8rem">(see help tab for more information)</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -583,6 +572,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
todo: enable changing color of edit page toggle? remove underline from links? nudge elements 1px with arrow keys? reset data button?
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
@@ -2103,6 +2093,11 @@
|
|||||||
links[i].style.cursor = cursors.link ? 'url("' + cursors.link + '"), pointer' : "pointer";
|
links[i].style.cursor = cursors.link ? 'url("' + cursors.link + '"), pointer' : "pointer";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lastly, set current state as download contents for export button
|
||||||
|
const exportData = new Blob([JSON.stringify(localStorage)], {type: 'text/plain'});
|
||||||
|
const url = window.URL.createObjectURL(exportData);
|
||||||
|
document.getElementById("export-button").href = url;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/**************************
|
/**************************
|
||||||
@@ -2226,6 +2221,11 @@
|
|||||||
// save active settings tab for next session
|
// save active settings tab for next session
|
||||||
localStorage.setItem("activeTabId", JSON.stringify(activeTabId));
|
localStorage.setItem("activeTabId", JSON.stringify(activeTabId));
|
||||||
|
|
||||||
|
// lastly, set current state as download contents for export button
|
||||||
|
const exportData = new Blob([JSON.stringify(localStorage)], {type: 'text/plain'});
|
||||||
|
const url = window.URL.createObjectURL(exportData);
|
||||||
|
document.getElementById("export-button").href = url;
|
||||||
|
|
||||||
document.getElementById("editToggle").innerHTML = "edit page";
|
document.getElementById("editToggle").innerHTML = "edit page";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3428,40 +3428,36 @@
|
|||||||
/************************************
|
/************************************
|
||||||
* RESET / IMPORT & EXPORT HANDLERS *
|
* RESET / IMPORT & EXPORT HANDLERS *
|
||||||
************************************/
|
************************************/
|
||||||
async function exportData() {
|
|
||||||
try {
|
|
||||||
window.focus();
|
|
||||||
await navigator.clipboard.writeText(JSON.stringify(localStorage));
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error.message);
|
|
||||||
}
|
|
||||||
alert(
|
|
||||||
"export to clipboard successful. paste contents to file and keep safe!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function importData(buttonClick) {
|
function importData(buttonClick) {
|
||||||
let data = document.getElementById("importDataInput").value;
|
let input = document.getElementById("import-input").files[0];
|
||||||
if (data == "") {
|
if (!input) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(document.getElementById("importDataInput").value);
|
const reader = new FileReader();
|
||||||
} catch (error) {
|
reader.onload = () => {
|
||||||
|
let themeData = reader.result;
|
||||||
|
themeData = JSON.parse(themeData);
|
||||||
|
for (const [key, value] of Object.entries(themeData)) {
|
||||||
|
localStorage.setItem(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
alert(
|
||||||
|
"data import successful. " +
|
||||||
|
"please refresh the page!" +
|
||||||
|
"\n(you can ignore unsaved changes warning, the imported data has already been loaded + stored)"
|
||||||
|
);
|
||||||
|
justImported = true;
|
||||||
|
}
|
||||||
|
reader.readAsText(input);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
alert("please only enter data that was provided by the export button!");
|
alert("please only enter data that was provided by the export button!");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(data)) {
|
|
||||||
localStorage.setItem(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
alert(
|
|
||||||
"data import successful. " +
|
|
||||||
"please refresh the page!" +
|
|
||||||
"\n(you can ignore unsaved changes warning, the imported data has already been loaded + stored)"
|
|
||||||
);
|
|
||||||
justImported = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************
|
/*****************
|
||||||
|
|||||||
Reference in New Issue
Block a user