add LibreJS licenses to all demo JS split browser build from node build add copyright info to license files update to use yarn v4.13.0 update to v0.9.2
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt
|
|
|
|
import { hashTwt } from "/dist-browser/twtxt-lib.js";
|
|
|
|
let wasHashTwtResultAppended = false;
|
|
|
|
const formHash = document.forms["formHash"];
|
|
formHash.addEventListener("submit", (e) => {
|
|
e.preventDefault();
|
|
const content = formHash.elements["content"].value;
|
|
const created = formHash.elements["created"].value;
|
|
const url = formHash.elements["url"].value;
|
|
const hash = hashTwt({
|
|
content,
|
|
created,
|
|
url,
|
|
});
|
|
|
|
const result = [
|
|
`content: ${content}`,
|
|
`created: ${created}`,
|
|
`url: ${url}`,
|
|
`hash: ${hash}`,
|
|
].join("\n");
|
|
|
|
console.log((wasHashTwtResultAppended ? "\n" : "") + result);
|
|
|
|
const resultHTML = result
|
|
.split("\n")
|
|
.map((line) =>
|
|
line.replace(
|
|
// to color properties
|
|
/^\w+:/,
|
|
(val) => `<span class="code-str">${val}</span>`,
|
|
),
|
|
)
|
|
.join("\n");
|
|
|
|
if (wasHashTwtResultAppended) {
|
|
document
|
|
.getElementById("preHashTwtResult")
|
|
.insertAdjacentHTML("afterbegin", resultHTML + "<br />\n");
|
|
return;
|
|
}
|
|
|
|
const resultsHTML = `
|
|
<details open="">
|
|
<summary>Results</summary>
|
|
<figure>
|
|
<pre id="preHashTwtResult">${resultHTML}</pre>
|
|
</figure>
|
|
</details>
|
|
`.trim();
|
|
|
|
document
|
|
.getElementById("tabHashTwt-panel")
|
|
.insertAdjacentHTML("beforeend", resultsHTML);
|
|
|
|
document
|
|
.querySelector("#tabHashTwt-panel .js-sourceDetails")
|
|
?.removeAttribute("open");
|
|
|
|
document.body.classList.add("isLoaded");
|
|
wasHashTwtResultAppended = true;
|
|
});
|
|
|
|
// @license-end
|