assets/js/wordgames-result.js in word-games-theme-2.7.9 vs assets/js/wordgames-result.js in word-games-theme-2.8.6

- old
+ new

@@ -3,13 +3,11 @@ ***************/ const getScript = document.currentScript; let form = document.querySelector("#form"); let wordCount = document.querySelector(".wordCount"); let main = document.querySelector(".main"); -// let loader = document.querySelector(".main-loader") let errorMsg = document.querySelector(".errorMsg"); -let script = document.currentScript; // getqueryUrl from form const params = new URLSearchParams(window.location.search); let serachValue = params.get("search").toLowerCase(); let prefixValue = params.get("prefix"); @@ -20,160 +18,25 @@ let lengthValue = params.get("length"); let dictonary = params.get("dictionary"); // advanced filter element grabs let tick; -let startsWith = document.getElementById("startsWith"); -let mustInclude = document.getElementById("mustInclude"); -console.log(mustInclude); -let endsWith = document.getElementById("endsWith"); -let exculdeWith = document.getElementById("exculdeWith"); -let inculdeWith = document.getElementById("inculdeWith"); -let wordLength = document.getElementById("wordLength"); - - let ok = true; let tab_container = document.querySelector(".tab_container"); let lengthSelect = document.querySelector(".length-select"); const siteUrl = getScript.dataset.url; var sortValue; var sortBool = false; - -let letterCloseButton = document.querySelector( - ".letter-close-button-commonPage" -); -if (serachValue) { - letterCloseButton.classList.add("ltr-cls-btn-commonPage"); -} -letterCloseButton.addEventListener("click", () => { - txtBox.value = ""; - letterCloseButton.classList.remove("ltr-cls-btn-commonPage"); -}); - -let txtBox = document.querySelector(".txtBox"); -txtBox.focus(); +let featureContainer = document.querySelector("#featureContainer") +let howContainer = document.querySelector("#howContainer") +let faqsContainer = document.querySelector("#faqsContainer") +let infographicsContainer = document.querySelector("#infographicsContainer") txtBox.value = serachValue; -txtBox.addEventListener("input", (e) => { - if (e.target.value === "") { - letterCloseButton.classList.remove("ltr-cls-btn-commonPage"); - } else { - letterCloseButton.classList.add("ltr-cls-btn-commonPage"); - } - let rangeOfBlankTile = script.dataset.range; - e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, ""); - if (rangeOfBlankTile === "") { - rangeOfBlankTile = 3; - } - e.target.value = e.target.value.replace(/ /g, "?"); - let data = []; - data = e.target.value.split("").filter((i) => i === "?"); - if (data.length > rangeOfBlankTile) { - e.target.value = e.target.value.replace(/\?$/, ""); - } -}); - -function mobileScrollTop(x) { - if (x.matches) { - console.log(x.matches); - txtBox.addEventListener("click", () => { - document.documentElement.scrollTop = 350; - setTimeout(() => { - document.documentElement.scrollTop = 350; - }, 300); - }); - } else { - console.log("false"); - } -} -var x = window.matchMedia("(max-width: 768px)"); -// mobileScrollTop(x); -// x.addListener(mobileScrollTop); - -let rangeOfBlankTile = script.dataset.range; -let quesMark = "?"; - -if (rangeOfBlankTile) { - if (!serachValue.includes("?")) { - serachValue = serachValue + quesMark.repeat(rangeOfBlankTile); // - txtBox.value = serachValue; - } -} - -const filterInputs = document.querySelectorAll('.filter_val'); -Array.from(filterInputs).forEach((item) => { - item.addEventListener("input", (e) => { - const inputValue = e.target.value; - const parentElement = e.target.parentElement; - const imgElement = parentElement.querySelector('img'); - const tooltipElement = parentElement.querySelector('.filter-tooltip'); - - if (inputValue == "") { - imgElement.src = "/assets/images/questionmark.svg" - item.nextElementSibling.setAttribute("data-tip", item.nextElementSibling.id) - tooltipElement.style.setProperty('--tooltip-padding', '0.5rem'); - tooltipElement.style.setProperty('--tooltip-border-style', 'soild'); - - } else { - item.nextElementSibling.removeAttribute("data-tip") - imgElement.src = "/assets/images/close-btn.svg" - tooltipElement.style.setProperty('--tooltip-padding', '0'); - tooltipElement.style.setProperty('--tooltip-border-style', 'none'); - } - item.nextElementSibling.addEventListener("click", () => { - e.target.value = "" - imgElement.src = "/assets/images/questionmark.svg" - item.nextElementSibling.setAttribute("data-tip", item.nextElementSibling.id) - tooltipElement.style.setProperty('--tooltip-padding', '0.5rem'); - tooltipElement.style.setProperty('--tooltip-border-style', 'soild'); - }) - }) -}) - - -function handleFilterInput(e) { - const inputValue = e.target.value; - const parentElement = e.target.parentElement; - const imgElement = parentElement.querySelector('img'); - const tooltipElement = parentElement.querySelector('.filter-tooltip'); - - if (inputValue == "") { - imgElement.src = "/assets/images/questionmark.svg" - e.target.nextElementSibling.setAttribute("data-tip", e.target.nextElementSibling.id) - tooltipElement.style.setProperty('--tooltip-padding', '0.5rem'); - tooltipElement.style.setProperty('--tooltip-border-style', 'solid'); - } else { - e.target.nextElementSibling.removeAttribute("data-tip") - imgElement.src = "/assets/images/close-btn.svg" - tooltipElement.style.setProperty('--tooltip-padding', '0'); - tooltipElement.style.setProperty('--tooltip-border-style', 'none'); - } - - e.target.nextElementSibling.addEventListener("click", () => { - e.target.value = "" - imgElement.src = "/assets/images/questionmark.svg" - e.target.nextElementSibling.setAttribute("data-tip", e.target.nextElementSibling.id) - tooltipElement.style.setProperty('--tooltip-padding', '0.5rem'); - tooltipElement.style.setProperty('--tooltip-border-style', 'solid'); - }); -} - -document.addEventListener("DOMContentLoaded", () => { - const filterInputs = document.querySelectorAll('.filter_val'); - Array.from(filterInputs).forEach((item) => { - // Call the function on load - handleFilterInput({ target: item }); - item.addEventListener("input", handleFilterInput); - }); -}); - - - - let theSelect = document.getElementById("select_dropDown"); - +let sortingFilter = document.querySelector("#select_dropDown"); const sortup = document.querySelector(".sortup-icon"); let bool = false; sortup.addEventListener("click", () => { if (bool) { theSelect.size = 0; @@ -206,27 +69,72 @@ diffRange.push(currentRange); } return diffRange; }; +let authorsLists = document.querySelector(".authors-list") + // getWords define... const getData = async (serachValue) => { try { + document.querySelector(".main-header").style.background = "#fff" + document.querySelector(".heading-h2").style.display = "none" + document.querySelector(".sortingFilters").style.display = "none" + if (featureContainer) { + featureContainer.remove() + } + if (howContainer) { + howContainer.remove() + } + if (faqsContainer) { + faqsContainer.remove() + } + if (infographicsContainer) { + infographicsContainer.remove() + } + if (authorsLists) { + authorsLists.remove() + } errorMsg.innerHTML = ""; wordCount.innerHTML = ""; let selectedDictionary = document.querySelector(".select_dropDown2").value; - main.innerHTML = `<div class="loader"> - <img src='/assets/images/loading.gif'> - <div style="font-weight:900;font-size:14px" >Finding words - Powered by ${siteUrl.replace( - /^https?:\/\//, - "" - )}</div> - </div>`; + main.innerHTML = `<main class="placeholder-loader"> + <ul class="o-vertical-spacing o-vertical-spacing--l"> + <li class="blog-post o-media"> + <div class="o-media__body"> + <div class="o-vertical-spacing"> + <p class="m-0"> + <span class="skeleton-box" style="width:40%;"></span> + </p> + </div> + </div> + </li> + <li class="blog-post o-media"> + <div class="o-media__figure"> + <span class="skeleton-box" style="width:900px;height:140px;"></span> + </div> + </li> + <li class="blog-post o-media"> + <div class="o-media__figure"> + <span class="skeleton-box" style="width:900px;height:140px;"></span> + </div> + </li> + <li class="blog-post o-media"> + <div class="o-media__figure"> + <span class="skeleton-box" style="width:900px;height:140px;"></span> + </div> + </li> + </ul> + </main>`; /// loader - const response = await fetch( - `/.netlify/functions/getWords?name=${serachValue}&selecteddictionary=${selectedDictionary}` - ); + let response + if (serachValue) { + response = await fetch(`/.netlify/functions/getWords?name=${serachValue}&selecteddictionary=${selectedDictionary}`); + } else { + response = await fetch(`/.netlify/functions/getData?&selecteddictionary=${selectedDictionary}`) + } + const data = await response.json(); main.innerHTML = ""; getWords(data); //getWords calling... } catch (error) { @@ -242,15 +150,15 @@ document.querySelector(".fillterWrapper").classList.add("hide") const scrollingElement = document.scrollingElement || document.body; scrollingElement.scroll({ top: 0, behavior: "smooth" }); - if (rangeOfBlankTile) { - if (!txtBox.value.includes("?")) { - txtBox.value = txtBox.value + quesMark.repeat(rangeOfBlankTile); // - } - } + // if (rangeOfBlankTile) { + // if (!txtBox.value.includes("?")) { + // txtBox.value = txtBox.value + quesMark.repeat(rangeOfBlankTile); // + // } + // } let selectedDictionary = document.querySelector(".select_dropDown2").value; event.preventDefault(); if (history.pushState) { var newurl = @@ -307,34 +215,36 @@ }); } getData(txtBox.value.toLowerCase()); // addFilterCount(); } - let selectedDictionary = document.querySelector(".select_dropDown2"); selectedDictionary.addEventListener("change", (e) => { logSubmit(e); }); // applyBtn.addEventListener("submit", logSubmit); form.addEventListener("submit", logSubmit); + sortingFilter.addEventListener("change", logSubmit); } -// getWords function define... +let moreData = [] +let data_index = 25; function getWords(data) { + data_index = 25 + moreData = [] main.innerHTML = ""; - document.querySelector(".sortingFilters").style.display="flex" - // tab_container.innerHTML = ""; lengthSelect.innerHTML = "" + document.querySelector(".sortingFilters").style.display = "flex" if (typeof data === "string") { errorMsg.innerHTML = "no words found"; wordCount.innerHTML = `<strong>Found 0 words with letters ${serachValue.split( "" )}</strong>`; } else { let newWordsLength = 0; let dataArr = []; - for (let i = serachValue.length; i >= 1; i--) { + for (let i = 15; i > 0; i--) { let newdata = data.filter((item) => item.length === i); if (prefixValue) { newdata = newdata.filter((item2) => item2.startsWith(prefixValue.toLowerCase()) ); @@ -422,38 +332,40 @@ } if (newdata.length === 0) { main.innerHTML += ""; } else { newWordsLength += newdata.length; - const result = newdata.map((item) => { - var text1 = serachValue.replace("?", ""); - var text2 = item; - var text3 = item; - let chars = text1.split(""); - - let indexs = []; - chars.map((i) => { - let findIndexes = findIndex(text3, i); - if (findIndexes.length > 0) { - text3 = text3.split(""); - text3[findIndexes] = "$"; - text3 = text3.join(""); - - indexs = [...indexs, ...findIndexes]; - } - }); + newdata = sortWords(newdata); + moreData.push(newdata) + let result = newdata.map((item) => { let itemHtml = ""; - text2.split("").map((itemValue, index) => { - let check = indexs.find((i) => i === index); - - if (check !== undefined) { - itemHtml += `${itemValue}`; - } else { - itemHtml += `<span class='highlight'>${itemValue}</span>`; - } - }); - + if (serachValue) { + var text1 = serachValue.replace("?", ""); + var text2 = item; + var text3 = item; + let chars = text1.split(""); + let indexs = []; + chars.map((i) => { + let findIndexes = findIndex(text3, i); + if (findIndexes.length > 0) { + text3 = text3.split(""); + text3[findIndexes] = "$"; + text3 = text3.join(""); + indexs = [...indexs, ...findIndexes]; + } + }); + text2.split("").map((itemValue, index) => { + let check = indexs.find((i) => i === index); + if (check !== undefined) { + itemHtml += `${itemValue}`; + } else { + itemHtml += `<span class='highlight'>${itemValue}</span>`; + } + }); + } else { + itemHtml = item + } if (item.length === 1) { ok = false; newWordsLength = newWordsLength - 1; } else { let ScrabbleLetterScore = ScrabbleScore(); @@ -461,301 +373,235 @@ item = item.toLowerCase(); for (let i = 0; i < item.length; i++) { sum += ScrabbleLetterScore[item[i]] || 0; // for unknown characters } dataArr.push(item); - return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item.toLowerCase()}"> - <li>${itemHtml} - <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span> - </li></a>`; + return ` + <a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item.toLowerCase()}"> + ${itemHtml} + <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px">${sum}</span> + </a> + `; } }); - if (result[0] !== undefined) { - var option = document.createElement("option"); - option.text = `${i} Letter`; - option.value = i; - lengthSelect.setAttribute("onchange", `Filtering(${i})`) - lengthSelect.add(option); + if (wordLength.value) { + lengthSelect.style.display = "none" + } else { + var option = document.createElement("option"); + option.text = `${i} Letter`; + option.value = i; + lengthSelect.setAttribute("onchange", `Filtering(${i})`) + lengthSelect.add(option); + lengthSelect.style.display = "block" + } - // tab_container.innerHTML += ` - // <input type="button" id="Tab_${i}" onclick="Filtering(${i})" value="${i} Letter" - // class="tab_link cursorPointer" /> - // `; - // let tabs = document.getElementsByClassName("tab_link"); - // tabs[0] ? tabs[0].classList.add("active-tab") : ""; + result = result.slice(0, 25) + main.innerHTML += ` - <div class="allGroupWords wordlistContainer" id="alpha_${i}"> - <div class="wordListHeading"> - <h3 class="lead">${i} Letter Words</h3> - </div> - <div class="wordList"> - <ul class="ul list-unstyled"> - ${result.join("")} - </ul> - </div> - </div> - `; + <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"> + <button onclick="showMoreWords(this)" type="button" class="my-4 showmore_btn" id="${i}">More Words</button> + </div> + </div>` + + showMoreLimit() } } } - theSelect.addEventListener("change", () => { - sortValue = theSelect[theSelect.selectedIndex].text; - if (sortValue == "Z-A") { - sortBool = true; - sortby(sortBool, dataArr); - } else { - sortBool = false; - sortby(sortBool, dataArr); - } - if (sortValue == "Points") { - sortBool = true; - sortPointsby(sortBool, dataArr); - } - }); - sortValue = theSelect[theSelect.selectedIndex].text; - if (sortValue == "Z-A") { - sortby(sortBool, dataArr); - } - if (sortValue == "Points") { - sortPointsby(sortBool, dataArr); - } if (newWordsLength === 0) { - errorMsg.innerHTML = "no words found"; - } else { - wordCount.innerHTML = `<strong>Found ${newWordsLength} words with letters with ${serachValue.split( - "" - )}</strong>`; - } - } -} + errorMsg.innerHTML = "No Words Found"; + document.querySelector(".sortingFilters").style.display = "none" -// sorting by points -function sortPointsby(sortValue, data) { - main.innerHTML = ""; - if (sortValue) { - let newWordsLength = 0; - for (let i = serachValue.length; i >= 1; i--) { - var newdata = data.filter((item) => item.length === i); - if (newdata.length === 0) { - main.innerHTML += ""; + } else { + if (serachValue) { + wordCount.innerHTML = `<strong>Found ${newWordsLength} words with letters with ${serachValue.split("")}</strong>`; } else { - newWordsLength += newdata.length; - var newArray = []; - newdata.map((item) => { - if (item.length === 1) { - ok = false; - newWordsLength = newWordsLength - 1; - } else { - let ScrabbleLetterScore = ScrabbleScore(); - let points = 0; - item = item.toLowerCase(); - for (let i = 0; i < item.length; i++) { - points += ScrabbleLetterScore[item[i]] || 0; // for unknown characters - } - const value = { - words: item, - points: points, - }; - newArray.push(value); - } - }); - newArray.sort(function (a, b) { - return b.points - a.points; - }); - const result = newArray.map((item) => { - var text1 = serachValue.replace("?", ""); - var text2 = item.words; - var text3 = item.words; - function findIndex(str, char) { - const strLength = str.length; - const indexes = []; - let newStr = str; - while (newStr && newStr.indexOf(char) > -1) { - indexes.push(newStr.indexOf(char) + strLength - newStr.length); - newStr = newStr.substring(newStr.indexOf(char) + 1); - newStr = newStr.substring(newStr.indexOf(char) + 1); - } - return indexes; - } - let chars = text1.split(""); - let indexs = []; - chars.map((i) => { - let findIndexes = findIndex(text3, i); - if (findIndexes.length > 0) { - text3 = text3.split(""); - text3[findIndexes] = "$"; - text3 = text3.join(""); - indexs = [...indexs, ...findIndexes]; - } - }); - let itemHtml = ""; - text2.split("").map((itemValue, index) => { - let check = indexs.find((i) => i === index); - if (check !== undefined) { - itemHtml += `${itemValue}`; - } else { - itemHtml += `<span class='highlight'>${itemValue}</span>`; - } - }); - return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item.words}"> - <li>${itemHtml} - <span class="points" value="${item.points}" style="position:relative; top:4px; font-size:12px"> ${item.points}</span> - </li></a>`; - }); + let startwithMsg = "" + let endwithMsg = "" + let containsMsg = "" + let lengthMsg = "" + let inputVal = "" + if (serachValue) { + inputVal = `${input.value.split("")} ` + } + if (prefixValue) { + startwithMsg = `starting with ${prefixValue.split("")}` + } + if (suffixValue) { + endwithMsg = `ending with ${suffixValue.split("")} ` + } + if (containsValue) { + containsMsg = `containing with ${containsValue.split("")} ` + } + if (lengthValue) { + lengthMsg = `with ${lengthValue} letter words` + } + let msg = `<strong> Found ${newWordsLength} words with letters + ${lengthMsg} ${inputVal} ${startwithMsg} ${endwithMsg} ${containsMsg} </strong>` - main.innerHTML += ` - <div class="allGroupWords wordlistContainer" id="alpha_${i}"> - <div class="wordListHeading"> - <h3 class="lead">${i} Letter Words</h3> - </div> - <div class="wordList"> - <ul class="ul list-unstyled"> - ${result.join("")} - </ul> - </div> - </div> - `; + wordCount.innerHTML = `${msg} ` } } } } -// sort by aplhabets -function sortby(sortBool, data) { - if (sortBool) { - main.innerHTML = ""; - data.reverse(); - let newWordsLength = 0; - for (let i = serachValue.length; i >= 1; i--) { - var newdata = data.filter((item) => item.length === i); - if (newdata.length === 0) { - main.innerHTML += ""; - } else { - newWordsLength += newdata.length; - const result = newdata.map((item) => { - var text1 = serachValue.replace("?", ""); - var text2 = item; - var text3 = item; - let chars = text1.split(""); - let indexs = []; - chars.map((i) => { - let findIndexes = findIndex(text3, i); - if (findIndexes.length > 0) { - text3 = text3.split(""); - text3[findIndexes] = "$"; - text3 = text3.join(""); - indexs = [...indexs, ...findIndexes]; - } - }); - let itemHtml = ""; - text2.split("").map((itemValue, index) => { - let check = indexs.find((i) => i === index); - if (check !== undefined) { - itemHtml += `${itemValue}`; - } else { - itemHtml += `<span class='highlight'>${itemValue}</span>`; - } - }); - if (item.length === 1) { - ok = false; - newWordsLength = newWordsLength - 1; - } else { - let ScrabbleLetterScore = ScrabbleScore(); - let sum = 0; - item = item.toLowerCase(); - for (let i = 0; i < item.length; i++) { - sum += ScrabbleLetterScore[item[i]] || 0; // for unknown characters - } - return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item.toLowerCase()}"> - <li>${itemHtml} - <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span> - </li></a>`; - } - }); +async function getMoreWords() { + let flattenedArray = moreData.flat(); + let uniqueArray = [...new Set(flattenedArray)]; + // console.log(uniqueArray); + return uniqueArray +} - main.innerHTML += ` - <div class="allGroupWords wordlistContainer" id="alpha_${i}"> - <div class="wordListHeading"> - <h3 class="lead">${i} Letter Words</h3> - </div> - <div class="wordList"> - <ul class="ul list-unstyled"> - ${result.join("")} - </ul> - </div> - </div> - `; - } +let previousDataIndex = null +let previousID = null; + +async function showMoreWords(e) { + try { + let showmore = e.parentElement.children[0]; + let id = showmore.id; + + // Compare previousID with current id + if (previousID !== null && parseInt(previousID) !== parseInt(id)) { + console.log("Previous ID:", previousID); + console.log("Current ID:", id); + previousDataIndex = data_index; + data_index = 25 } - } else { - main.innerHTML = ""; - data.sort(); - for (let i = serachValue.length; i >= 1; i--) { - var newdata = data.filter((item) => item.length === i); - if (newdata.length === 0) { - main.innerHTML += ""; - } else { - const result = newdata.map((item) => { - var text1 = serachValue.replace("?", ""); - var text2 = item; - var text3 = item; - let chars = text1.split(""); - let indexs = []; - chars.map((i) => { - let findIndexes = findIndex(text3, i); - if (findIndexes.length > 0) { - text3 = text3.split(""); - text3[findIndexes] = "$"; - text3 = text3.join(""); - indexs = [...indexs, ...findIndexes]; - } - }); + else if (previousID !== null && parseInt(previousID) === parseInt(id)) { + data_index = previousDataIndex + 25; // Resume data_index from previous record + } + previousID = id; + + console.log("Previous data_index:", previousDataIndex); + 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++) { + if (full_words[d] != undefined) { let itemHtml = ""; - text2.split("").map((itemValue, index) => { - let check = indexs.find((i) => i === index); - if (check !== undefined) { - itemHtml += `${itemValue}`; - } else { - itemHtml += `<span class='highlight'>${itemValue}</span>`; - } - }); - if (item.length === 1) { - ok = false; + if (serachValue) { + var text1 = serachValue.replace("?", ""); + var text2 = full_words[d]; + var text3 = full_words[d]; + let chars = text1.split(""); + let indexs = []; + chars.map((i) => { + let findIndexes = findIndex(text3, i); + if (findIndexes.length > 0) { + text3 = text3.split(""); + text3[findIndexes] = "$"; + text3 = text3.join(""); + indexs = [...indexs, ...findIndexes]; + } + }); + text2.split("").map((itemValue, index) => { + let check = indexs.find((i) => i === index); + if (check !== undefined) { + itemHtml += `${itemValue}`; + } else { + itemHtml += `<span class='highlight'>${itemValue}</span>`; + } + }); } else { - let ScrabbleLetterScore = ScrabbleScore(); - let sum = 0; - item = item.toLowerCase(); - for (let i = 0; i < item.length; i++) { - sum += ScrabbleLetterScore[item[i]] || 0; // for unknown characters - } - - return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item.toLowerCase()}"> - <li>${itemHtml} - <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span> - </li></a>`; + itemHtml = full_words[d] } - }); - main.innerHTML += ` - <div class="allGroupWords wordlistContainer" id="alpha_${i}"> - <div class="wordListHeading"> - <h3 class="lead">${i} Letter Words</h3> - </div> - <div class="wordList"> - <ul class="ul list-unstyled"> - ${result.join("")} - </ul> - </div> - </div> - `; + 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 + } + + let span = document.createElement("span"); + span.setAttribute("class", "points"); + span.setAttribute("value", `${points}`); + span.innerHTML = `${points}`; + + let a = document.createElement("a"); + a.setAttribute("class", "anchor__style"); + a.setAttribute("target", "_blank"); + a.setAttribute("href", "/word-meaning?search=" + full_words[d].replace(/<\/?[^>]+>/gi, '')); + a.setAttribute("data-original-title", `Lookup ${full_words[d].replace(/<\/?[^>]+>/gi, '')} in Dictionary`) + a.innerHTML = ` ${itemHtml} `; + a.appendChild(span) + content_area.appendChild(a); + } } + document.getElementById(id).innerHTML = `More Words`; + previousDataIndex = data_index; + data_index += 25; + } else { + data_index = 25 + document.getElementById(id).style.display = "none"; } + } catch (error) { + console.error("Error fetching or processing data:", error); } } +function showMoreLimit() { + 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) { + tableFooter[i].style.display = "none"; + } + } +} +function sortWords(data) { + if (sortingFilter.selectedIndex == 0) { + return data; + } else if (sortingFilter.selectedIndex == 1) { + return data.sort(); + } else if (sortingFilter.selectedIndex == 2) { + return data.reverse(); + } else if (sortingFilter.selectedIndex == 3) { + var tempArr = []; + var newArray = []; + data.map((item) => { + let newWordsLength = 0; + if (item.length === 1) { + ok = false; + newWordsLength = newWordsLength - 1; + } else { + let ScrabbleLetterScore = ScrabbleScore(); + let points = 0; + item = item.toLowerCase(); + for (let i = 0; i < item.length; i++) { + points += ScrabbleLetterScore[item[i]] || 0; // for unknown characters + } + const value = { + words: item, + points: points, + }; + newArray.push(value); + } + }); + + newArray.sort(function (a, b) { + return b.points - a.points; + }); + + newArray.map((ele) => { + tempArr.push(ele.words); + }); + + return tempArr; + } +} // Scrabble Point Array const ScrabbleScore = () => { let twl06_sowpods = { a: 1, e: 1, \ No newline at end of file