init
This commit is contained in:
parent
ee97eae16a
commit
a88746075a
15 changed files with 582 additions and 0 deletions
48
js/calc.js
Normal file
48
js/calc.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* @author oitsjustjose | https://github.com/oitsjustjose | oitsjustjose.com
|
||||
* Handles all things in regards to the calculator functionality
|
||||
*/
|
||||
|
||||
let display = document.querySelector("input.view");
|
||||
let justEvaled = false;
|
||||
|
||||
const isNumeric = (val) => {
|
||||
return !isNaN(parseInt(val));
|
||||
};
|
||||
|
||||
const evaluate = () => {
|
||||
if (display.value == "err") {
|
||||
return "err";
|
||||
}
|
||||
|
||||
let ret;
|
||||
|
||||
try {
|
||||
ret = eval(display.value);
|
||||
} catch (ex) {
|
||||
ret = "err";
|
||||
}
|
||||
|
||||
justEvaled = true;
|
||||
return ret;
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
document.querySelectorAll(".buttons tr td").forEach((el) => {
|
||||
el.addEventListener("click", () => {
|
||||
if (el.innerText == "AC") {
|
||||
display.value = "";
|
||||
} else if (el.innerText == "=") {
|
||||
display.value = evaluate();
|
||||
} else {
|
||||
if (justEvaled && isNumeric(el.innerText)) {
|
||||
display.value = "";
|
||||
}
|
||||
display.value += el.innerText;
|
||||
justEvaled = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
init();
|
||||
65
js/theme.js
Normal file
65
js/theme.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @author oitsjustjose | https://github.com/oitsjustjose | oitsjustjose.com
|
||||
* Handles all things in regards to theming
|
||||
*/
|
||||
|
||||
let mode = "dark";
|
||||
|
||||
const css = document.getElementById("themekit");
|
||||
const icon = document.querySelector(".theme-toggle");
|
||||
|
||||
const updateIcon = () => {
|
||||
if (mode == "dark") {
|
||||
icon.innerHTML = `<i class="fas fa-moon"></i>`;
|
||||
} else if (mode == "moonlight") {
|
||||
icon.innerHTML = `<i class="fas fa-sun"></i>`;
|
||||
} else {
|
||||
icon.innerHTML = `<i class="fas fa-adjust"></i>`;
|
||||
}
|
||||
};
|
||||
|
||||
const toggle = () => {
|
||||
if (mode == "dark") {
|
||||
window.localStorage.setItem("theme", "moonlight");
|
||||
mode = "moonlight";
|
||||
css.href = "/css/themes/moonlight.css";
|
||||
} else if (mode == "moonlight") {
|
||||
window.localStorage.setItem("theme", "light");
|
||||
mode = "light";
|
||||
css.href = "/css/themes/light.css";
|
||||
} else {
|
||||
window.localStorage.setItem("theme", "dark");
|
||||
mode = "dark";
|
||||
css.href = "/css/themes/dark.css";
|
||||
}
|
||||
updateIcon();
|
||||
};
|
||||
|
||||
window.addEventListener("DOMContentLoaded", (evt) => {
|
||||
if (window.localStorage.getItem("theme") === null) {
|
||||
// Match with system dark mode
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
window.localStorage.setItem("theme", "dark");
|
||||
}
|
||||
// Match with system light mode
|
||||
else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
||||
window.localStorage.setItem("theme", "light");
|
||||
}
|
||||
// Literally choose the middle option
|
||||
else {
|
||||
window.localStorage.setItem("theme", "moonlight");
|
||||
}
|
||||
}
|
||||
|
||||
mode = window.localStorage.getItem("theme");
|
||||
|
||||
if (mode == "dark") {
|
||||
css.href = "/css/themes/dark.css";
|
||||
} else if (mode == "moonlight") {
|
||||
css.href = "/css/themes/moonlight.css";
|
||||
} else {
|
||||
css.href = "/css/themes/light.css";
|
||||
}
|
||||
|
||||
updateIcon();
|
||||
});
|
||||
Loading…
Reference in a new issue