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 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') gtag('event', 'page_view', { page_location: window.location.pathname + location.search, }) } 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 wordleSolver = async (value, value2, value3, greenWithIndex) => { try { let result = '' document.querySelector('#updateTxt').innerHTML = '' spinner.classList.add('spinner-border') wordleWordCount.innerHTML = 'Searching for best possible letters...' let response = await fetch('/.netlify/functions/wordleSolver', { method: 'POST', body: JSON.stringify({ greenLetters: value, yellowLetters: value2, greyLetters: value3, greenWithIndex: greenWithIndex, }), }) let data = await response.json() data = data.slice(0, 1000) document.querySelector('#updateTxt').innerHTML = 'Solve' spinner.classList.remove('spinner-border') let ok = true if (data.length === 0) { newWordsLength = '' wordleSolverData.innerHTML = '' wordleSolvererrorMsg.classList.add('alert-danger') wordleSolvererrorMsg.innerHTML = 'Sorry!! No words found' wordleWordCount.style.display = 'none' // console.log(wordleWordCount) } else { wordleWordCount.style.display = 'block' wordleSolverData.innerHTML = '' wordleSolvererrorMsg.classList.remove('alert-danger') wordleSolvererrorMsg.innerHTML = '' newWordsLength = '' newWordsLength += data.length result = data.map((item) => { if (item.length === 1) { ok = false newWordsLength = newWordsLength - 1 } else { // console.log(newWordsLength); let ScrabbleLetterScore = ScrabbleScore() sum = 0 item = item.toLowerCase() for (let i = 0; i < item.length; i++) { sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters } return `
  • ${item.toLowerCase()} ${sum}
  • ` } }) if (ok) { wordleSolverData.innerHTML += `

    Solve wordle with these words

    ` } } if (newWordsLength === 0) { console.log(true) wordleSolvererrorMsg.classList.add('alert-danger') wordleSolvererrorMsg.innerHTML = 'Sorry!! No words found' } else { wordleWordCount.innerHTML = `Found ${newWordsLength} matching words for wordle` } } catch (error) { console.log(error) } } const getLetters = (object) => { let letters = [] if (typeof object === 'string') { object = document.querySelectorAll(object) } for (let item of object) { if (item.value.trim().length === 1) { letters.push(item.value.toLowerCase()) } } return letters } const getIndexs = (object) => { let index = [] if (typeof object === 'string') { object = document.querySelectorAll(object) } for (let item of object) { if (item.value.trim().length === 1) { index.push({ value: item.value.toLowerCase(), index: item.dataset.id, }) } } return index } document.querySelector(".refineSerach").addEventListener("click", () => { const scrollingElement = (document.scrollingElement || document.body); scrollingElement.scroll({ top: 0, behavior: 'smooth' }); }) const ScrabbleScore = () => { let twl06_sowpods = { a: 1, e: 1, i: 1, o: 1, u: 1, l: 1, n: 1, r: 1, s: 1, t: 1, d: 2, g: 2, b: 3, c: 3, m: 3, p: 3, f: 4, h: 4, v: 4, w: 4, y: 4, k: 5, j: 8, x: 8, q: 10, z: 10, } return twl06_sowpods }