Summary Files Commits Branches @commit @diff @stats
path: root / checklist.html
diff options
context:
space:
mode:
Commit26b82aa1778cb5257d8419349046db25bd5f30a5 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-06-22 15:32:21 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-06-22 15:32:21 +0300
Filesde077f016d3106be6916cfd06940aff035400943 /checklist.html
small-web-utilities-26b82aa1778cb5257d8419349046db25bd5f30a5.tar
small-web-utilities-26b82aa1778cb5257d8419349046db25bd5f30a5.tar.gz
small-web-utilities-26b82aa1778cb5257d8419349046db25bd5f30a5.zip
Parente16024e0aadb53685a5e968e80a2c8f1ebe009f9 (diff)
(checklist) Replaced import-export to URL with IndexedDB
URL has length limit which could easily be hit
1 files changed, 48 insertions, 15 deletions
-rw-r--r--checklist.html63
diff --git a/checklist.html b/checklist.html
index dcb8f95..d93db49 100644
--- a/checklist.html
+++ b/checklist.html
@@ -16,7 +16,7 @@
<style>
#lists {
position: relative;
- padding-left: 6em;
+ padding-left: 7em;
margin-top: 0.5em;
}
@@ -83,6 +83,7 @@ input {
<input type="button" value="Import" id="import-btn">
<input type="button" value="Export" id="export-btn">
<input type="text" id="exp-imp-text">
+ <select id="db-lists"></select>
</div>
<br>
<input type="button" value="Uncheck all" id="uncheck-all">
@@ -96,7 +97,6 @@ input {
const stylesheetLocked = document.getElementById('stylesheet-locked');
stylesheetLocked.disabled = true;
const expImpText = document.getElementById('exp-imp-text');
- const url = new URL(location.href);
/* Item functionality */
@@ -223,8 +223,23 @@ input {
document.getElementById('check-all').onclick = function () {
changeCheckLists(true);
}
-
+ </script>
+ <script>
/* Import-export */
+
+ const dropdown = document.getElementById('db-lists');
+ const dbRequest = window.indexedDB.open('checklist', 1);
+ var db = '', store = '';
+
+ dbRequest.onupgradeneeded = function() {
+ db = dbRequest.result;
+ store = db.createObjectStore('CheckLists', { keyPath: 'name' });
+ store.createIndex('name', 'name', { unique: true });
+ store.createIndex('data', 'data');
+ }
+ dbRequest.onerror = function() {
+ console.log('Error ', dbRequest.error);
+ }
function stringify(current) {
var str = "";
@@ -294,20 +309,38 @@ input {
}
}
- document.getElementById('import-btn').onclick = function () {
- if (expImpText.value != "")
- parse(expImpText.value, lists);
- else
- parse(url.searchParams.get('list'), lists);
- }
+ // while (db == '') {}
- document.getElementById('export-btn').onclick = function () {
- expImpText.value = stringify().substring(1);
- url.searchParams.set('list', expImpText.value);
- history.pushState(null, '', url);
- }
+ dbRequest.onsuccess = function() {
+ db = dbRequest.result;
- document.getElementById('import-btn').click();
+ var store = db.transaction('CheckLists', 'readwrite').objectStore('CheckLists');
+ var all = store.getAll();
+ all.onsuccess = function() {
+ all.result.forEach(function (l) {
+ var nop = document.createElement('option');
+ nop.value = l.name;
+ nop.innerText = l.name;
+ dropdown.appendChild(nop);
+ });
+ }
+
+ document.getElementById('import-btn').onclick = function () {
+ const name = dropdown.options[dropdown.selectedIndex].text;
+ var store = db.transaction('CheckLists', 'readwrite').objectStore('CheckLists');
+ var val = store.get(name);
+ val.onsuccess = function() {
+ parse(val.result.value, lists);
+ }
+ }
+
+ document.getElementById('export-btn').onclick = function () {
+ expImpText.value = stringify().substring(1);
+
+ var store = db.transaction('CheckLists', 'readwrite').objectStore('CheckLists');
+ store.put({ name: 'ListTest', value: expImpText.value });
+ }
+ }
</script>
</body>
</html>