assets/js/wordfinder-home.js in word-games-theme-3.1.5 vs assets/js/wordfinder-home.js in word-games-theme-3.1.6

- old
+ new

@@ -348,33 +348,35 @@ // getWords define const worker = new Worker('/assets/js/wordfinder-worker.js'); const getData = async (serachValue) => { try { let selectedDictionary = document.querySelector(".select_dropDown2").value; - if (letterLen) { home_page_search_result = document.querySelector("#home_page_search_result") homePageSearchResult = `/?search=${serachValue}&dictionary=Dictionary&prefix=&contains=&suffix=&exculde=&inculde=&length=`; } document.querySelector(".main-header").style.height = "auto" document.querySelector(".main-header").style.background = "#fff" document.querySelector(".heading-h2").style.display = "none" document.querySelector(".sortingFilters").style.display = "none" - errorMsg.innerHTML = ""; wordCount.innerHTML = ""; + + if (serachValue) { + serachValue = serachValue + startsWith.value + endsWith.value + mustInclude.value + inculdeWith.value + exculdeWith.value + } worker.postMessage({ type: "api", serachValue: serachValue, selectedDictionary: selectedDictionary, endpoint: `/.netlify/functions` }); worker.onmessage = (event) => { main.innerHTML = ""; serachBtn.style.background = 'url(/assets/images/search.svg) no-repeat center center'; - getWords(event.data.data); + getWords(serachValue, event.data.data); } } catch (error) { console.log(error); } }; @@ -403,24 +405,32 @@ } let previousDataIndex = null let previousID = null; let storepreviousIndex = [] let moreData = [] -let data_index = 25; -function getWords(data) { - data_index = 25 +let data_index = 98; +function getWords(serachValue, data) { + data_index = 98 moreData = [] storepreviousIndex = [] main.innerHTML = ""; lengthSelect.innerHTML = "" if (typeof data === "string") { + const params = new URLSearchParams(window.location.search); errorMsg.innerHTML = "no words found"; + + if (!letterLen) { + let serachValue = params.get("search").toLowerCase(); + txtBox.value = serachValue + "?" + logSubmit(new Event('submit')) + } + } else { worker.postMessage({ type: 'filterwords', data: data, - serachValue: txtBox.value.toLowerCase(), + serachValue: serachValue, prefixValue: startsWith.value, containsValue: mustInclude.value, suffixValue: endsWith.value, exculdeValue: exculdeWith.value, includeValue: inculdeWith.value, @@ -481,10 +491,11 @@ if (letterLen) { home_page_search_result.href = homePageSearchResult home_page_search_result.innerHTML = `See words of any length with letters ${serachValue.split("")}` } + main.innerHTML += ` <div class="allGroupWords wordlistContainer" id="alpha_${i}"> <h3 class="wordListHeading lead">${i} Letter Words</h3> <div class="wordList">${result.join("")}</div> <div class="w-100 text-center btn-container"> @@ -502,11 +513,10 @@ showMoreLimit() } } if (newWordsLength === 0) { - console.log(newdata); errorMsg.innerHTML = "No Words Found"; document.querySelector(".sortingFilters").style.display = "none" } else { if (txtBox.value) { wordCount.innerHTML = `<strong>Found ${newWordsLength} words with letters with ${txtBox.value.split("")}</strong>`; @@ -550,35 +560,40 @@ try { let showmore = e.parentElement.children[0]; let id = showmore.id; if (previousID !== null && parseInt(previousID) !== parseInt(id)) { - data_index = 25 + data_index = 98 const filteredIndexes = storepreviousIndex.filter(item => item.id === id); if (filteredIndexes.length > 0) { const lastItem = filteredIndexes[filteredIndexes.length - 1]; - data_index = lastItem.data_index + 25; + data_index = lastItem.data_index + 98; lastItem.data_index = data_index; } } previousID = id; storepreviousIndex.push({ data_index, id }) console.log("Current data_index:", data_index); - document.getElementById(id).innerHTML = `Loading...`; let content_area = document.getElementById("alpha_" + id).getElementsByClassName("wordList")[0]; const result = await getMoreWords(); let full_words = result.filter((item) => item.length === Number(id)); if (data_index < full_words.length) { - for (let d = data_index; d < data_index + 25; d++) { + for (let d = data_index; d < data_index + 98; d++) { if (full_words[d] != undefined) { let itemHtml = ""; + let points + let ScrabbleLetterScore = ScrabbleScore(); + if (serachValue) { + serachValue = serachValue + startsWith.value + endsWith.value + mustInclude.value + inculdeWith.value + exculdeWith.value + } + if (serachValue) { var text1 = serachValue.replace("?", ""); var text2 = full_words[d]; var text3 = full_words[d]; let chars = text1.split(""); let indexs = []; @@ -589,28 +604,37 @@ text3[findIndexes] = "$"; text3 = text3.join(""); indexs = [...indexs, ...findIndexes]; } }); + let n1 = false text2.split("").map((itemValue, index) => { let check = indexs.find((i) => i === index); if (check !== undefined) { itemHtml += `${itemValue}`; + n1 = true } else { itemHtml += `<span class='highlight'>${itemValue}</span>`; } }); + if (n1 == true) { + let parsedText = itemHtml.replace(/<span[^>]*>.*?<\/span>/g, ''); + // console.log(parsedText); + points = 0 + for (let i = 0; i < parsedText.length; i++) { + points += ScrabbleLetterScore[parsedText[i]] || 0; // for unknown characters + } + } } else { itemHtml = full_words[d] + points = 0; + for (let i = 0; i < full_words[d].length; i++) { + points += ScrabbleLetterScore[full_words[d][i]] || 0; // for unknown characters + } } - let ScrabbleLetterScore = ScrabbleScore(); - let points = 0; - full_words[d] = full_words[d].toLowerCase(); - for (let i = 0; i < full_words[d].length; i++) { - points += ScrabbleLetterScore[full_words[d][i]] || 0; // for unknown characters - } + full_words[d] = full_words[d].toLowerCase(); let span = document.createElement("span"); span.setAttribute("class", "points"); span.setAttribute("value", `${points}`); span.innerHTML = `${points}`; @@ -623,11 +647,11 @@ a.appendChild(span) content_area.appendChild(a); } } document.getElementById(id).innerHTML = `More Words`; - data_index += 25; + data_index += 98; } else { document.getElementById(id).style.display = "none"; } } catch (error) { console.error("Error fetching or processing data:", error); @@ -701,10 +725,10 @@ let tableFooter = document.querySelectorAll(".btn-container") let showmore = document.querySelectorAll(".showmore_btn"); for (let i = 0; i < showmore.length; i++) { let data_of_button = document.getElementById("alpha_" + showmore[i].getAttribute("id")); let final_data = data_of_button.getElementsByClassName("anchor__style"); - if (final_data.length < 25) { + if (final_data.length < 98) { tableFooter[i].style.display = "none"; } } } window.onscroll = function () { \ No newline at end of file