window.onload=function(){document.getElementById("keyword1").value="",window.conversionMode="charsToWords",adjustBoxHeight("div5"),adjustBoxHeight("div8")},document.getElementById("switchButton").addEventListener("click",(function(){"charsToWords"===window.conversionMode?(window.conversionMode="wordsToChars",document.querySelector(".div1").textContent="Words",document.querySelector(".div3").textContent="Characters"):(window.conversionMode="charsToWords",document.querySelector(".div1").textContent="Characters",document.querySelector(".div3").textContent="Words"),document.getElementById("keyword1").value="",document.getElementById("div5").innerHTML="0",document.getElementById("div8").innerHTML="0",adjustBoxHeight("div5"),adjustBoxHeight("div8")}));let userInput="";function callFunction(){if(userInput=document.getElementById("keyword1").value.trim(),""===userInput)document.getElementById("div5").innerHTML="0",document.getElementById("div8").innerHTML="0";else if(isNaN(userInput))document.getElementById("div5").innerHTML="Invalid number".fontcolor("red"),document.getElementById("div8").innerHTML="Invalid number".fontcolor("red");else if("charsToWords"===window.conversionMode){let e=calculateWordsFromCharacters(userInput);document.getElementById("div5").innerHTML=formatRange(e.low,e.high);let t=getPageCountRange(e.low),n=getPageCountRange(e.high);document.getElementById("div8").innerHTML=formatRangeForPages(t,n)}else{let e=calculateCharactersFromWords(userInput);document.getElementById("div5").innerHTML=formatRange(Math.ceil(e.low),Math.ceil(e.high));let t=getPageCountRange(parseInt(userInput));document.getElementById("div8").innerHTML=formatPageCount(t.toFixed(1))}adjustBoxHeight("div5"),adjustBoxHeight("div8")}function adjustBoxHeight(e){const t=document.getElementById(e);t&&(t.style.height="auto",t.style.height=`${t.scrollHeight+5}px`)}function calculateWordsFromCharacters(e){let t=Math.round(e/5);return{low:Math.round(e/6.5),high:t}}function getPageCountRange(e){return e/250}function calculateCharactersFromWords(e){return{low:5*e,high:6.5*e}}function formatRange(e,t){return e===t?e.toString():`${e} - ${t}`}function formatRangeForPages(e,t){return`${formatPageCount(e)} - ${formatPageCount(t)}`}function formatPageCount(e){const t=parseFloat(e);return t%1==0?t.toFixed(0):t.toFixed(1)}const selectElement=e=>{const t=document.querySelector(e);if(t)return t;throw new Error(`Something went wrong! Make sure that ${e} exists/is typed correctly.`)},scrollHeader=()=>{const e=selectElement("#header");this.scrollY>=15?e.classList.add("activated"):e.classList.remove("activated")};window.addEventListener("scroll",scrollHeader);const menuToggleIcon=selectElement("#menu-toggle-icon"),formOpenBtn=selectElement("#search-icon"),formCloseBtn=selectElement("#form-close-btn"),searchContainer=selectElement("#search-form-container"),toggleMenu=()=>{selectElement("#menu").classList.toggle("activated"),menuToggleIcon.classList.toggle("activated")};menuToggleIcon.addEventListener("click",toggleMenu),formOpenBtn.addEventListener("click",(()=>searchContainer.classList.add("activated"))),formCloseBtn.addEventListener("click",(()=>searchContainer.classList.remove("activated"))),window.addEventListener("keyup",(e=>{"Escape"===e.key&&searchContainer.classList.remove("activated")}));const body=document.body,themeToggleBtn=selectElement("#theme-toggle-btn"),currentTheme=localStorage.getItem("currentTheme");currentTheme&&body.classList.add("light-theme"),themeToggleBtn.addEventListener("click",(function(){body.classList.toggle("light-theme"),body.classList.contains("light-theme")?localStorage.setItem("currentTheme","themeActive"):localStorage.removeItem("currentTheme")}));