-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
329 lines (287 loc) · 8.81 KB
/
index.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
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
<!DOCTYPE html>
<html lang="he">
<head>
<title>מידע על פקודות בוט WhatsApp - Information about the bot commands</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #F6F8FA;
display: flex;
}
h1 {
color: #333;
text-align: center;
}
h2 {
color: #555;
margin-top: 20px;
}
pre {
background-color: #EAEAEA;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
.notes {
color: #555;
font-size: 14px;
}
.parameters {
color: #555;
font-size: 14px;
}
.command {
margin-bottom: 30px;
background-color: #FFFFFF;
border-radius: 4px;
padding: 20px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}
.command h2 {
color: #007BFF;
font-size: 24px;
margin-bottom: 10px;
}
.command p {
color: #333;
font-size: 16px;
}
.command h3 {
color: #555;
margin-top: 15px;
}
.command pre {
background-color: #F0F0F0;
font-size: 14px;
}
.command ul {
margin-top: 10px;
}
.command li {
font-size: 14px;
}
.index {
background-color: #FFFFFF;
border-radius: 4px;
padding: 20px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
min-width: 200px;
margin-right: 20px;
}
.index ul {
margin: 0;
padding: 0;
}
.index li {
margin-bottom: 10px;
list-style-type: none;
}
.index a {
color: #007BFF;
text-decoration: none;
font-weight: bold;
}
.index a:hover {
text-decoration: underline;
}
.content {
margin-right: 20px;
}
</style>
</head>
<body>
<div class="index">
<h2 id="commandMenuTitle">פקודות:</h2>
<ul id="commandsHerfs">
</ul>
</div>
<div class="content">
<select id="lang" onchange="changeLang()">
<option value="iw" selected>עברית</option>
<option value="en">English</option>
</select>
<h1 id="pageTitle">BabiBot - פקודות</h1>
<div >
<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js"
data-name="bmc-button" data-slug="BabiBot" data-color="#FFDD00" data-emoji="☕" data-font="Bree"
data-text="Buy me a coffee" data-outline-color="#000000" data-font-color="#000000"
data-coffee-color="#ffffff"></script>
</div>
<div class="privacy" id="privacyNote">
<h2>פרטיות</h2>
<p>שימו לב! למפתח של BabiBot קיימת גישה להודעות שתשלחו לבוט, ההודעות נבדקות מפעם לפעם על מנת לשפר ולתקן את הבוט.
</p>
</div>
<div id="commands"></div>
</div>
</body>
<script type="module">
import { AllCommands, keyNotes } from "./commands.js";
/**
*
* @param {AllCommands[lang][index]} command
* @param {string} lang
* @returns {HTMLDivElement}
*/
function generateCommandDiv(command, lang) {
let div = document.createElement("div");
div.classList.add("command");
div.id = "command-" + command.name.replace("!", "");
let h2 = document.createElement("h2");
h2.innerText = command.name;
div.appendChild(h2);
let p = document.createElement("p");
p.innerText = command.description;
div.appendChild(p);
let h3 = document.createElement("h3");
h3.innerText = keyNotes[lang].usage;
div.appendChild(h3);
let pre = document.createElement("pre");
pre.innerText = command.usage;
div.appendChild(pre);
if (command.parameters) {
h3 = document.createElement("h3");
h3.innerText = keyNotes[lang].parameters;
div.appendChild(h3);
let ul = document.createElement("ul");
ul.classList.add("parameters");
command.parameters.forEach(parameter => {
let li = document.createElement("li");
li.innerHTML = "<strong>" + parameter.name + ":</strong> " + parameter.description;
ul.appendChild(li);
});
div.appendChild(ul);
}
h3 = document.createElement("h3");
h3.innerText = keyNotes[lang].examples;
div.appendChild(h3);
command.examples.forEach(example => {
pre = document.createElement("pre");
pre.innerText = example;
div.appendChild(pre);
}
);
h3 = document.createElement("h3");
h3.innerText = keyNotes[lang].response;
div.appendChild(h3);
p = document.createElement("p");
p.innerText = command.response;
div.appendChild(p);
if (command.notes) {
h3 = document.createElement("h3");
h3.innerText = keyNotes[lang].notes;
div.appendChild(h3);
let ul = document.createElement("ul");
ul.classList.add("notes");
command.notes.forEach(note => {
let li = document.createElement("li");
li.innerText = " ● " + note;
ul.appendChild(li);
});
div.appendChild(ul);
}
return div;
}
/**
* only for testing
* @param {HTMLDivElement} div
*/
function fromDivTolist(div) {
let list = [];
let commands = div.querySelectorAll(".command");
console.log(commands);
commands.forEach(command => {
let name = command.querySelector("h2").innerText;
let description = command.querySelector("p").innerText;
let usage = command.querySelector("pre").innerText;
let parameters = [];
let parametersList = command.querySelectorAll("ul li");
parametersList.forEach(parameter => {
let name = parameter.querySelector("strong")?.innerText;
let description = parameter.innerText.replace(name + ": ", "");
parameters.push({
"name": name,
"description": description
});
});
let examples = [];
let examplesList = command.querySelectorAll("h3 + pre");
examplesList.forEach(example => {
examples.push(example.innerText);
});
let response = command.querySelector("h3 + p").innerText;
let notes = [];
let notesList = command.querySelectorAll("h3 + ul li");
notesList.forEach(note => {
notes.push(note.innerText);
});
list.push({
"name": name,
"description": description,
"usage": usage,
"parameters": parameters,
"examples": examples,
"response": response,
"notes": notes
});
});
return list;
}
function generateCommands() {
let div = document.getElementById("commands");
console.log(div);
let list = fromDivTolist(div);
div.innerHTML = "";
console.log(JSON.stringify(list, null, 2));
for (let i = 0; i < list.length; i++) {
let newDiv = generateCommandDiv(list[i], "iw");
console.log(newDiv);
document.getElementById("commands").appendChild(newDiv);
}
}
// generateCommands();
function reloadPageWithLang(lang) {
document.getElementById("commands").innerHTML = "";
document.getElementById("commandsHerfs").innerHTML = "";
for (let i = 0; i < AllCommands[lang].length; i++) {
let newDiv = generateCommandDiv(AllCommands[lang][i], lang);
document.getElementById("commands").appendChild(newDiv);
document.getElementById("commandsHerfs").innerHTML += "<li><a href='#command-" + AllCommands[lang][i].name.replace("!", "") + "'>" + AllCommands[lang][i].name + "</a></li>";
}
}
function changeLang() {
// get selected lang
let lang = document.getElementById("lang").value;
console.log("lang set to: " + lang); // "iw" or "en
// reload page with the selected lang
reloadPageWithLang(lang);
// change the layout direction
if (lang == "iw") {
window.document.dir = "rtl";
document.getElementById("commandMenuTitle").innerHTML = "פקודות:";
document.getElementById("pageTitle").innerHTML = "BabiBot - פקודות"
document.getElementById("privacyNote").innerHTML = `<h2>פרטיות</h2>
<p>שימו לב! למפתח של BabiBot קיימת גישה להודעות שתשלחו לבוט, ההודעות נבדקות מפעם לפעם על מנת לשפר ולתקן את הבוט.</p>`
}
else {
window.document.dir = "ltr";
document.getElementById("commandMenuTitle").innerHTML = "Commands:";
document.getElementById("pageTitle").innerHTML = "BabiBot - Commands"
document.getElementById("privacyNote").innerHTML = `<h2>Privacy</h2>
<p>Attention! The developer of BabiBot has access to the messages you send to the bot. The messages are periodically reviewed in order to improve and correct the bot.</p>`
}
}
// onload set the lang to the default lang
changeLang();
// save the function in the window object so it can be called from the html
window.changeLang = changeLang;
</script>
</html>