-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkim-convo-locator.php
250 lines (239 loc) · 8.72 KB
/
kim-convo-locator.php
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
<!DOCTYPE html>
<html>
<head>
<title>KIM Convo Locator | browse.wf</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="icon" href="https://browse.wf/Lotus/Interface/Icons/Categories/GrimoireModIcon.png">
</head>
<body data-bs-theme="dark">
<?php require "components/navbar.php"; ?>
<div class="container pt-3">
<div id="loading">
<p>Loading, please wait...</p>
</div>
<div id="content" class="d-none">
<input id="query" type="text" class="form-control mb-2" placeholder="Enter (part of) a message you want to locate..." />
<div id="results"></div>
</div>
</div>
</body>
<?php require "components/commonjs.html"; ?>
<script>
if (location.host == "kim.browse.wf" && location.pathname == "/convo-locator.html")
{
location.pathname = "/convo-locator";
}
const chatroom_to_username = {
"ArthurDialogue_rom.dialogue": "Broadsword",
"EleanorDialogue_rom.dialogue": "Salem",
"LettieDialogue_rom.dialogue": "Belladona ~{@",
"JabirDialogue_rom.dialogue": "H16h V0l7463",
"AoiDialogue_rom.dialogue": "xX GLIMMER Xx",
"QuincyDialogue_rom.dialogue": "Soldja1Shot1kil",
"HexDialogue_rom.dialogue": "The Hex",
};
Promise.all([
fetch("https://kim.browse.wf/dicts/en.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/de.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/es.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/fr.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/it.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/ja.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/ko.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/pl.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/pt.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/ru.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/tc.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/th.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/tr.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/uk.json").then(res => res.json()),
fetch("https://kim.browse.wf/dicts/zh.json").then(res => res.json()),
fetch("https://kim.browse.wf/ArthurDialogue_rom.dialogue.json").then(res => res.json()),
fetch("https://kim.browse.wf/EleanorDialogue_rom.dialogue.json").then(res => res.json()),
fetch("https://kim.browse.wf/LettieDialogue_rom.dialogue.json").then(res => res.json()),
fetch("https://kim.browse.wf/JabirDialogue_rom.dialogue.json").then(res => res.json()),
fetch("https://kim.browse.wf/AoiDialogue_rom.dialogue.json").then(res => res.json()),
fetch("https://kim.browse.wf/QuincyDialogue_rom.dialogue.json").then(res => res.json()),
fetch("https://kim.browse.wf/HexDialogue_rom.dialogue.json").then(res => res.json())
]).then(([
dict_en, dict_de, dict_es, dict_fr, dict_it, dict_ja, dict_ko, dict_pl, dict_pt, dict_ru, dict_tc, dict_th, dict_tr, dict_uk, dict_zh,
ArthurDialogue_rom, EleanorDialogue_rom, LettieDialogue_rom, JabirDialogue_rom, AoiDialogue_rom, QuincyDialogue_rom, HexDialogue_rom
]) => {
window.dicts = {
en: dict_en,
de: dict_de,
es: dict_es,
fr: dict_fr,
it: dict_it,
ja: dict_ja,
ko: dict_ko,
pl: dict_pl,
pt: dict_pt,
ru: dict_ru,
tc: dict_tc,
th: dict_th,
tr: dict_tr,
uk: dict_uk,
zh: dict_zh,
};
window.chatrooms = {
"ArthurDialogue_rom.dialogue": { nodes: ArthurDialogue_rom, convos: {} },
"EleanorDialogue_rom.dialogue": { nodes: EleanorDialogue_rom, convos: {} },
"LettieDialogue_rom.dialogue": { nodes: LettieDialogue_rom, convos: {} },
"JabirDialogue_rom.dialogue": { nodes: JabirDialogue_rom, convos: {} },
"AoiDialogue_rom.dialogue": { nodes: AoiDialogue_rom, convos: {} },
"QuincyDialogue_rom.dialogue": { nodes: QuincyDialogue_rom, convos: {} },
"HexDialogue_rom.dialogue": { nodes: HexDialogue_rom, convos: {} },
};
for (const [chatroom_name, chatroom] of Object.entries(chatrooms))
{
for (const node of chatroom.nodes)
{
if (node.type == "/EE/Types/Engine/StartDialogueNode")
{
const convo = node.name;
//convo_to_chatroom[convo] = chatroom_name;
const pending = [ node.id ];
const done = [];
while (pending.length != 0)
{
const node_id = pending.pop();
if (done.find(x => x == node_id))
{
continue;
}
done.push(node_id);
const n = chatroom.nodes[node_id];
if (n.true_choices)
{
for (const choice of n.true_choices)
{
pending.push(choice);
}
for (const choice of n.false_choices)
{
pending.push(choice);
}
}
else
{
for (const choice of n.choices)
{
pending.push(choice);
}
}
}
chatroom.convos[convo] = done;
}
}
}
const params = new URLSearchParams(location.hash.toString().replace("#", ""));
if (params.has("q"))
{
document.getElementById("query").value = params.get("q");
doLocate();
}
document.getElementById("loading").classList.add("d-none");
document.getElementById("content").classList.remove("d-none");
});
function node_id_to_convo(chatroom, node_id)
{
for (const [convo, convo_node_ids] of Object.entries(chatroom.convos))
{
for (const convo_node_id of convo_node_ids)
{
if (convo_node_id == node_id)
{
return convo;
}
}
}
console.error("node_id_to_convo failed", chatroom, node_id);
}
function normaliseText(text)
{
return text.toLowerCase().split("‘").join("'").split("’").join("'");
}
function doLocate()
{
const lang = localStorage.getItem("lang") || "en";
const query = normaliseText(document.getElementById("query").value);
if (query.length >= 3)
{
location.hash = "q=" + encodeURIComponent(query);
document.getElementById("results").innerHTML = "";
const results_set = {};
for (const [chatroom_name, chatroom] of Object.entries(chatrooms))
{
for (const node of chatroom.nodes)
{
if (node.type == "/EE/Types/Engine/DialogueNode" || node.type == "/EE/Types/Engine/PlayerChoiceDialogueNode")
{
let text = dicts[lang][node.name] ?? node.name;
if (node.vars)
{
for (const [k, v] of Object.entries(node.vars))
{
text = text.split("|"+k+"|").join(dicts[lang][v] ?? v);
}
}
text = text.split("<RETRO_EMOJI_HEART>").join("<3");
if (normaliseText(text).indexOf(query) != -1)
{
const convo = node_id_to_convo(chatroom, node.id);
let sender_name = "Drifter";
if (node.type == "/EE/Types/Engine/DialogueNode")
{
sender_name = chatroom_to_username[chatroom_name];
if (node.nickname_override)
{
sender_name = node.nickname_override;
if (dicts[lang][sender_name])
{
sender_name = dicts[lang][sender_name];
}
}
}
const slug = convo + "+++" + sender_name + "+++" + text;
if (slug in results_set)
{
continue;
}
results_set[slug] = true;
const p = document.createElement("p");
p.className = "mb-1";
p.textContent = sender_name + ": " + text + " (" + convo + " • ";
{
const a = document.createElement("a");
a.href = "https://kim.browse.wf/flowcharts_svg/" + lang + "/" + chatroom_name + "/" + convo + ".svg";
a.target = "_blank";
a.textContent = "Flowchart";
p.appendChild(a);
}
p.innerHTML += " • ";
{
const a = document.createElement("a");
a.href = "kimulacrum#chatroom=" + chatroom_name + "&dialogue=" + convo;
a.target = "_blank";
a.textContent = "Kimulacrum";
p.appendChild(a);
}
p.innerHTML += ")";
document.getElementById("results").appendChild(p);
}
}
}
}
}
else
{
location.hash = "";
document.getElementById("results").innerHTML = "<p>Please enter at least 3 characters.</p>";
}
}
onLanguageUpdate = doLocate;
document.getElementById("query").oninput = doLocate;
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</html>