init form functionality
This commit is contained in:
parent
20353b8f4b
commit
279bc8528b
1 changed files with 48 additions and 29 deletions
|
|
@ -1,59 +1,78 @@
|
||||||
let currentDisplayMode = "dark";
|
let currentDisplayMode = 'dark';
|
||||||
|
|
||||||
const updateDisplayModeIcons = () => {
|
const updateDisplayModeIcons = () => {
|
||||||
document.querySelectorAll(".display-mode-icon").forEach((el) => {
|
document.querySelectorAll('.display-mode-icon').forEach((el) => {
|
||||||
if (currentDisplayMode == "dark") {
|
if (currentDisplayMode == 'dark') {
|
||||||
el.innerHTML = `<i class="fas fa-moon"></i>`;
|
el.innerHTML = `<i class='fas fa-moon'></i>`;
|
||||||
} else if (currentDisplayMode == "moonlight") {
|
} else if (currentDisplayMode == 'moonlight') {
|
||||||
el.innerHTML = `<i class="fas fa-sun"></i>`;
|
el.innerHTML = `<i class='fas fa-sun'></i>`;
|
||||||
} else {
|
} else {
|
||||||
el.innerHTML = `<i class="fas fa-adjust"></i>`;
|
el.innerHTML = `<i class='fas fa-adjust'></i>`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleDisplayMode = () => {
|
const toggleDisplayMode = () => {
|
||||||
if (currentDisplayMode == "dark") {
|
if (currentDisplayMode == 'dark') {
|
||||||
window.localStorage.setItem("displayMode", "moonlight");
|
window.localStorage.setItem('displayMode', 'moonlight');
|
||||||
currentDisplayMode = "moonlight";
|
currentDisplayMode = 'moonlight';
|
||||||
document.getElementById("themekit-css").href = "./Libraries/sass/themekit/main-moonlight.css";
|
document.getElementById('themekit-css').href = '/JuiceUI/Libraries/sass/themekit/main-moonlight.css';
|
||||||
} else if (currentDisplayMode == "moonlight") {
|
} else if (currentDisplayMode == 'moonlight') {
|
||||||
window.localStorage.setItem("displayMode", "light");
|
window.localStorage.setItem('displayMode', 'light');
|
||||||
currentDisplayMode = "light";
|
currentDisplayMode = 'light';
|
||||||
document.getElementById("themekit-css").href = "./Libraries/sass/themekit/main-light.css";
|
document.getElementById('themekit-css').href = '/JuiceUI/Libraries/sass/themekit/main-light.css';
|
||||||
} else {
|
} else {
|
||||||
window.localStorage.setItem("displayMode", "dark");
|
window.localStorage.setItem('displayMode', 'dark');
|
||||||
currentDisplayMode = "dark";
|
currentDisplayMode = 'dark';
|
||||||
document.getElementById("themekit-css").href = "./Libraries/sass/themekit/main-dark.css";
|
document.getElementById('themekit-css').href = '/JuiceUI/Libraries/sass/themekit/main-dark.css';
|
||||||
}
|
}
|
||||||
updateDisplayModeIcons();
|
updateDisplayModeIcons();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", (evt) => {
|
const initForm = () => {
|
||||||
if (window.localStorage.getItem("displayMode") == null) {
|
const form = document.forms[0];
|
||||||
|
const urlIn = document.getElementById('url');
|
||||||
|
form.addEventListener('submit', async (evt) => {
|
||||||
|
evt.preventDefault();
|
||||||
|
try {
|
||||||
|
const resp = await fetch(`/add?url=${urlIn.value}`, {
|
||||||
|
method: 'POST',
|
||||||
|
})
|
||||||
|
const json = await resp.json();
|
||||||
|
urlIn.value =`${location.origin}/${json.shortid}`
|
||||||
|
} catch (ex) {
|
||||||
|
alert(`There was an error processing your request: ${ex}`)
|
||||||
|
console.error(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('DOMContentLoaded', (evt) => {
|
||||||
|
if (window.localStorage.getItem('displayMode') == null) {
|
||||||
// Match with system dark mode
|
// Match with system dark mode
|
||||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
window.localStorage.setItem("displayMode", "dark");
|
window.localStorage.setItem('displayMode', 'dark');
|
||||||
}
|
}
|
||||||
// Match with system light mode
|
// Match with system light mode
|
||||||
else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
||||||
window.localStorage.setItem("displayMode", "light");
|
window.localStorage.setItem('displayMode', 'light');
|
||||||
}
|
}
|
||||||
// Literally choose the middle option
|
// Literally choose the middle option
|
||||||
else {
|
else {
|
||||||
window.localStorage.setItem("displayMode", "moonlight");
|
window.localStorage.setItem('displayMode', 'moonlight');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentDisplayMode = window.localStorage.getItem("displayMode");
|
currentDisplayMode = window.localStorage.getItem('displayMode');
|
||||||
|
|
||||||
if (currentDisplayMode == "dark") {
|
if (currentDisplayMode == 'dark') {
|
||||||
document.getElementById("themekit-css").href = "./Libraries/sass/themekit/main-dark.css";
|
document.getElementById('themekit-css').href = '/JuiceUI/Libraries/sass/themekit/main-dark.css';
|
||||||
} else if (currentDisplayMode == "moonlight") {
|
} else if (currentDisplayMode == 'moonlight') {
|
||||||
document.getElementById("themekit-css").href = "./Libraries/sass/themekit/main-moonlight.css";
|
document.getElementById('themekit-css').href = '/JuiceUI/Libraries/sass/themekit/main-moonlight.css';
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("themekit-css").href = "./Libraries/sass/themekit/main-light.css";
|
document.getElementById('themekit-css').href = '/JuiceUI/Libraries/sass/themekit/main-light.css';
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDisplayModeIcons();
|
updateDisplayModeIcons();
|
||||||
|
initForm();
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue