|
16 | 16 | $('upload').onchange = function() { |
17 | 17 | var fr = new FileReader(); |
18 | 18 |
|
19 | | - fr.onload = function(e) { |
| 19 | + fr.onload = async function(e) { |
| 20 | + |
| 21 | + |
20 | 22 | var result = JSON.parse(e.target.result); |
21 | 23 | console.log(result); |
22 | 24 | for (let key in result) { |
23 | 25 | if ( |
24 | | - key.startsWith('block.') || |
25 | | - key.startsWith('death.') || |
26 | | - key.startsWith('container.') || |
27 | | - key.startsWith('advancements.') || |
28 | | - key.startsWith('biome.') || |
29 | | - key.startsWith('color.') || |
30 | | - key.startsWith('createWorld.') || |
31 | | - key.startsWith('deathScreen.') || |
32 | | - key.startsWith('effect.') || |
33 | | - key.startsWith('enchantment.') || |
34 | | - key.startsWith('entity.') || |
35 | | - key.startsWith('gamerule.') || |
36 | | - key.startsWith('item.') || |
37 | | - key.startsWith('itemGroup.') || |
38 | | - key.startsWith('jukebox_song.') || |
39 | | - key.startsWith('key.') || |
40 | | - key.startsWith('menu.') || |
41 | | - key.startsWith('merchant.') || |
42 | | - key.startsWith('options.') || |
43 | | - key.startsWith('painting.') || |
44 | | - key.startsWith('soundCategory.') || |
45 | | - key.startsWith('spectatorMenu.') || |
46 | | - key.startsWith('stat.') || |
47 | | - key.startsWith('structure.') || |
48 | | - key.startsWith('subtitles.') || |
49 | | - key.startsWith('telemetry.') || |
50 | | - key.startsWith('trim_material.') || |
51 | | - key.startsWith('tutorial.') |
| 26 | + key.startsWith('block.') |
| 27 | + || key.startsWith('death.') |
| 28 | + || key.startsWith('container.') |
| 29 | + || key.startsWith('advancements.') |
| 30 | + || key.startsWith('biome.') |
| 31 | + || key.startsWith('color.') |
| 32 | + || key.startsWith('createWorld.') |
| 33 | + || key.startsWith('deathScreen.') |
| 34 | + || key.startsWith('effect.') |
| 35 | + || key.startsWith('enchantment.') |
| 36 | + || key.startsWith('entity.') |
| 37 | + || key.startsWith('item.') |
| 38 | + || key.startsWith('itemGroup.') |
| 39 | + || key.startsWith('jukebox_song.') |
| 40 | + || key.startsWith('key.') |
| 41 | + || key.startsWith('merchant.') |
| 42 | + || key.startsWith('painting.') |
| 43 | + || key.startsWith('soundCategory.') |
| 44 | + || key.startsWith('spectatorMenu.') |
| 45 | + || key.startsWith('stat.') |
| 46 | + || key.startsWith('structure.') |
| 47 | + || key.startsWith('subtitles.') |
| 48 | + || key.startsWith('trim_material.') |
| 49 | + || key.startsWith('tutorial.') |
52 | 50 | ) { |
53 | | - let value = result[key]; |
54 | | - value = value |
55 | | - .replace(/[^a-z ]/gi, '') |
56 | | - .replace(/ +(?= )/g,'') |
57 | | - .toLowerCase(); |
58 | | - if (value.replaceAll(" ","").length<3) continue; |
59 | | - let words = value |
60 | | - .split(" ") |
61 | | - .filter(a => a.length > 2); |
62 | | - words.push(value.replaceAll(" ","")); |
| 51 | + let fullPhrase = result[key]; |
| 52 | + let cleanedPhrase = fullPhrase.toLowerCase(); |
| 53 | + let words = cleanedPhrase.split(" "); |
| 54 | + words.push(cleanedPhrase.replaceAll(" ","")); // add entire phrase with spaces removed (eg craftingtable) |
| 55 | + let cleanedWords = words.filter(w => !w.includes("%") && !w.includes("$")) |
| 56 | + .map(w => w.replace(/[^a-z ]/g, '')); |
63 | 57 |
|
64 | | - for (let word of words) { |
65 | | - if (word in output) { |
66 | | - output[word].push(result[key]); |
67 | | - } else { |
68 | | - output[word] = [result[key]]; |
| 58 | + for (let cleanword of cleanedWords) { |
| 59 | + if (cleanword.length > 2) { |
| 60 | + if (cleanword in output) { |
| 61 | + output[cleanword].push(result[key]); |
| 62 | + } else { |
| 63 | + output[cleanword] = [result[key]]; |
| 64 | + } |
69 | 65 | } |
70 | 66 | } |
71 | 67 | } |
|
75 | 71 | (a, b) => |
76 | 72 | // pick b if it's shorter, or same length but a has '%' and b doesn't |
77 | 73 | b.length < a.length || |
78 | | - (b.length === a.length && a.includes('%') && !b.includes('%')) |
| 74 | + (b.length === a.length && a.includes('%') && !b.includes('%') && a.includes('$') && !b.includes('$')) |
79 | 75 | ? b |
80 | 76 | : a |
81 | 77 | ) |
|
96 | 92 |
|
97 | 93 | alert(i+" found"); |
98 | 94 | $('out').value = JSON.stringify(outputSorted); |
| 95 | + for (let numLetters in outputSorted) { |
| 96 | + console.log(numLetters + ": " + Object.keys(outputSorted[numLetters]).length) |
| 97 | + } |
99 | 98 | } |
100 | 99 |
|
101 | 100 | fr.readAsText($('upload').files[0]); |
102 | 101 | } |
| 102 | + |
| 103 | + |
103 | 104 |
|
104 | 105 | </script> |
105 | 106 | </body> |
|
0 commit comments