let getScript = document.currentScript let fileName = getScript.dataset.filename let permalink = getScript.dataset.permalink let form = document.querySelector('[name=verify') let greenLetters = document.querySelectorAll('.greenLetters') let yellowLetters = document.querySelectorAll('.yellowLetters') let greyLetters = document.querySelectorAll('.greyLetters') greenLetters[0].focus() for (let g = 0; g < greenLetters.length; g++) { const elem = greenLetters[g] elem.addEventListener('input', (e) => { e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, "") if (e.target.value) { e.target.classList.add('ws-fcs') } else { e.target.classList.remove('ws-fcs') } }) } for (let y = 0; y < yellowLetters.length; y++) { const elem = yellowLetters[y] elem.addEventListener('input', (e) => { e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, "") if (e.target.value) { e.target.classList.add('ws-fcs2') } else { e.target.classList.remove('ws-fcs2') } }) } for (let e = 0; e < greyLetters.length; e++) { const elem = greyLetters[e] elem.addEventListener('input', (e) => { e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, "") if (e.target.value) { e.target.classList.add('ws-fcs3') } else { e.target.classList.remove('ws-fcs3') } }) } let wordleSolverData = document.getElementById('wordleSolverData') greenLetters[0].focus() let wordleWordCount = document.querySelector('#wordleWordCount') let wordleSolvererrorMsg = document.querySelector('#wordleSolvererrorMsg') let wordlesolver_submit = document.getElementById('wordlesolver_submit') let newWordsLength = 0 let errMessage = document.querySelector('.errMessage') let wrapper_div = document.querySelector('.wrapper_div') const params = new URLSearchParams(window.location.search) let spinner = document.querySelector('.spinner') let featureContainer = document.querySelector("#featureContainer") let howContainer = document.querySelector("#howContainer") let faqsContainer = document.querySelector("#faqsContainer") let infographicsContainer = document.querySelector("#infographicsContainer") let authorsLists = document.querySelector(".authors-list") function sendPageViewEvent() { gtag('event', 'page_view', { page_location: window.location.pathname + location.search }); } function handleSubmit(e) { e.preventDefault() if (featureContainer) { featureContainer.remove() } if (howContainer) { howContainer.remove() } if (faqsContainer) { faqsContainer.remove() } if (infographicsContainer) { infographicsContainer.remove() } if (authorsLists) { authorsLists.remove() } document.querySelector(".refineSerach").style.display = "block" const scrollingElement = (document.scrollingElement || document.body); scrollingElement.scroll({ top: 515, behavior: 'smooth' }); let greenWithIndex = getIndexs('.greenWithIndex') let corretLettterArray = [] let getGreenLetters = [] Array.from(greenLetters).map((item) => { if (!item.value) { corretLettterArray.push(item.value.replace("", "_").toLowerCase()) } else { getGreenLetters.push(item.value.toLowerCase()) corretLettterArray.push(item.value.toLowerCase()) } }) let includesLettersArray = [] let getYellowLetters = [] Array.from(yellowLetters).map((item) => { if (!item.value) { includesLettersArray.push(item.value.replace("", "_").toLowerCase()) } else { getYellowLetters.push(item.value.toLowerCase()) includesLettersArray.push(item.value.toLowerCase()) } }) let excludesLettersArray = [] let getGreyLetters = [] Array.from(greyLetters).map((item) => { if (!item.value) { excludesLettersArray.push(item.value.replace("", "_").toLowerCase()) } else { getGreyLetters.push(item.value.toLowerCase()) excludesLettersArray.push(item.value.toLowerCase()) } }) if (history.pushState) { var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + "correct" + "=" + corretLettterArray.join("") + '&includes' + '=' + includesLettersArray.join("") + "&excludes" + '=' + excludesLettersArray.join("") window.history.pushState({ path: newurl }, '', newurl); const params = new URLSearchParams(window.location.search) let correct = params.get('correct') let includes = params.get('includes') let excludes = params.get('excludes') setTimeout(sendPageViewEvent, 0); } wordleSolver(getGreenLetters, getYellowLetters, getGreyLetters, greenWithIndex) } if (params.size > 0) { window.onload = function (e) { handleSubmit(e); } let correct = params.get('correct').toLowerCase() let includes = params.get('includes').toLowerCase() let excludes = params.get('excludes').toLowerCase() for (let g = 0; g < greenLetters.length; g++) { const elem = greenLetters[g] let values = correct.split("") values.map((item, index) => { if (Number(elem.dataset.id) === index) { elem.value = item.replace("_", "") if (elem.value != "") { elem.classList.add('ws-fcs') } } }) elem.addEventListener('input', (e) => { e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, "") if (e.target.value) { e.target.classList.add('ws-fcs') } else { e.target.classList.remove('ws-fcs') } }) } for (let y = 0; y < yellowLetters.length; y++) { const elem = yellowLetters[y] let values = includes.split("") values.map((item, index) => { if (Number(elem.dataset.id) === index) { elem.value = item.replace("_", "") if (elem.value != "") { elem.classList.add('ws-fcs2') } } }) elem.addEventListener('input', (e) => { e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, "") if (e.target.value) { e.target.classList.add('ws-fcs2') } else { e.target.classList.remove('ws-fcs2') } }) } for (let e = 0; e < greyLetters.length; e++) { const elem = greyLetters[e] let values = excludes.split("") values.map((item, index) => { if (Number(elem.dataset.id) === index) { elem.value = item.replace("_", "") if (elem.value != "") { elem.classList.add('ws-fcs3') } } }) elem.addEventListener('input', (e) => { e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, "") if (e.target.value) { e.target.classList.add('ws-fcs3') } else { e.target.classList.remove('ws-fcs3') } }) } } form.addEventListener('submit', handleSubmit) const worker = new Worker('/assets/js/wordleSolver-worker.js'); const wordleSolver = async (value, value2, value3, greenWithIndex) => { try { document.querySelector('#updateTxt').innerHTML = '' spinner.classList.add('spinner-border') wordleWordCount.innerHTML = 'Searching for best possible letters...' worker.postMessage({ type: "api", endpoint: `/.netlify/functions/wordleSolver/wordleSolver`, greenLetters: value, yellowLetters: value2, greyLetters: value3, greenWithIndex: greenWithIndex, }); worker.onmessage = (event) => { document.querySelector('#updateTxt').innerHTML = 'Solve' spinner.classList.remove('spinner-border') if (event.data == "error") { newWordsLength = '' wordleSolverData.innerHTML = '' wordleSolvererrorMsg.classList.add('alert-danger') wordleSolvererrorMsg.innerHTML = 'Sorry!! No words found' wordleWordCount.style.display = 'none' } else { wordleWordCount.style.display = 'block' wordleSolverData.innerHTML = '' wordleSolvererrorMsg.classList.remove('alert-danger') wordleSolvererrorMsg.innerHTML = '' if (event.data.ok) { wordleSolverData.innerHTML += `