added Dark mode to website and styled it up a little (#778)

* added dark mode

* added css and js files
This commit is contained in:
Dhruv
2024-12-31 00:37:16 +05:30
committed by GitHub
parent 4f51f408a1
commit 01ad54a5b7
7 changed files with 432 additions and 111 deletions

36
js/darkmode.js Normal file
View File

@ -0,0 +1,36 @@
const darkBG = "#141414";
const darkLink = "#ff1c5c";
const darkText = "Dark Mode";
const darkColor = "black";
const lightBG = "white";
const lightLink = "#9e1bd6";
const lightText = "Light Mode";
const lightColor = "white";
darkMode = false;
function lightDark(s) {
let root = document.documentElement;
document.querySelector("img").classList.toggle("invert");
document.querySelector("button").classList.toggle("hover");
document.querySelector("form select").classList.toggle("hover");
document
.querySelectorAll("form input")
.forEach((e) => e.classList.toggle("hover"));
document.querySelector("form input[type='text']").classList.toggle("white");
document.querySelector("form span").classList.toggle("muted-color");
if (!darkMode) {
darkMode = true;
s.innerText = lightText;
root.style.setProperty("--link-color", darkLink);
root.style.setProperty("--bg-color", darkBG);
} else {
darkMode = false;
s.innerText = darkText;
root.style.setProperty("--link-color", lightLink);
root.style.setProperty("--bg-color", lightBG);
}
console.log(darkMode);
}

62
js/index.js Normal file
View File

@ -0,0 +1,62 @@
const COMANCHE055 = "Comanche055";
const LUMINARY099 = "Luminary099";
const COMANCHE055_PAGES = 1751;
const LUMINARY099_PAGES = 1743;
function changeDir() {
showPage();
}
function showFirst() {
changePage(1);
}
function showLast() {
const directory = document.form.directory.value;
if (directory === COMANCHE055) changePage(COMANCHE055_PAGES);
else if (directory === LUMINARY099) changePage(LUMINARY099_PAGES);
}
function showPrevious() {
const newpage = parseInt(document.form.pagenum.value) - 1;
if (newpage >= 1) {
changePage(newpage);
}
}
function showNext() {
const newpage = parseInt(document.form.pagenum.value) + 1;
const directory = document.form.directory.value;
if (
(directory === COMANCHE055 && newpage <= COMANCHE055_PAGES) ||
(directory === LUMINARY099 && newpage <= LUMINARY099_PAGES)
) {
changePage(newpage);
}
}
function changePage(page) {
document.form.pagenum.value = parseInt(page);
showPage();
}
function showPage() {
let page = parseInt(document.form.pagenum.value);
const directory = document.form.directory.value;
if (page < 1) {
document.form.pagenum.value = 1;
page = 1;
} else if (directory === COMANCHE055 && page > COMANCHE055_PAGES) {
document.form.pagenum.value = COMANCHE055_PAGES;
page = COMANCHE055_PAGES;
} else if (directory === LUMINARY099 && page > LUMINARY099_PAGES) {
document.form.pagenum.value = LUMINARY099_PAGES;
page = LUMINARY099_PAGES;
}
const formattedPage = page.toString().padStart(4, "0");
const imageURL = `https://www.ibiblio.org/apollo/ScansForConversion/${directory}/${formattedPage}.jpg`;
document.image.src = imageURL;
document.body.style.cursor = "progress";
}