dumb/static/script.js

73 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

const description = document.querySelector("#description > #full");
const summary = document.querySelector("#description > #summary");
2024-06-09 21:29:17 +01:00
function showDescription() {
summary.classList.toggle("hidden");
description.classList.toggle("hidden");
}
description &&
[description, summary].forEach(
(item) => (item.onclick = showDescription)
);
2024-04-06 00:14:51 -06:00
window.addEventListener("load", () => {
document.querySelectorAll("#lyrics a").forEach((item) => {
item.addEventListener("click", getAnnotation);
});
2024-04-06 00:14:51 -06:00
const linkedAnnotationId = window.location.pathname.match(
new RegExp("/(\\d+)")
)?.[1];
2024-04-06 00:14:51 -06:00
if (linkedAnnotationId) {
const target = document.querySelector(
`a[href^="/${linkedAnnotationId}"][class^="ReferentFragmentdesktop__ClickTarget"] > span`
);
target?.click();
target?.scrollIntoView();
2024-04-06 00:14:51 -06:00
}
});
2022-06-30 21:32:56 +01:00
function getAnnotation(e) {
e.preventDefault();
2024-03-04 20:43:46 +01:00
//document.querySelector('.annotation')?.remove()
const unreviewedAnnotation =
'<p id="unreviewed-annotation">This annotation is unreviewed</p>';
const link = e.currentTarget;
const uri = link.getAttribute("href");
const presentAnnotation =
link.nextElementSibling.matches(".annotation") &&
link.nextElementSibling;
2023-09-13 18:32:35 +02:00
if (presentAnnotation) {
presentAnnotation.remove();
return;
2023-09-13 18:32:35 +02:00
}
xhr = new XMLHttpRequest();
xhr.open("GET", uri + "/annotations");
xhr.send();
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
const parsedReponse = JSON.parse(this.responseText);
const annotationDiv = document.createElement("div");
annotationDiv.innerHTML = parsedReponse.body.html;
annotationDiv.id = uri;
annotationDiv.className = "annotation";
if (parsedReponse.state !== "accepted") {
annotationDiv.insertAdjacentHTML(
"afterbegin",
unreviewedAnnotation
);
}
if (!link.nextElementSibling.matches(".annotation")) {
link.insertAdjacentElement(
"afterend",
annotationDiv
);
}
}
};
2022-06-30 21:32:56 +01:00
}