This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/articles/static/scripts.js

33 lines
883 B
JavaScript

function activateDarkMode() {
document.getElementById("code-dark").removeAttribute("disabled");
}
function activateLightMode() {
document.getElementById("code-dark").setAttribute("disabled", "true");
}
function darkModeListener(e) {
if (e.matches) {
activateDarkMode();
} else {
activateLightMode();
}
}
let mql = window.matchMedia("(prefers-color-scheme: dark)");
darkModeListener(mql);
mql.addListener(darkModeListener);
window.onload = function () {
const adminLinkElement = document.querySelector(".article-detail .metadata a.admin-link");
if (adminLinkElement === undefined || adminLinkElement === null) {
return;
}
const adminLocation = adminLinkElement.href;
document.addEventListener("keydown", event => {
if (event.code === "KeyE") {
window.location = adminLocation;
}
})
}