Fetch and display weather data.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB
Raw

document.addEventListener("DOMContentLoaded",()=>{
let currentUrlObj=document.getElementsByClassName('currentUrl');
for (let i=0; i<currentUrlObj.length; i++){
currentUrlObj[i].innerHTML=window.location.origin;
}
let helpLinkObj=document.getElementsByClassName('helpLink');
for (let i=0; i<helpLinkObj.length; i++){
helpLinkObj[i].setAttribute("href",helpLinkObj[i].getAttribute("href").replace("[currentUrl]",window.location.origin));
}
let nightModeInputObj=document.getElementById("nightModeInput");
nightModeInputObj.addEventListener("change",(e)=>{
toggleDayNightMode(e.target.checked);
});
if(nightModeInputObj.checked){
toggleDayNightMode(nightModeInputObj.checked);
}else{
toggleDayNightIcon(nightModeInputObj.checked);
}
let helpObj=document.getElementById("help");
let helpImageObj=document.getElementById("helpImage");
if(helpImageObj){//Used because #helpImage can be hidden by user request.
document.getElementById("helpImage").addEventListener("click", ()=>{
if(window.getComputedStyle(helpObj).getPropertyValue("display")=="none"){
helpObj.style.display="block";
}else{
helpObj.style.display="none";
}
});
}
});
function toggleDayNightMode(nightMode){
document.body.classList.toggle("nightBackground");
let weatherImageArray=document.querySelectorAll(".weatherImage,#dayMode,#helpImage");
for (let i=0; i<weatherImageArray.length; i++){
weatherImageArray[i].classList.toggle("nightFilter");
}
let tableCellArray=document.querySelectorAll("td,th:not(:first-child)");
for (let i=0; i<tableCellArray.length; i++){
tableCellArray[i].classList.toggle("nightBorder");
}
let allArray=document.querySelectorAll("*");
for (let i=0; i<allArray.length; i++){
allArray[i].classList.toggle("nightColor");
}
let alternativeColumnArray=document.querySelectorAll("td:nth-child(2n+1):not(:first-child)");
for (let i=0; i<alternativeColumnArray.length; i++){
alternativeColumnArray[i].classList.toggle("nightAlternateBackground");
}
toggleDayNightIcon(nightMode);
}
function toggleDayNightIcon(nightMode){
if(nightMode){
document.getElementById("dayMode").style.display="block";
document.getElementById("nightMode").style.display="none";
}else{
document.getElementById("dayMode").style.display="none";
document.getElementById("nightMode").style.display="block";
}
}