import { loadAndParseTwtxtFile } from "/dist-browser/twtxt-lib.js"; const tabLoadAndParsePanel = document.getElementById("tabLoadAndParse-panel"); let wasLoadAndParseResultAppended = false; document .getElementById("formLoadAndParse") .addEventListener("submit", async (ev) => { ev?.preventDefault(); tabLoadAndParsePanel.classList.add("isLoading"); const loadAndParseURL = document.getElementById("loadAndParseURL"); const url = loadAndParseURL?.value || "/twtxt-demos/demo-hipster-twtxt.txt"; const parsedFile = await loadAndParseTwtxtFile(url); console.log(parsedFile); tabLoadAndParsePanel.classList.remove("isLoading"); if (wasLoadAndParseResultAppended) { document.getElementById("preLoadAndParseResult").outerHTML = `
${JSON.stringify(
					parsedFile,
					null,
					2,
				).replace(
					// to color properties
					/"\w+":/g,
					(val) => `${val}`,
				)}
`; return; } const resultsHTML = `
Results
${JSON.stringify(
						parsedFile,
						null,
						2,
					).replace(
						// to color properties
						/"\w+":/g,
						(val) => `${val}`,
					)}
`; tabLoadAndParsePanel.insertAdjacentHTML("beforeend", resultsHTML); document .querySelector("#tabLoadAndParse-panel .js-sourceDetails") ?.removeAttribute("open"); document.body.classList.add("isLoaded"); wasLoadAndParseResultAppended = true; }); const loadAndParseClickHandler = (ev) => { ev?.preventDefault(); loadAndParseURL.value = ev.target.dataset.url; }; [ "loadAndParseHipsterButton", "loadAndParsePirateButton", "loadAndParseSaganButton", ].forEach((curr) => { document .getElementById(curr) .addEventListener("click", loadAndParseClickHandler); });