| 1 |
import { getById, debounce, writeError, resetLog } from "/common.module.js"; |
| 2 |
import lzString from "/lz-string.module.js"; |
| 3 |
|
| 4 |
let input = undefined; |
| 5 |
export function onLoad() { |
| 6 |
input = getById("input"); |
| 7 |
input.addEventListener("input", debounce(() => { |
| 8 |
if (input.value === '') { |
| 9 |
window.location.hash = '' |
| 10 |
} |
| 11 |
else { |
| 12 |
window.location.hash = '#' + lzString.compressToEncodedURIComponent(input.value); |
| 13 |
} |
| 14 |
resetLog(); |
| 15 |
}, 10)) |
| 16 |
|
| 17 |
window.addEventListener('hashchange', loadState); |
| 18 |
loadState(); |
| 19 |
} |
| 20 |
|
| 21 |
export function onUpdate() { |
| 22 |
loadState(); |
| 23 |
} |
| 24 |
|
| 25 |
function loadState() { |
| 26 |
if (window.location.hash !== '') { |
| 27 |
input.value = lzString.decompressFromEncodedURIComponent(window.location.hash.substring(1)); |
| 28 |
if (input.value === '') { |
| 29 |
|
| 30 |
writeError("Failed to load note from url.") |
| 31 |
} |
| 32 |
} |
| 33 |
} |