console.log('wordle solver ...')
let form = document.querySelector('[name=verify')
let greenLetters = document.querySelectorAll('.greenLetters')
let yellowLetters = document.querySelectorAll('.yellowLetters')
let greyLetters = document.querySelectorAll('.greyLetters')
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 = document.querySelector('.wrapper')
let addMore = document.querySelector('#addMore')
addMore.addEventListener('click', (e) => {
e.preventDefault()
let div = document.createElement('div')
div.classList.add('d-flex')
div.classList.add('mt-2')
for (let i = 20; i <= 24; i++) {
let input = document.createElement('input')
input.type = 'text'
input.setAttribute('maxlength', '1')
input.setAttribute('autocomplete', 'off')
if (i <= 24) {
input.setAttribute('tabIndex', i)
}
let classes = ['wordleSolver-field', 'greyLetters', 'form-control', 'px-5']
input.classList.add(...classes)
input.id = 'greyLetters'
div.append(input)
wrapper.append(div)
}
})
let spinner = document.querySelector('.spinner')
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,
}),
})
const data = await response.json()
document.querySelector('#updateTxt').innerHTML = 'Update'
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 {
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 `