gasgasgas/js/promise.js

36 lines
1.0 KiB
JavaScript

async function putPromise(o) {
let c = 0;
const v = JSON.stringify(o);
const h = new jsSHA("SHA-256", "TEXT", { encoding: "UTF8" });
h.update(v);
const z = h.getHash("HEX");
g_persistIndex.push(z);
localStorage.setItem(PERSIST_STORAGEKEY, JSON.stringify(g_persistIndex));
for (let i = 0; i < g_persist.length; i++) {
const o = g_persist[i];
const r = await o.put(v);
c++;
stateChange(r, STATE.PROMISE_PERSIST);
}
}
async function scanPromises() {
const promises = localStorage.getItem(PERSIST_STORAGEKEY);
if (!promises) {
return;
}
const o = JSON.parse(promises);
const eList = document.createElement('ul');
eList.setAttribute('id', 'promiseList');
o.forEach(async (v) => {
const r = await g_persist[0].get(v); // replace with fadfada
const o = JSON.parse(r);
console.debug('o', o);
const eItem = document.createElement('li');
eItem.innerText = o.label;
eList.appendChild(eItem);
});
document.getElementById('promiseList').remove();
document.getElementById('promise').prepend(eList);
}