2024-06-09 21:29:17 +01:00
|
|
|
const description = document.querySelector("#description > #full")
|
|
|
|
const summary = document.querySelector("#description > #summary")
|
2022-10-08 22:46:48 +01:00
|
|
|
|
2024-06-09 21:29:17 +01:00
|
|
|
function showDescription() {
|
2022-10-08 22:46:48 +01:00
|
|
|
summary.classList.toggle("hidden")
|
2024-06-09 21:29:17 +01:00
|
|
|
description.classList.toggle("hidden")
|
2022-10-08 22:46:48 +01:00
|
|
|
}
|
|
|
|
|
2024-06-09 21:29:17 +01:00
|
|
|
description && [description, summary].forEach(item => item.onclick = showDescription)
|
2022-10-08 22:46:48 +01:00
|
|
|
|
2024-04-06 00:14:51 -06:00
|
|
|
window.addEventListener("load", () => {
|
2024-04-16 01:26:28 +01:00
|
|
|
const geniusURL = "https://genius.com" + document.location.pathname + document.location.search
|
|
|
|
document.getElementById("goto-genius").setAttribute("href", geniusURL)
|
2024-04-06 00:14:51 -06:00
|
|
|
document.querySelectorAll("#lyrics a").forEach(item => {
|
|
|
|
item.addEventListener("click", getAnnotation)
|
|
|
|
})
|
|
|
|
|
|
|
|
const linkedAnnotationId = window.location.pathname.match(new RegExp("/(\\d+)"))?.[1]
|
|
|
|
if (linkedAnnotationId) {
|
|
|
|
const target = document.querySelector(`a[href^="/${linkedAnnotationId}"][class^="ReferentFragmentdesktop__ClickTarget"] > span`)
|
|
|
|
target?.click()
|
|
|
|
target?.scrollIntoView()
|
|
|
|
}
|
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()
|
2024-04-10 13:30:45 -06:00
|
|
|
const link = e.target.parentElement
|
|
|
|
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-09 15:19:11 +02:00
|
|
|
|
|
|
|
xhr = new XMLHttpRequest()
|
|
|
|
xhr.open("GET", uri + "/annotations")
|
|
|
|
xhr.send()
|
|
|
|
xhr.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && this.status == 200) {
|
2023-09-09 18:11:00 +02:00
|
|
|
const parsedReponse = JSON.parse(this.responseText)
|
2023-09-13 18:32:35 +02:00
|
|
|
const annotationDiv = document.createElement('div');
|
|
|
|
annotationDiv.innerHTML = parsedReponse.html
|
|
|
|
annotationDiv.id = uri
|
|
|
|
annotationDiv.className = "annotation"
|
2024-04-10 13:30:45 -06:00
|
|
|
if (!link.nextElementSibling.matches(".annotation")) {
|
|
|
|
link.insertAdjacentElement('afterend', annotationDiv)
|
2024-04-06 14:17:42 -06:00
|
|
|
}
|
2023-09-09 15:19:11 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-30 21:32:56 +01:00
|
|
|
}
|
2024-03-09 21:40:20 +01:00
|
|
|
|
|
|
|
window._currentTheme = localStorage.getItem("_theme") || "light"
|
|
|
|
setTheme(window._currentTheme)
|
|
|
|
|
|
|
|
const themeChooser = document.getElementById("choose-theme")
|
|
|
|
themeChooser.addEventListener("click", function() {
|
|
|
|
if (window._currentTheme === "dark") {
|
|
|
|
setTheme("light")
|
|
|
|
} else {
|
|
|
|
setTheme("dark")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
function setTheme(theme) {
|
|
|
|
const toggler = document.getElementById("ic_fluent_dark_theme_24_regular")
|
|
|
|
switch (theme) {
|
|
|
|
case "dark":
|
|
|
|
toggler.setAttribute("fill", "#fff")
|
|
|
|
localStorage.setItem("_theme", "dark")
|
|
|
|
document.body.classList.add("dark")
|
|
|
|
window._currentTheme = "dark"
|
|
|
|
return
|
|
|
|
case "light":
|
|
|
|
toggler.setAttribute("fill", "#181d31")
|
|
|
|
localStorage.setItem("_theme", "light")
|
|
|
|
document.body.classList.remove("dark")
|
|
|
|
window._currentTheme = "light"
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|