summaryrefslogtreecommitdiff
path: root/pages/prefix.inc
blob: d7d8a401719394d02b563b20f8fa778cbed373bf (plain)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn;
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';

?>

<br>
<div class="container">
    <div id="page-content">
        <h2>Prefix generator</h2>
        <p>This prefix generator will take into account the prefixes from the existing members to try to generate new original prefixes for a potential new member.</p>

        <div style="display:grid;grid-template-columns:1fr 1fr 1fr;grid-gap:10px;">
            <select id="system" title="Existing prefixes from..." class="tooltip-nohelp form-select" style='color:white;background-color:#111;border-color:#222;background-image:url("data:image/svg+xml,%3csvg xmlns=&apos;http://www.w3.org/2000/svg&apos; viewBox=&apos;0 0 16 16&apos;%3e%3cpath fill=&apos;none&apos; stroke=&apos;%23ffffff&apos; stroke-linecap=&apos;round&apos; stroke-linejoin=&apos;round&apos; stroke-width=&apos;2&apos; d=&apos;M2 5l6 6 6-6&apos;/%3e%3c/svg%3e");' onchange="update();">
                <optgroup label="General Options">
                    <option value="all">All systems</option>
                    <option value="none">Ignore existing prefixes</option>
                </optgroup>
                <optgroup label="Individual Systems">
                    <option value="cloudburst">Cloudburst System</option>
                    <option value="raindrops">Raindrops System</option>
                </optgroup>
            </select>
            <input title="First Name" type="text" class="tooltip-nohelp form-control" id="first-name" placeholder="First Name" style="color:white;background:#111;border-color:#222;" onchange="update();" onkeydown="update();" onkeyup="update();">
            <input title="Last Name" type="text" class="tooltip-nohelp form-control" id="last-name" placeholder="Last Name (optional)" style="color:white;background:#111;border-color:#222;" onchange="update();" onkeydown="update();" onkeyup="update();">
        </div>

        <br>
        <div id="already" class="alert alert-primary" style="display:none;">
            There is already a member named <b id="already-name">Name</b> in one of the systems, their primary prefix is currently <code id="already-prefix">???</code>
        </div>
        <div id="results-singular" style="display:none;">
            <h4>Generated Prefix</h4>
            <p>Below is a generated prefix for a member who goes by the entered name. We managed to generate only a single prefix for this name.</p>
        </div>
        <div id="results-none">
            <h4>Generated Prefix</h4>
            <p>We couldn't generate a prefix for a member who goes by this name, try tuning your settings.</p>
        </div>
        <div id="results-plural" style="display:none;">
            <h4>Generated Prefixes</h4>
            <p>Below is a list of generated prefixes for a member who goes by the entered name. The prefixes are ordered by relevance, the first prefix being the most relevant one. Hover over a prefix to see what makes it revelent or not</p>
        </div>
        <ol id="generated">
            <li><code>{...}</code></li>
        </ol>
        <p id="hidden-message" style="display:none;"><span id="hidden-count">0</span> <span id="hidden-plural">entries have been hidden because they are existing prefixes </span><span id="hidden-singular">entry has been hidden because it is an existing prefix </span>in the selected system<span id="hidden-sys-plural">s</span>.</p>
    </div>

    <script>
        let existing = <?php

            $existing1 = [];
            foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true) as $member) {
                if ($member["name"] !== "unknown") {
                    foreach ($member['proxy_tags'] as $tag) {
                        if (!$tag["prefix"]) {
                            $existing1[] = "..." . $tag["suffix"];
                        } else if (!$tag["suffix"]) {
                            $existing1[] = $tag["prefix"];
                        } else {
                            $existing1[] = $tag["prefix"] . "..." . $tag["suffix"];
                        }
                    }
                }
            }


            $existing2 = [];
            foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true) as $member) {
                if ($member["name"] !== "unknown") {
                    foreach ($member['proxy_tags'] as $tag) {
                        if (!$tag["prefix"]) {
                            $existing2[] = "..." . $tag["suffix"];
                        } else if (!$tag["suffix"]) {
                            $existing2[] = $tag["prefix"];
                        } else {
                            $existing2[] = $tag["prefix"] . "..." . $tag["suffix"];
                        }
                    }
                }
            }

            echo(json_encode([
                "cloudburst" => $existing1,
                "raindrops" => $existing2
            ]));

            ?>;

        let prefixesUsedBy = <?php

            $existing1 = [];
            foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true) as $member) {
                if ($member["name"] !== "unknown") {
                    foreach ($member['proxy_tags'] as $tag) {
                        if (!$tag["prefix"]) {
                            $existing1["..." . $tag["suffix"]] = $member["display_name"] ?? $member["name"];
                        } else if (!$tag["suffix"]) {
                            $existing1[$tag["prefix"]] = $member["display_name"] ?? $member["name"];
                        } else {
                            $existing1[$tag["prefix"] . "..." . $tag["suffix"]] = $member["display_name"] ?? $member["name"];
                        }
                    }
                }
            }


            $existing2 = [];
            foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true) as $member) {
                if ($member["name"] !== "unknown") {
                    foreach ($member['proxy_tags'] as $tag) {
                        if (!$tag["prefix"]) {
                            $existing2["..." . $tag["suffix"]] = $member["display_name"] ?? $member["name"];
                        } else if (!$tag["suffix"]) {
                            $existing2[$tag["prefix"]] = $member["display_name"] ?? $member["name"];
                        } else {
                            $existing2[$tag["prefix"] . "..." . $tag["suffix"]] = $member["display_name"] ?? $member["name"];
                        }
                    }
                }
            }

            echo(json_encode([
                "cloudburst" => $existing1,
                "raindrops" => $existing2
            ]));

            ?>;

        let o;
        let membersByPrefixCloudburst = {};
        let membersByPrefixRaindrops = {};

        o = prefixesUsedBy["cloudburst"];
        Object.keys(o).map((i) => { if (!membersByPrefixCloudburst[o[i]]) membersByPrefixCloudburst[o[i]] = []; membersByPrefixCloudburst[o[i]].push(i); });

        o = prefixesUsedBy["raindrops"];
        Object.keys(o).map((i) => { if (!membersByPrefixRaindrops[o[i]]) membersByPrefixRaindrops[o[i]] = []; membersByPrefixRaindrops[o[i]].push(i); });

        function update() {
            let generated = [];
            let toIgnore = [];

            let system = document.getElementById("system").value;
            let firstName = document.getElementById("first-name").value.toLowerCase().trim().replace(/[^a-z]/gm, "");
            let lastName = document.getElementById("last-name").value.toLowerCase().trim().replace(/[^a-z]/gm, "");

            document.getElementById("already").style.display = "none";
            if (Object.keys(membersByPrefixRaindrops).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).includes((firstName + " " + lastName).trim())) {
                let data = {
                    name: Object.keys(membersByPrefixRaindrops)[Object.keys(membersByPrefixRaindrops).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).indexOf((firstName + " " + lastName).trim())],
                    prefix: membersByPrefixRaindrops[Object.keys(membersByPrefixRaindrops)[Object.keys(membersByPrefixRaindrops).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).indexOf((firstName + " " + lastName).trim())]][0]
                };
                console.log(data);

                document.getElementById("already-name").innerText = data.name;
                document.getElementById("already-prefix").innerText = data.prefix;
                document.getElementById("already").style.display = "";
            }
            if (Object.keys(membersByPrefixCloudburst).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).includes((firstName + " " + lastName).trim())) {
                let data = {
                    name: Object.keys(membersByPrefixCloudburst)[Object.keys(membersByPrefixCloudburst).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).indexOf((firstName + " " + lastName).trim())],
                    prefix: membersByPrefixCloudburst[Object.keys(membersByPrefixCloudburst)[Object.keys(membersByPrefixCloudburst).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).indexOf((firstName + " " + lastName).trim())]][0]
                };
                console.log(data);

                document.getElementById("already-name").innerText = data.name;
                document.getElementById("already-prefix").innerText = data.prefix;
                document.getElementById("already").style.display = "";
            }

            switch (system) {
                case "all":
                    toIgnore = [...existing["cloudburst"], ...existing["raindrops"]];
                    document.getElementById("hidden-sys-plural").style.display = "";
                    break;

                case "raindrops":
                    toIgnore = existing["raindrops"];
                    document.getElementById("hidden-sys-plural").style.display = "none";
                    break;

                case "cloudburst":
                    toIgnore = existing["cloudburst"];
                    document.getElementById("hidden-sys-plural").style.display = "none";
                    break;

                case "none":
                    toIgnore = [];
                    document.getElementById("hidden-sys-plural").style.display = "";
                    break;
            }

            if (firstName.length > 0) {
                generated.push({
                    prefix: firstName.substring(0, 1) + ".",
                    rules: ["<span class='text-warning'>firstNameFirstLetter</span>"]
                });
            }

            if (lastName.length > 0) {
                generated.push({
                    prefix: lastName.substring(0, 1) + ".",
                    rules: ["<span class='text-warning'>lastNameFirstLetter</span>"]
                });
            }

            if (firstName.length > 1) {
                generated.push({
                    prefix: firstName.substring(0, 2) + ".",
                    rules: ["<span class='text-warning'>firstNameFirstTwoLetters</span>"]
                });
            }

            if (firstName.length > 0 && lastName.length > 0) {
                generated.push({
                    prefix: firstName.substring(0, 1) + lastName.substring(0, 1) + ".",
                    rules: ["<span class='text-warning'>lastNameFirstTwoLetters</span>"]
                });
            }

            if (firstName.length > 1) {
                for (let i = 2; i < firstName.length + 1; i++) {
                    if (!(
                        firstName.substring(i - 1, i) === "a" ||
                        firstName.substring(i - 1, i) === "e" ||
                        firstName.substring(i - 1, i) === "i" ||
                        firstName.substring(i - 1, i) === "o" ||
                        firstName.substring(i - 1, i) === "u" ||
                        firstName.substring(i - 1, i) === "y"
                    )) {
                        generated.push({
                            prefix: firstName.substring(i - 1, i) + ".",
                            rules: ["<span class='text-warning'>firstNameLetterConsonant</span>"]
                        });
                    }
                }
            }

            if (lastName.length > 1) {
                for (let i = 2; i < lastName.length + 1; i++) {
                    if (!(
                        lastName.substring(i - 1, i) === "a" ||
                        lastName.substring(i - 1, i) === "e" ||
                        lastName.substring(i - 1, i) === "i" ||
                        lastName.substring(i - 1, i) === "o" ||
                        lastName.substring(i - 1, i) === "u" ||
                        lastName.substring(i - 1, i) === "y"
                    )) {
                        generated.push({
                            prefix: lastName.substring(i - 1, i) + ".",
                            rules: ["<span class='text-warning'>lastNameLetterConsonant</span>"]
                        });
                    }
                }
            }

            if (firstName.length > 1) {
                for (let i = 2; i < firstName.length + 1; i++) {
                    if (
                        firstName.substring(i - 1, i) === "a" ||
                        firstName.substring(i - 1, i) === "e" ||
                        firstName.substring(i - 1, i) === "i" ||
                        firstName.substring(i - 1, i) === "o" ||
                        firstName.substring(i - 1, i) === "u" ||
                        firstName.substring(i - 1, i) === "y"
                    ) {
                        generated.push({
                            prefix: firstName.substring(i - 1, i) + ".",
                            rules: ["<span class='text-warning'>firstNameLetterVowel</span>"]
                        });
                    }
                }
            }

            if (lastName.length > 1) {
                for (let i = 2; i < lastName.length; i++) {
                    if (
                        lastName.substring(i - 1, i) === "a" ||
                        lastName.substring(i - 1, i) === "e" ||
                        lastName.substring(i - 1, i) === "i" ||
                        lastName.substring(i - 1, i) === "o" ||
                        lastName.substring(i - 1, i) === "u" ||
                        lastName.substring(i - 1, i) === "y"
                    ) {
                        generated.push({
                            prefix: lastName.substring(i - 1, i + 1) + ".",
                            rules: ["<span class='text-warning'>lastNameTwoLettersVowel</span>"]
                        });
                    }
                }
            }

            if (firstName.length > 2) {
                for (let i = 2; i < firstName.length; i++) {
                    if (!(
                        firstName.substring(i - 1, i) === "a" ||
                        firstName.substring(i - 1, i) === "e" ||
                        firstName.substring(i - 1, i) === "i" ||
                        firstName.substring(i - 1, i) === "o" ||
                        firstName.substring(i - 1, i) === "u" ||
                        firstName.substring(i - 1, i) === "y"
                    )) {
                        generated.push({
                            prefix: firstName.substring(i - 1, i + 1) + ".",
                            rules: ["<span class='text-warning'>firstNameTwoLettersConsonant</span>"]
                        });
                    }
                }
            }

            if (lastName.length > 2) {
                for (let i = 2; i < lastName.length; i++) {
                    if (!(
                        lastName.substring(i - 1, i) === "a" ||
                        lastName.substring(i - 1, i) === "e" ||
                        lastName.substring(i - 1, i) === "i" ||
                        lastName.substring(i - 1, i) === "o" ||
                        lastName.substring(i - 1, i) === "u" ||
                        lastName.substring(i - 1, i) === "y"
                    )) {
                        generated.push({
                            prefix: lastName.substring(i - 1, i + 1) + ".",
                            rules: ["<span class='text-warning'>lastNameTwoLettersConsonant</span>"]
                        });
                    }
                }
            }

            if (firstName.length > 2) {
                for (let i = 2; i < firstName.length; i++) {
                    if (
                        firstName.substring(i - 1, i) === "a" ||
                        firstName.substring(i - 1, i) === "e" ||
                        firstName.substring(i - 1, i) === "i" ||
                        firstName.substring(i - 1, i) === "o" ||
                        firstName.substring(i - 1, i) === "u" ||
                        firstName.substring(i - 1, i) === "y"
                    ) {
                        generated.push({
                            prefix: firstName.substring(i - 1, i + 1) + ".",
                            rules: ["<span class='text-warning'>firstNameTwoLettersVowel</span>"]
                        });
                    }
                }
            }

            if (lastName.length > 2) {
                for (let i = 2; i < lastName.length; i++) {
                    if (
                        lastName.substring(i - 1, i) === "a" ||
                        lastName.substring(i - 1, i) === "e" ||
                        lastName.substring(i - 1, i) === "i" ||
                        lastName.substring(i - 1, i) === "o" ||
                        lastName.substring(i - 1, i) === "u" ||
                        lastName.substring(i - 1, i) === "y"
                    ) {
                        generated.push({
                            prefix: lastName.substring(i - 1, i + 1) + ".",
                            rules: ["<span class='text-warning'>lastNameTwoLettersVowel</span>"]
                        });
                    }
                }
            }

            generated = generated.filter((c, index) => {
                return generated.map((i) => { return i.prefix; }).indexOf(c.prefix) === index;
            });

            let generatedVowels = generated.filter((i) => {
                return i.prefix.match(/[aeiouy]/);
            }).map((i) => {
                i.rules.push("<span class='text-danger'>containsVowels</span>");
                return i;
            });

            let generatedNotVowels = generated.filter((i) => {
                return !i.prefix.match(/[aeiouy]/);
            }).map((i) => {
                i.rules.push("<span class='text-success'>notContainsVowels</span>");
                return i;
            });

            generated = [...generatedNotVowels, ... generatedVowels];

            generated.sort((a, b) => {
                return a.prefix.length - b.prefix.length;
            });

            let totalLength = generated.length;
            generated = generated.filter((i) => {
                return !toIgnore.includes(i.prefix);
            });
            let lengthAfterIgnore = generated.length;
            let ignoredCount = totalLength - lengthAfterIgnore;

            document.getElementById("hidden-count").innerText = ignoredCount.toString();
            document.getElementById("hidden-plural").style.display = ignoredCount === 1 ? "none" : "inline";
            document.getElementById("hidden-singular").style.display = ignoredCount === 1 ? "inline" : "none";
            document.getElementById("hidden-message").style.display = ignoredCount === 0 ? "none" : "";

            document.getElementById("results-none").style.display = "none";
            document.getElementById("results-singular").style.display = "none";
            document.getElementById("results-plural").style.display = "none";

            if (generated.length === 0) {
                document.getElementById("generated").innerHTML = "<li><code>{...}</code></li>";
                document.getElementById("results-none").style.display = "";
            } else {
                let html = [];
                let index = 1;

                for (let prefix of generated) {
                    if (prefix.prefix === "n." || prefix.prefix === "g.") continue;

                    html.push(`<li><code data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="right" title="<b>Prefix:</b> <code>${prefix.prefix}</code><br><b>Score:</b> ${((1 - (index/generated.length))*100).toFixed(2)}%<hr><div class='text-peh-nowrap'>- ${prefix.rules.join("</div><div class='text-peh-nowrap'>- ")}</div><hr><div class='text-peh-nowrap'>- <span class='text-${existing["cloudburst"].includes(prefix.prefix) ? "danger" : "success"}'>Cloudburst</span> ${existing["cloudburst"].includes(prefix.prefix) ? ` (${prefixesUsedBy["cloudburst"][prefix.prefix]})` : ""}</div><div class='text-peh-nowrap'>- <span class='text-${existing["raindrops"].includes(prefix.prefix) ? "danger" : "success"}'>Raindrops</span> ${existing["raindrops"].includes(prefix.prefix) ? ` (${prefixesUsedBy["raindrops"][prefix.prefix]})` : ""}">${prefix.prefix}</code></li>`);

                    index++;
                }

                document.getElementById("generated").innerHTML = html.join("");

                document.getElementById(generated.length > 1 ? "results-plural" : "results-singular").style.display = "";
            }

            let tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
            let tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
                return new bootstrap.Tooltip(tooltipTriggerEl)
            });

            Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')).forEach((item) => {
                item.style.cursor = "help";
            })
        }
    </script>
    <style>
        .tooltip-inner {
            text-align: left !important;
        }

        .text-peh-nowrap {
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
        }
    </style>
</div>

<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.inc'; ?>