-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordgen.html
187 lines (172 loc) · 5.28 KB
/
wordgen.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html>
<body>
<p id="js-status">Words processed 0/0 (0%) Rate: 0/s Eta: Calculating..</p>
<button id="js-start" onclick="loadWordsFromClip()">Start</button>
</body>
<script>
const dictionary = {
"Neigh": "Hi",
"Néigh": "Fly",
"Nneigh": "Friend",
"Ṅeigh": "Help",
"Nee": "Dead",
" ": " ",
"Eigh": "Sleep",
"Neiǧh": "Home",
"Neɨgh": "Elf",
"Ɲeigh": "School/hell",
"Neeeiigh": "very/naughty/word",
"Negh": "sad",
"Neo": "No",
"Nieghe": "Chill",
"Hniegh": "book",
"Neihg": "come",
"Nee": "play",
"Nieggh": "genius",
"Nogh": "Now",
"Noeigh": "More",
"Neiogh": "Less",
"Eig": "Pain",
"Ni": "die",
"Nogḥ": "work",
"N": "in",
"Giddy up": "go",
"Noeiiigh": "hole",
"Nieό": "human",
"N": "I",
"Nhem": "them",
"Igh": "end",
"Ne": "start",
"No": "OwensMusic",
"Ha": "of",
"Neigh": "Good",
"Nah": "Bad",
};
const letterDic = {
"A": "a",
"B": "b",
"C": "c",
"D": "d",
"E": "ė",
"F": "f",
"G": "G",
"H": "H",
"I": "i",
"J": "j",
"K": "ဌ",
"L": "w",
"M": "m",
"N": "N",
"O": "o",
"P": "p",
"Q": "q",
"R": "r",
"S": "s",
"T": "T",
"U": "u",
"V": "v",
"W": "ẻ",
"X": "Ĭ",
"Y": "y",
"Z": "z",
}
let lps = 0;
let letters = 0;
setInterval(() => {
lps = letters;
letters = 0;
}, 1000);
async function loadWordsFromClip() {
calcLoadWordsFromClip(await navigator.clipboard.readText());
}
async function calcLoadWordsFromClip(_val) {
var time = new Date();
var status = document.getElementById('js-status');
console.log(status.innerText);
document.getElementById("js-start").style.display = "none";
var val = _val.replace('/\r/', '');
var words;
if (val.split(/\n/).length > 10)
words = val.split(/\n/);
else
words = val.split(' ');
var newString = '';
let lastsec = 0;
var t0 = performance.now();
for (let z = 0; z < words.length; z++) {
let element = filterPunctuation(words[z]);
console.log('Words processed ' + z + '/' + words.length + ' (' + ((z / words.length) * 100) + '%) Rate: ' + lps + '/s Eta: ' + ((words.length - z) / lps) + ' seconds!');
status.innerText = 'Words processed ' + z + '/' + words.length + ' (' + ((z / words.length) * 100) + '%) Rate: ' + lps + '/s Eta: ' + ((words.length - z) / lps) + ' seconds!';
var prefix = "\"" + words[z] + "\": \"";
var suffix = "\",";
letters++;
if (performance.now() > t0 + 1000) {
lps = letters;
letters = 0;
t0 = performance.now()
}
newString += prefix + findValueByKey(element[0]) + suffix + element[1];
}
console.log(newString);
status.innerText = newString;
}
function copyToClipboard(text) {
const elem = document.createElement('textarea');
elem.value = text;
document.body.appendChild(elem);
elem.select();
document.execCommand('copy');
document.body.removeChild(elem);
}
function findValueByKey(searchKey) {
for (const [key, value] of Object.entries(dictionary))
if (value.toLowerCase() == searchKey.toLowerCase())
if (searchKey.charAt(0) == searchKey.charAt(0).toUpperCase())
return key;
else
return key.charAt(0).toLowerCase() + key.substr(1);
const baseStringStart = "N";
const baseStringEnds = ["eh", "h", "h", "gh", "h", "h"];
let middleOfString = '';
const charArr = searchKey.split('');
for (let v = 0; v < charArr.length; v++) {
const element = charArr[v];
if (v != 0 && v != charArr.length - 1)
for (const [key, value] of Object.entries(letterDic)) {
if (key.toLowerCase() == charArr[v].toLowerCase())
middleOfString += value;
}
}
return baseStringStart + middleOfString + baseStringEnds[Math.floor(Math.random() * baseStringEnds.length)];
}
function getPrefix(z, words) {
if (z == 0) return ''; // No previous char
if (words[z - 1] == ' ') // Previous char is space
return '';
return ' '; // Space since last char is part of word
}
function filterPunctuation(string) {
let newString;
let punc2;
const punc = [
'.',
',',
'?',
'!',
';',
];
punc.forEach(element => {
if (string.includes(element)) {
newString = string.replace(element, '');
punc2 = element;
}
});
if (!punc2) {
newString = string;
punc2 = "";
}
return [newString, punc2];
}
</script>
</html>