word-games-theme 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/_includes/section/commonPage.html +1 -1
- data/_layouts/page.html +13 -0
- data/_layouts/page2.html +9 -0
- data/assets/css/advancedFilter.css +1 -1
- data/assets/css/style.css +2 -3
- data/assets/js/X-letter-test.js +676 -0
- data/assets/js/X-letter.js +2 -1
- data/assets/js/wordScrabble-test.js +786 -0
- data/assets/js/words-in-certain-positions.js +1 -1
- data/assets/js/words-starting-with.js +50 -8
- metadata +4 -3
- data/assets/js/test.js +0 -763
@@ -0,0 +1,676 @@
|
|
1
|
+
const getScript = document.currentScript
|
2
|
+
const letterLen = getScript.dataset.letter
|
3
|
+
const ablank = getScript.dataset.ablank
|
4
|
+
|
5
|
+
const siteUrl = getScript.dataset.url
|
6
|
+
|
7
|
+
let errorMsg = document.querySelector('.errorMsg')
|
8
|
+
let script = document.currentScript
|
9
|
+
let wordCount = document.querySelector('.wordCount')
|
10
|
+
let main = document.querySelector('.main')
|
11
|
+
|
12
|
+
const params = new URLSearchParams(window.location.search)
|
13
|
+
let serachValue = params.get('search').toLowerCase()
|
14
|
+
let prefixValue = params.get('prefix')
|
15
|
+
let containsValue = params.get('contains')
|
16
|
+
let suffixValue = params.get('suffix')
|
17
|
+
let exculdeValue = params.get('exculde')
|
18
|
+
let includeValue = params.get('include')
|
19
|
+
let lengthValue = params.get('length')
|
20
|
+
let dictonary = params.get('dictionary')
|
21
|
+
|
22
|
+
|
23
|
+
let tab_link_wrapper = document.querySelector('.tab_link_wrapper')
|
24
|
+
tab_link_wrapper.style.display = "none"
|
25
|
+
|
26
|
+
let home_page_search_result = document.querySelector("#home_page_search_result")
|
27
|
+
let homePageSearchResult = `/result?search=${serachValue}&dictionary=Dictionary&prefix=&contains=&suffix=&exculde=&inculde=&length=`;
|
28
|
+
|
29
|
+
let txtBox = document.querySelector('.txtBox')
|
30
|
+
txtBox.focus()
|
31
|
+
txtBox.value = serachValue
|
32
|
+
|
33
|
+
|
34
|
+
if (ablank) {
|
35
|
+
if (!serachValue.includes("?")) {
|
36
|
+
if (serachValue.length <= letterLen || serachValue.length >= letterLen) {
|
37
|
+
serachValue = serachValue + '?'
|
38
|
+
txtBox.value = serachValue
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
let letterCloseButton = document.querySelector('.letter-close-button-commonPage')
|
43
|
+
if (serachValue) {
|
44
|
+
letterCloseButton.classList.add("ltr-cls-btn-commonPage")
|
45
|
+
}
|
46
|
+
letterCloseButton.addEventListener("click", () => {
|
47
|
+
txtBox.value = ""
|
48
|
+
letterCloseButton.classList.remove("ltr-cls-btn-commonPage")
|
49
|
+
})
|
50
|
+
|
51
|
+
txtBox.addEventListener('input', (e) => {
|
52
|
+
if (e.target.value === "") {
|
53
|
+
letterCloseButton.classList.remove("ltr-cls-btn-commonPage")
|
54
|
+
} else {
|
55
|
+
letterCloseButton.classList.add("ltr-cls-btn-commonPage")
|
56
|
+
}
|
57
|
+
let rangeOfBlankTile = script.dataset.range
|
58
|
+
e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, '')
|
59
|
+
if (rangeOfBlankTile === '') {
|
60
|
+
rangeOfBlankTile = 3
|
61
|
+
}
|
62
|
+
e.target.value = e.target.value.replace(/ /g, '?')
|
63
|
+
let data = []
|
64
|
+
data = e.target.value.split('').filter((i) => i === '?')
|
65
|
+
// console.log(data)
|
66
|
+
if (data.length > rangeOfBlankTile) {
|
67
|
+
e.target.value = e.target.value.replace(/\?$/, '')
|
68
|
+
}
|
69
|
+
})
|
70
|
+
|
71
|
+
var theSelect = document.getElementById('select_dropDown')
|
72
|
+
const sortup = document.querySelector(".sortup-icon")
|
73
|
+
let bool = false
|
74
|
+
sortup.addEventListener("click", () => {
|
75
|
+
if (bool) {
|
76
|
+
theSelect.size = 0
|
77
|
+
bool = false
|
78
|
+
theSelect.style.display = "none"
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
bool = true
|
82
|
+
theSelect.size = 3
|
83
|
+
theSelect.style.display = "block"
|
84
|
+
}
|
85
|
+
})
|
86
|
+
document.querySelector('.select_dropDown2').value = dictonary
|
87
|
+
const getDiff = (text1, text2) => {
|
88
|
+
var diffRange = []
|
89
|
+
var currentRange = undefined
|
90
|
+
for (var i = 0; i < text1.length; i++) {
|
91
|
+
if (text1[i] != text2[i]) {
|
92
|
+
if (currentRange == undefined) {
|
93
|
+
currentRange = [i]
|
94
|
+
}
|
95
|
+
}
|
96
|
+
if (currentRange != undefined && text1[i] == text2[i]) {
|
97
|
+
currentRange.push(i)
|
98
|
+
diffRange.push(currentRange)
|
99
|
+
currentRange = undefined
|
100
|
+
}
|
101
|
+
}
|
102
|
+
if (currentRange != undefined) {
|
103
|
+
currentRange.push(i)
|
104
|
+
diffRange.push(currentRange)
|
105
|
+
}
|
106
|
+
return diffRange
|
107
|
+
}
|
108
|
+
const getData = async (serachValue) => {
|
109
|
+
try {
|
110
|
+
errorMsg.innerHTML = ""
|
111
|
+
wordCount.innerHTML = ""
|
112
|
+
home_page_search_result.innerHTML = ""
|
113
|
+
let selectedDictionary = document.querySelector('.select_dropDown2').value
|
114
|
+
main.innerHTML = `<div class="loader">
|
115
|
+
<img src='/assets/images/loading.gif'>
|
116
|
+
<div style="font-weight:900;font-size:14px" >Finding words - Powered by ${siteUrl.replace(/^https?:\/\//, '')}</div>
|
117
|
+
</div>`
|
118
|
+
const response = await fetch(
|
119
|
+
`/.netlify/functions/getWords?name=${serachValue}&selecteddictionary=${selectedDictionary}`
|
120
|
+
)
|
121
|
+
const data = await response.json()
|
122
|
+
main.innerHTML = ''
|
123
|
+
x_with_letters(data)
|
124
|
+
} catch (error) {
|
125
|
+
console.log(error)
|
126
|
+
}
|
127
|
+
}
|
128
|
+
// calling function
|
129
|
+
getData(serachValue.toLowerCase())
|
130
|
+
function logSubmit(event) {
|
131
|
+
let selectedDictionary = document.querySelector('.select_dropDown2').value
|
132
|
+
event.preventDefault();
|
133
|
+
if (history.pushState) {
|
134
|
+
var newurl = window.location.protocol + "//" + window.location.host +
|
135
|
+
window.location.pathname + '?' + "search" + "=" + txtBox.value.toLowerCase() + '&' +
|
136
|
+
'dictionary' + '=' + selectedDictionary +
|
137
|
+
'&' + 'prefix' + '=' + startsWith.value + '&' + 'contains' + '=' + mustInclude.value +
|
138
|
+
'&' + 'suffix' + '=' + endsWith.value + '&' + 'exculde' + '=' + exculdeWith.value +
|
139
|
+
'&' + 'include' + '=' + inculdeWith.value + '&' + 'length' + '=' + wordLength.value;
|
140
|
+
window.history.pushState({ path: newurl }, '', newurl);
|
141
|
+
|
142
|
+
const params = new URLSearchParams(window.location.search)
|
143
|
+
serachValue = params.get('search')
|
144
|
+
prefixValue = params.get('prefix')
|
145
|
+
containsValue = params.get('contains')
|
146
|
+
suffixValue = params.get('suffix')
|
147
|
+
exculdeValue = params.get('exculde')
|
148
|
+
includeValue = params.get('include')
|
149
|
+
lengthValue = params.get('length')
|
150
|
+
dictonary = params.get('dictionary')
|
151
|
+
}
|
152
|
+
getData(txtBox.value.toLowerCase())
|
153
|
+
addFilterCount()
|
154
|
+
|
155
|
+
}
|
156
|
+
applyBtn.addEventListener('submit', logSubmit)
|
157
|
+
form.addEventListener('submit', logSubmit);
|
158
|
+
|
159
|
+
|
160
|
+
function x_with_letters(data) {
|
161
|
+
main.innerHTML = ""
|
162
|
+
if (typeof data === 'string') {
|
163
|
+
errorMsg.innerHTML = 'No words found'
|
164
|
+
wordCount.innerHTML = `<strong>Found 0 words with letters ${serachValue.split(
|
165
|
+
''
|
166
|
+
)}</strong>`
|
167
|
+
} else {
|
168
|
+
let newWordsLength = 0
|
169
|
+
let filterData = ''
|
170
|
+
|
171
|
+
|
172
|
+
if (letterLen) {
|
173
|
+
filterData = data.filter((item) => item.length == letterLen)
|
174
|
+
}
|
175
|
+
|
176
|
+
if (prefixValue) {
|
177
|
+
filterData = filterData.filter((item2) =>
|
178
|
+
item2.startsWith(prefixValue.toLowerCase())
|
179
|
+
)
|
180
|
+
startsWith.classList.add('tick')
|
181
|
+
startsWith.value = prefixValue
|
182
|
+
} else {
|
183
|
+
startsWith.classList.remove('tick')
|
184
|
+
}
|
185
|
+
if (containsValue) {
|
186
|
+
filterData = filterData.filter((item) =>
|
187
|
+
item.includes(containsValue.toLowerCase())
|
188
|
+
)
|
189
|
+
mustInclude.classList.add('tick')
|
190
|
+
mustInclude.value = containsValue
|
191
|
+
} else {
|
192
|
+
mustInclude.classList.remove('tick')
|
193
|
+
}
|
194
|
+
if (suffixValue) {
|
195
|
+
filterData = filterData.filter((item) =>
|
196
|
+
item.endsWith(suffixValue.toLowerCase())
|
197
|
+
)
|
198
|
+
endsWith.classList.add('tick')
|
199
|
+
endsWith.value = suffixValue
|
200
|
+
} else {
|
201
|
+
endsWith.classList.remove('tick')
|
202
|
+
}
|
203
|
+
if (exculdeValue) {
|
204
|
+
let data = []
|
205
|
+
filterData.map((item) => {
|
206
|
+
let check = false
|
207
|
+
for (let e = 0; e < exculdeValue.length; e++) {
|
208
|
+
const element = exculdeValue[e].toLowerCase()
|
209
|
+
if (item.includes(element)) {
|
210
|
+
check = true
|
211
|
+
break
|
212
|
+
} else {
|
213
|
+
check = false
|
214
|
+
}
|
215
|
+
}
|
216
|
+
if (check === false) {
|
217
|
+
data.push(item)
|
218
|
+
}
|
219
|
+
})
|
220
|
+
exculdeWith.classList.add('tick')
|
221
|
+
exculdeWith.value = exculdeValue
|
222
|
+
filterData = data
|
223
|
+
} else {
|
224
|
+
exculdeWith.classList.remove('tick')
|
225
|
+
}
|
226
|
+
|
227
|
+
if (includeValue) {
|
228
|
+
let data = []
|
229
|
+
filterData.map((item) => {
|
230
|
+
let check = false
|
231
|
+
for (let e = 0; e < includeValue.length; e++) {
|
232
|
+
const element = includeValue[e].toLowerCase()
|
233
|
+
if (!item.includes(element)) {
|
234
|
+
check = true
|
235
|
+
break
|
236
|
+
} else {
|
237
|
+
check = false
|
238
|
+
}
|
239
|
+
}
|
240
|
+
if (check === false) {
|
241
|
+
data.push(item)
|
242
|
+
}
|
243
|
+
})
|
244
|
+
inculdeWith.classList.add('tick')
|
245
|
+
inculdeWith.value = includeValue
|
246
|
+
filterData = data
|
247
|
+
} else {
|
248
|
+
inculdeWith.classList.remove('tick')
|
249
|
+
}
|
250
|
+
|
251
|
+
if (filterData.length === 0) {
|
252
|
+
main.innerHTML += ''
|
253
|
+
errorMsg.innerHTML = 'No words Found with this length'
|
254
|
+
} else {
|
255
|
+
// sort eventlistener
|
256
|
+
theSelect.addEventListener('change', () => {
|
257
|
+
sortValue = theSelect[theSelect.selectedIndex].text
|
258
|
+
if (sortValue == 'Z-A') {
|
259
|
+
sortBool = true
|
260
|
+
sortby(sortBool, filterData, itemLength)
|
261
|
+
} else {
|
262
|
+
sortBool = false
|
263
|
+
sortby(sortBool, filterData, itemLength)
|
264
|
+
}
|
265
|
+
if (sortValue == 'Points') {
|
266
|
+
sortBool = true
|
267
|
+
sortPointsby(sortBool, filterData, itemLength)
|
268
|
+
}
|
269
|
+
})
|
270
|
+
|
271
|
+
newWordsLength += filterData.length
|
272
|
+
let itemLength = ''
|
273
|
+
const result = filterData.map((item) => {
|
274
|
+
itemLength = item.length
|
275
|
+
let ScrabbleLetterScore = ScrabbleScore()
|
276
|
+
sum = 0
|
277
|
+
item = item.toLowerCase()
|
278
|
+
for (let i = 0; i < item.length; i++) {
|
279
|
+
sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
|
280
|
+
}
|
281
|
+
wordLength.value = itemLength
|
282
|
+
|
283
|
+
var text1 = serachValue.replace('?', '')
|
284
|
+
var text2 = item
|
285
|
+
var text3 = item
|
286
|
+
function findIndex(str, char) {
|
287
|
+
const strLength = str.length
|
288
|
+
const indexes = []
|
289
|
+
let newStr = str
|
290
|
+
while (newStr && newStr.indexOf(char) > -1) {
|
291
|
+
indexes.push(newStr.indexOf(char) + strLength - newStr.length)
|
292
|
+
newStr = newStr.substring(newStr.indexOf(char) + 1)
|
293
|
+
newStr = newStr.substring(newStr.indexOf(char) + 1)
|
294
|
+
}
|
295
|
+
return indexes
|
296
|
+
}
|
297
|
+
let chars = text1.split('')
|
298
|
+
let indexs = []
|
299
|
+
chars.map((i) => {
|
300
|
+
let findIndexes = findIndex(text3, i)
|
301
|
+
if (findIndexes.length > 0) {
|
302
|
+
text3 = text3.split('')
|
303
|
+
text3[findIndexes] = '$'
|
304
|
+
text3 = text3.join('')
|
305
|
+
indexs = [...indexs, ...findIndexes]
|
306
|
+
}
|
307
|
+
})
|
308
|
+
let itemHtml = ''
|
309
|
+
text2.split('').map((itemValue, index) => {
|
310
|
+
let check = indexs.find((i) => i === index)
|
311
|
+
if (check !== undefined) {
|
312
|
+
itemHtml += `${itemValue}`
|
313
|
+
} else {
|
314
|
+
itemHtml += `<span class='highlight'>${itemValue}</span>`
|
315
|
+
}
|
316
|
+
})
|
317
|
+
|
318
|
+
|
319
|
+
return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item}">
|
320
|
+
<li>${itemHtml}
|
321
|
+
<span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span>
|
322
|
+
</li></a>`
|
323
|
+
})
|
324
|
+
|
325
|
+
// tab_container.innerHTML += `
|
326
|
+
// <a href="#${itemLength}">
|
327
|
+
// <input type="button" value="${itemLength} Letter" id="Tab${itemLength}" onclick="addFilter(${itemLength})"
|
328
|
+
// class="tab_link">
|
329
|
+
// </a>
|
330
|
+
// `
|
331
|
+
|
332
|
+
// let tabs = document.getElementsByClassName('tab_link')
|
333
|
+
// tabs[0] ? tabs[0].classList.add('active-tab') : ''
|
334
|
+
|
335
|
+
home_page_search_result.href = homePageSearchResult
|
336
|
+
home_page_search_result.innerHTML = `See words of any length with letters ${serachValue.split("")}`
|
337
|
+
|
338
|
+
|
339
|
+
main.innerHTML += `
|
340
|
+
<div class="allGroupWords">
|
341
|
+
<div class="wordListHeading">
|
342
|
+
<h3 class="lead">${itemLength} Letter Words</h3>
|
343
|
+
</div>
|
344
|
+
<div class="wordList">
|
345
|
+
<ul class="ul list-unstyled">
|
346
|
+
${result.join('')}
|
347
|
+
</ul>
|
348
|
+
</div>
|
349
|
+
</div>
|
350
|
+
`
|
351
|
+
}
|
352
|
+
wordCount.innerHTML = `<strong>Found ${newWordsLength} words with letters with ${serachValue.split(
|
353
|
+
''
|
354
|
+
)}</strong>`
|
355
|
+
}
|
356
|
+
}
|
357
|
+
|
358
|
+
//Handling of filter counter in advanced filter
|
359
|
+
function addFilterCount() {
|
360
|
+
let filter_val = document.getElementsByClassName('filter_val')
|
361
|
+
let filter = document.querySelector('.filter_count')
|
362
|
+
let filter_count = 0
|
363
|
+
|
364
|
+
filter_val[0].value = prefixValue
|
365
|
+
filter_val[1].value = containsValue
|
366
|
+
filter_val[2].value = suffixValue
|
367
|
+
filter_val[3].value = exculdeValue
|
368
|
+
filter_val[4].value = includeValue
|
369
|
+
filter_val[5].value = lengthValue
|
370
|
+
|
371
|
+
for (var i = 0; i <= 4; i++) {
|
372
|
+
if (filter_val[i].value != '') {
|
373
|
+
filter_count += 1
|
374
|
+
}
|
375
|
+
if (filter_count === 0) {
|
376
|
+
filter.style.display = 'none'
|
377
|
+
} else {
|
378
|
+
filter.style.display = 'inline-block'
|
379
|
+
}
|
380
|
+
|
381
|
+
filter.innerHTML = filter_count
|
382
|
+
}
|
383
|
+
}
|
384
|
+
addFilterCount()
|
385
|
+
|
386
|
+
// sorting by points
|
387
|
+
function sortPointsby(sortValue, data, i) {
|
388
|
+
if (sortValue) {
|
389
|
+
main.innerHTML = ''
|
390
|
+
let newArray = []
|
391
|
+
data.map((item) => {
|
392
|
+
let ScrabbleLetterScore = ScrabbleScore()
|
393
|
+
let points = 0
|
394
|
+
item = item.toLowerCase()
|
395
|
+
for (let i = 0; i < item.length; i++) {
|
396
|
+
points += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
|
397
|
+
}
|
398
|
+
const value = {
|
399
|
+
words: item,
|
400
|
+
points: points,
|
401
|
+
}
|
402
|
+
newArray.push(value)
|
403
|
+
newArray.sort(function (a, b) {
|
404
|
+
return b.points - a.points
|
405
|
+
})
|
406
|
+
})
|
407
|
+
const result = newArray.map((item) => {
|
408
|
+
var text1 = serachValue.replace('?', '')
|
409
|
+
var text2 = item.words
|
410
|
+
var text3 = item.words
|
411
|
+
function findIndex(str, char) {
|
412
|
+
const strLength = str.length
|
413
|
+
const indexes = []
|
414
|
+
let newStr = str
|
415
|
+
while (newStr && newStr.indexOf(char) > -1) {
|
416
|
+
indexes.push(newStr.indexOf(char) + strLength - newStr.length)
|
417
|
+
newStr = newStr.substring(newStr.indexOf(char) + 1)
|
418
|
+
newStr = newStr.substring(newStr.indexOf(char) + 1)
|
419
|
+
}
|
420
|
+
return indexes
|
421
|
+
}
|
422
|
+
let chars = text1.split('')
|
423
|
+
let indexs = []
|
424
|
+
chars.map((i) => {
|
425
|
+
let findIndexes = findIndex(text3, i)
|
426
|
+
if (findIndexes.length > 0) {
|
427
|
+
text3 = text3.split('')
|
428
|
+
text3[findIndexes] = '$'
|
429
|
+
text3 = text3.join('')
|
430
|
+
indexs = [...indexs, ...findIndexes]
|
431
|
+
}
|
432
|
+
})
|
433
|
+
let itemHtml = ''
|
434
|
+
text2.split('').map((itemValue, index) => {
|
435
|
+
let check = indexs.find((i) => i === index)
|
436
|
+
if (check !== undefined) {
|
437
|
+
itemHtml += `${itemValue}`
|
438
|
+
} else {
|
439
|
+
itemHtml += `<span class='highlight'>${itemValue}</span>`
|
440
|
+
}
|
441
|
+
})
|
442
|
+
return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item.words}">
|
443
|
+
<li>${itemHtml}
|
444
|
+
<span class="points" value="${item.points}" style="position:relative; top:4px; font-size:12px"> ${item.points}</span>
|
445
|
+
</li></a>`
|
446
|
+
})
|
447
|
+
|
448
|
+
main.innerHTML += `
|
449
|
+
<div class="allGroupWords wordlistContainer" id="alpha_${i}">
|
450
|
+
<div class="wordListHeading">
|
451
|
+
<h3 class="lead">${i} Letter Words</h3>
|
452
|
+
</div>
|
453
|
+
<div class="wordList">
|
454
|
+
<ul class="ul list-unstyled">
|
455
|
+
${result.join('')}
|
456
|
+
</ul>
|
457
|
+
</div>
|
458
|
+
</div>
|
459
|
+
`
|
460
|
+
}
|
461
|
+
}
|
462
|
+
// sort by aplhabets
|
463
|
+
function sortby(sortBool, data, i) {
|
464
|
+
if (sortBool) {
|
465
|
+
main.innerHTML = ''
|
466
|
+
data.reverse()
|
467
|
+
const result = data.map((item) => {
|
468
|
+
let ScrabbleLetterScore = ScrabbleScore()
|
469
|
+
let sum = 0
|
470
|
+
item = item.toLowerCase()
|
471
|
+
for (let i = 0; i < item.length; i++) {
|
472
|
+
sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
|
473
|
+
}
|
474
|
+
|
475
|
+
var text1 = serachValue.replace('?', '')
|
476
|
+
var text2 = item
|
477
|
+
var text3 = item
|
478
|
+
function findIndex(str, char) {
|
479
|
+
const strLength = str.length
|
480
|
+
const indexes = []
|
481
|
+
let newStr = str
|
482
|
+
while (newStr && newStr.indexOf(char) > -1) {
|
483
|
+
indexes.push(newStr.indexOf(char) + strLength - newStr.length)
|
484
|
+
newStr = newStr.substring(newStr.indexOf(char) + 1)
|
485
|
+
newStr = newStr.substring(newStr.indexOf(char) + 1)
|
486
|
+
}
|
487
|
+
return indexes
|
488
|
+
}
|
489
|
+
let chars = text1.split('')
|
490
|
+
let indexs = []
|
491
|
+
chars.map((i) => {
|
492
|
+
let findIndexes = findIndex(text3, i)
|
493
|
+
if (findIndexes.length > 0) {
|
494
|
+
text3 = text3.split('')
|
495
|
+
text3[findIndexes] = '$'
|
496
|
+
text3 = text3.join('')
|
497
|
+
indexs = [...indexs, ...findIndexes]
|
498
|
+
}
|
499
|
+
})
|
500
|
+
let itemHtml = ''
|
501
|
+
text2.split('').map((itemValue, index) => {
|
502
|
+
let check = indexs.find((i) => i === index)
|
503
|
+
if (check !== undefined) {
|
504
|
+
itemHtml += `${itemValue}`
|
505
|
+
} else {
|
506
|
+
itemHtml += `<span class='highlight'>${itemValue}</span>`
|
507
|
+
}
|
508
|
+
})
|
509
|
+
|
510
|
+
return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item}">
|
511
|
+
<li>${itemHtml}
|
512
|
+
<span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span>
|
513
|
+
</li></a>`
|
514
|
+
})
|
515
|
+
|
516
|
+
main.innerHTML += `
|
517
|
+
<div class="allGroupWords wordlistContainer" id="alpha_${i}">
|
518
|
+
<div class="wordListHeading">
|
519
|
+
<h3 class="lead">${i} Letter Words</h3>
|
520
|
+
</div>
|
521
|
+
<div class="wordList">
|
522
|
+
<ul class="ul list-unstyled">
|
523
|
+
${result.join('')}
|
524
|
+
</ul>
|
525
|
+
</div>
|
526
|
+
</div>
|
527
|
+
|
528
|
+
`
|
529
|
+
} else {
|
530
|
+
main.innerHTML = ''
|
531
|
+
data.sort()
|
532
|
+
const result = data.map((item) => {
|
533
|
+
let ScrabbleLetterScore = ScrabbleScore()
|
534
|
+
let sum = 0
|
535
|
+
item = item.toLowerCase()
|
536
|
+
for (let i = 0; i < item.length; i++) {
|
537
|
+
sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
|
538
|
+
}
|
539
|
+
|
540
|
+
var text1 = serachValue.replace('?', '')
|
541
|
+
var text2 = item
|
542
|
+
var text3 = item
|
543
|
+
function findIndex(str, char) {
|
544
|
+
const strLength = str.length
|
545
|
+
const indexes = []
|
546
|
+
let newStr = str
|
547
|
+
while (newStr && newStr.indexOf(char) > -1) {
|
548
|
+
indexes.push(newStr.indexOf(char) + strLength - newStr.length)
|
549
|
+
newStr = newStr.substring(newStr.indexOf(char) + 1)
|
550
|
+
newStr = newStr.substring(newStr.indexOf(char) + 1)
|
551
|
+
}
|
552
|
+
return indexes
|
553
|
+
}
|
554
|
+
let chars = text1.split('')
|
555
|
+
let indexs = []
|
556
|
+
chars.map((i) => {
|
557
|
+
let findIndexes = findIndex(text3, i)
|
558
|
+
if (findIndexes.length > 0) {
|
559
|
+
text3 = text3.split('')
|
560
|
+
text3[findIndexes] = '$'
|
561
|
+
text3 = text3.join('')
|
562
|
+
indexs = [...indexs, ...findIndexes]
|
563
|
+
}
|
564
|
+
})
|
565
|
+
let itemHtml = ''
|
566
|
+
text2.split('').map((itemValue, index) => {
|
567
|
+
let check = indexs.find((i) => i === index)
|
568
|
+
if (check !== undefined) {
|
569
|
+
itemHtml += `${itemValue}`
|
570
|
+
} else {
|
571
|
+
itemHtml += `<span class='highlight'>${itemValue}</span>`
|
572
|
+
}
|
573
|
+
})
|
574
|
+
|
575
|
+
return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item}">
|
576
|
+
<li>${itemHtml}
|
577
|
+
<span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span>
|
578
|
+
</li></a>`
|
579
|
+
})
|
580
|
+
|
581
|
+
main.innerHTML += `
|
582
|
+
<div class="allGroupWords wordlistContainer" id="alpha_${i}">
|
583
|
+
<div class="wordListHeading">
|
584
|
+
<h3 class="lead">${i} Letter Words</h3>
|
585
|
+
</div>
|
586
|
+
<div class="wordList">
|
587
|
+
<ul class="ul list-unstyled">
|
588
|
+
${result.join('')}
|
589
|
+
</ul>
|
590
|
+
</div>
|
591
|
+
</div>
|
592
|
+
|
593
|
+
`
|
594
|
+
}
|
595
|
+
}
|
596
|
+
|
597
|
+
// Implement Active class
|
598
|
+
// const addFilter = () => {
|
599
|
+
// let tabs = document.getElementsByClassName('tab_link')
|
600
|
+
// tabs[0] ? tabs[0].classList.add('active-tab') : ''
|
601
|
+
|
602
|
+
// Array.from(tabs).map((item) => {
|
603
|
+
// item.classList.remove('active-tab')
|
604
|
+
// })
|
605
|
+
// main.innerHTML += ``
|
606
|
+
// let activeLetter = event.target
|
607
|
+
// // console.log(activeLetter)
|
608
|
+
// activeLetter.classList.add('active-tab')
|
609
|
+
// }
|
610
|
+
|
611
|
+
// Scrabble Point Counts
|
612
|
+
const ScrabbleScore = () => {
|
613
|
+
let twl06_sowpods = {
|
614
|
+
a: 1,
|
615
|
+
e: 1,
|
616
|
+
i: 1,
|
617
|
+
o: 1,
|
618
|
+
u: 1,
|
619
|
+
l: 1,
|
620
|
+
n: 1,
|
621
|
+
r: 1,
|
622
|
+
s: 1,
|
623
|
+
t: 1,
|
624
|
+
d: 2,
|
625
|
+
g: 2,
|
626
|
+
b: 3,
|
627
|
+
c: 3,
|
628
|
+
m: 3,
|
629
|
+
p: 3,
|
630
|
+
f: 4,
|
631
|
+
h: 4,
|
632
|
+
v: 4,
|
633
|
+
w: 4,
|
634
|
+
y: 4,
|
635
|
+
k: 5,
|
636
|
+
j: 8,
|
637
|
+
x: 8,
|
638
|
+
q: 10,
|
639
|
+
z: 10,
|
640
|
+
}
|
641
|
+
|
642
|
+
let wwfScore = {
|
643
|
+
a: 1,
|
644
|
+
b: 4,
|
645
|
+
c: 4,
|
646
|
+
d: 2,
|
647
|
+
e: 1,
|
648
|
+
f: 4,
|
649
|
+
g: 3,
|
650
|
+
h: 3,
|
651
|
+
i: 1,
|
652
|
+
j: 10,
|
653
|
+
k: 5,
|
654
|
+
l: 2,
|
655
|
+
m: 4,
|
656
|
+
n: 2,
|
657
|
+
o: 1,
|
658
|
+
p: 4,
|
659
|
+
q: 10,
|
660
|
+
r: 1,
|
661
|
+
s: 1,
|
662
|
+
t: 1,
|
663
|
+
u: 2,
|
664
|
+
v: 5,
|
665
|
+
w: 4,
|
666
|
+
x: 8,
|
667
|
+
y: 3,
|
668
|
+
z: 10,
|
669
|
+
}
|
670
|
+
|
671
|
+
if (dictonary === 'wwf') {
|
672
|
+
return wwfScore
|
673
|
+
} else {
|
674
|
+
return twl06_sowpods
|
675
|
+
}
|
676
|
+
}
|
data/assets/js/X-letter.js
CHANGED
@@ -110,12 +110,13 @@ const getDiff = (text1, text2) => {
|
|
110
110
|
}
|
111
111
|
const getData = async (serachValue) => {
|
112
112
|
try {
|
113
|
+
let selectedDictionary = document.querySelector('.select_dropDown2').value
|
113
114
|
main.innerHTML = `<div class="loader">
|
114
115
|
<img src='/assets/images/loading.gif'>
|
115
116
|
<div style="font-weight:900;font-size:14px" >Finding words - Powered by ${siteUrl.replace(/^https?:\/\//, '')}</div>
|
116
117
|
</div>`
|
117
118
|
const response = await fetch(
|
118
|
-
`/.netlify/functions/getWords?name=${serachValue}`
|
119
|
+
`/.netlify/functions/getWords?name=${serachValue}&selecteddictionary=${selectedDictionary}`
|
119
120
|
)
|
120
121
|
const data = await response.json()
|
121
122
|
main.innerHTML = ''
|