︙ | | |
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
|
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
|
-
-
+
+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
+
-
-
-
+
|
}
function showError (e) {
console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}
document.getElementById("lexicon_button").addEventListener("click", () => { oPage.showPage("lexicon"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oPage.showPage("lemma"); }, false);
document.getElementById("lexicon_button").addEventListener("click", () => { oWidgets.showPage("lexicon"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oWidgets.showPage("lemma"); }, false);
document.getElementById("table").addEventListener("click", (xEvent) => { oPage.onTableClick(xEvent); }, false);
document.getElementById("table").addEventListener("click", (xEvent) => { oWidgets.onTableClick(xEvent); }, false);
document.getElementById("save_button").addEventListener("click", () => { oLexicon.save(); }, false);
document.getElementById("editor").addEventListener("click", (xEvent) => { oPage.onSelectionClick(xEvent); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oPage.onWrite(); }, false);
document.getElementById("lemma2").addEventListener("keyup", () => { oPage.onWrite2(); }, false);
document.getElementById("verb_pattern").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("flexion").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("add_to_lexicon").addEventListener("click", () => { oFlex.addToLexicon(); }, false);
document.getElementById("editor").addEventListener("click", (xEvent) => { oWidgets.onSelectionClick(xEvent); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oWidgets.onWrite(); }, false);
document.getElementById("lemma2").addEventListener("keyup", () => { oWidgets.onWrite2(); }, false);
document.getElementById("verb_pattern").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("flexion").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("add_to_lexicon").addEventListener("click", () => { oFlexGen.addToLexicon(); }, false);
/*
ACTIONS
*/
const oPage = {
const oWidgets = {
showPage: function (sPage) {
if (sPage == "lexicon") {
document.getElementById("add_word_page").style.display = "none";
document.getElementById("lexicon_page").style.display = "block";
this.hideElement("add_word_page");
this.showElement("lexicon_page");
document.getElementById("lexicon_button").style.backgroundColor = "hsl(210, 80%, 90%)";
document.getElementById("add_word_button").style.backgroundColor = "hsl(210, 10%, 95%)";
} else {
document.getElementById("lexicon_page").style.display = "none";
document.getElementById("add_word_page").style.display = "block";
this.hideElement("lexicon_page");
this.showElement("add_word_page");
document.getElementById("lexicon_button").style.backgroundColor = "hsl(210, 10%, 95%)";
document.getElementById("add_word_button").style.backgroundColor = "hsl(210, 80%, 90%)";
}
},
showEditor: function () {
document.getElementById("editor").style.display = "block";
showElement: function (sElemId) {
if (document.getElementById(sElemId)) {
document.getElementById(sElemId).style.display = "block";
} else {
console.log("HTML node named <" + sElemId + "> not found.")
}
},
hideEditor: function () {
document.getElementById("editor").style.display = "none";
hideElement: function (sElemId) {
if (document.getElementById(sElemId)) {
document.getElementById(sElemId).style.display = "none";
} else {
console.log("HTML node named <" + sElemId + "> not found.")
}
},
hideAllSections: function () {
for (let xElem of document.getElementById("sections").childNodes) {
if (xElem.id) {
xElem.style.display = "none";
}
}
},
showSection: function (sName) {
this.clear();
this.hideAllSections();
if (document.getElementById(sName)) {
this.showElement(sName);
document.getElementById(sName).style.display = "block";
}
},
clear: function () {
try {
document.getElementById("lemma2").value = "";
this.hideWord2();
this.hideElement("word_section2");
// nom, adjectif, noms propres
for (let xElem of document.getElementsByName("POS")) {
xElem.checked = false;
}
for (let xElem of document.getElementsByName("POS2")) {
xElem.checked = false;
}
|
︙ | | |
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
|
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
|
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
onSelectionClick: function (xEvent) {
try {
let xElem = xEvent.target;
if (xElem.id) {
if (xElem.id.startsWith("select_")) {
this.showSection("section_" + xElem.id.slice(7));
oFlex.setMainTag(xElem.dataset.tag);
oFlex.update();
oFlexGen.setMainTag(xElem.dataset.tag);
oFlexGen.update();
} else if (xElem.id.startsWith("up_")) {
oFlex.update();
oFlexGen.update();
}
}
}
catch (e) {
showError(e);
}
},
onWrite: function () {
if (document.getElementById("lemma").value.trim() !== "") {
this.showEditor();
oFlex.update();
this.showElement("editor");
oFlexGen.update();
} else {
this.showSection("section_vide");
this.hideEditor();
this.hideActions();
this.hideElement("editor");
this.hideElement("actions");
}
},
onWrite2: function () {
if (document.getElementById("lemma2").value.trim() !== "") {
this.showWord2();
oFlex.update();
this.showElement("word_section2");
oFlexGen.update();
} else {
this.hideWord2();
this.hideElement("word_section2");
}
},
showWord2: function () {
document.getElementById("word_section2").style.display = "block";
},
hideWord2: function () {
document.getElementById("word_section2").style.display = "none";
},
showActions: function () {
document.getElementById("actions").style.display = "block";
},
hideActions: function () {
document.getElementById("actions").style.display = "none";
},
showSaveButton: function () {
document.getElementById("save_button").style.display = "block";
},
hideSaveButton: function () {
document.getElementById("save_button").style.display = "none";
},
createTableHeader: function () {
let xRowNode = createNode("tr");
xRowNode.appendChild(createNode("th", { textContent: "·" }));
xRowNode.appendChild(createNode("th", { textContent: "#" }));
xRowNode.appendChild(createNode("th", { textContent: "Forme fléchie" }));
|
︙ | | |
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
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
+
|
xRowNode.appendChild(createNode("td", { textContent: "×", className: "delete_entry", title: "Effacer cette entrée" }, { id_entry: n }));
xRowNode.appendChild(createNode("td", { textContent: n }));
xRowNode.appendChild(createNode("td", { textContent: sFlexion }));
xRowNode.appendChild(createNode("td", { textContent: sLemma }));
xRowNode.appendChild(createNode("td", { textContent: sTags }));
return xRowNode;
},
displayTable: function (lFlex) {
this.clearTable();
if (lFlex.length > 0) {
let xTable = document.getElementById("table");
let n = 0;
this.hideElement("no_elem_line");
xTable.appendChild(this.createTableHeader());
for (let [sFlexion, sLemma, sTags] of lFlex) {
xTable.appendChild(this.createRowNode(n, sFlexion, sLemma, sTags));
n += 1;
}
} else {
this.showElement("no_elem_line");
}
},
addEntriesToTable: function (n, lFlex) {
let xTable = document.getElementById("table");
if (lFlex.length > 0) {
if (document.getElementById("no_elem_line").style.display !== "none") {
this.hideElement("no_elem_line");
xTable.appendChild(this.createTableHeader());
}
for (let [sFlexion, sLemma, sTags] of lFlex) {
xTable.appendChild(this.createRowNode(n, sFlexion, sLemma, sTags));
n += 1;
}
}
},
clearTable: function () {
let xTable = document.getElementById("table");
while (xTable.firstChild) {
xTable.removeChild(xTable.firstChild);
}
},
onTableClick: function (xEvent) {
try {
let xElem = xEvent.target;
if (xElem.className) {
if (xElem.className == "delete_entry") {
let iEntry = xElem.dataset.id_entry
oLexicon.lFlexion[parseInt(iEntry)] = null;
document.getElementById("row_"+iEntry).style.display = "none";
this.showSaveButton();
this.hideElement("row_"+iEntry);
this.showElement("save_button");
}
}
}
catch (e) {
showError(e);
}
}
}
const oFlex = {
const oFlexGen = {
cMainTag: "",
lFlexion: [],
clear: function () {
this.lFlexion = [];
document.getElementById("actions").style.display = "none";
oWidgets.hideElement("actions");
},
setMainTag: function (sValue) {
this.cMainTag = sValue;
},
addFlexion: function (sFlexion, sLemma, sTag) {
|
︙ | | |
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
|
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
|
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
|
case "N":
if (!this.getRadioValue("POS") || !this.getRadioValue("genre")) {
break;
}
let sTag = this.getRadioValue("POS") + this.getRadioValue("genre");
switch (this.getRadioValue("pluriel")) {
case "s":
this.addFlexion(sLemma, sLemma, sTag+":s");
this.addFlexion(sLemma+"s", sLemma, sTag+":p");
this.addFlexion(sLemma, sLemma, sTag+":s/*");
this.addFlexion(sLemma+"s", sLemma, sTag+":p/*");
break;
case "x":
this.addFlexion(sLemma, sLemma, sTag+":s");
this.addFlexion(sLemma+"x", sLemma, sTag+":p");
this.addFlexion(sLemma, sLemma, sTag+":s/*");
this.addFlexion(sLemma+"x", sLemma, sTag+":p/*");
break;
case "i":
this.addFlexion(sLemma, sLemma, sTag+":i");
this.addFlexion(sLemma, sLemma, sTag+":i/*");
break;
}
let sLemma2 = document.getElementById("lemma2").value.trim();
if (sLemma2.length > 0 && this.getRadioValue("POS2") && this.getRadioValue("genre2")) {
let sTag2 = this.getRadioValue("POS2") + this.getRadioValue("genre2");
switch (this.getRadioValue("pluriel2")) {
case "s":
this.addFlexion(sLemma2, sLemma, sTag2+":s");
this.addFlexion(sLemma2+"s", sLemma, sTag2+":p");
this.addFlexion(sLemma2, sLemma, sTag2+":s/*");
this.addFlexion(sLemma2+"s", sLemma, sTag2+":p/*");
break;
case "x":
this.addFlexion(sLemma2, sLemma, sTag2+":s");
this.addFlexion(sLemma2+"x", sLemma, sTag2+":p");
this.addFlexion(sLemma2, sLemma, sTag2+":s/*");
this.addFlexion(sLemma2+"x", sLemma, sTag2+":p/*");
break;
case "i":
this.addFlexion(sLemma2, sLemma, sTag2+":i");
this.addFlexion(sLemma2, sLemma, sTag2+":i/*");
break;
}
}
break;
case "V": {
if (!sLemma.endsWith("er") && !sLemma.endsWith("ir") && !sLemma.endsWith("re")) {
break;
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
|
}
}
}
break;
}
case "W":
sLemma = sLemma.toLowerCase();
this.addFlexion(sLemma, sLemma, ":W");
this.addFlexion(sLemma, sLemma, ":W/*");
break;
case "M1":
sLemma = sLemma.slice(0,1).toUpperCase() + sLemma.slice(1);
sGenderTag = this.getRadioValue("genre_m1");
if (sGenderTag) {
this.addFlexion(sLemma, sLemma, ":M1"+sGenderTag+":i");
this.addFlexion(sLemma, sLemma, ":M1"+sGenderTag+":i/*");
}
break;
case "M2":
sLemma = sLemma.slice(0,1).toUpperCase() + sLemma.slice(1);
sGenderTag = this.getRadioValue("genre_m2");
if (sGenderTag) {
this.addFlexion(sLemma, sLemma, ":M2"+sGenderTag+":i");
this.addFlexion(sLemma, sLemma, ":M2"+sGenderTag+":i/*");
}
break;
case "MP":
sGenderTag = this.getRadioValue("genre_mp");
if (sGenderTag) {
this.addFlexion(sLemma, sLemma, ":MP"+sGenderTag+":i");
this.addFlexion(sLemma, sLemma, ":MP"+sGenderTag+":i/*");
}
break;
case "X":
let sFlexion = document.getElementById("flexion").value.trim();
let sTags = document.getElementById("tags").value.trim();
if (sFlexion.length > 0 && sTags.startsWith(":")) {
this.addFlexion(sFlexion, sLemma, sTags);
|
︙ | | |
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
+
+
+
+
-
+
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
+
-
|
}
return null;
},
show: function () {
let sText = "";
for (let [sFlexion, sLemma, sTag] of this.lFlexion) {
sText += sFlexion + " (" + sLemma + ") " + sTag + "<br/>\n";
sText += sFlexion + " (" + sLemma + ") " + sTag + "\n";
}
if (sText) {
document.getElementById("results").innerHTML = sText;
oPage.showActions();
document.getElementById("results").textContent = sText;
oWidgets.showElement("actions");
} else {
oPage.hideActions();
oWidgets.hideElement("actions");
}
},
addToLexicon: function () {
try {
oLexicon.addFlexions(this.lFlexion);
document.getElementById("lemma").value = "";
oPage.showSection("section_vide");
oPage.hideEditor();
oPage.hideActions();
oPage.clear();
oPage.showSaveButton();
oWidgets.showSection("section_vide");
oWidgets.hideElement("editor");
oWidgets.hideElement("actions");
oWidgets.clear();
oWidgets.showElement("save_button");
this.clear();
this.cMainTag = "";
}
catch (e) {
showError(e);
}
}
}
const oLexicon = {
lFlexion: [],
addFlexions: function (lFlex) {
let n = this.lFlexion.length;
for (let aFlex of lFlex) {
this.lFlexion.push(aFlex);
}
this.display();
oWidgets.addEntriesToTable(n, lFlex);
},
load: function () {
if (bChrome) {
browser.storage.local.get("lexicon_list", this._setList);
return;
}
let xPromise = browser.storage.local.get("lexicon_list");
xPromise.then(this._setList, showError);
xPromise.then(this._setList.bind(this), showError);
},
_setList: function (dResult) {
if (dResult.hasOwnProperty("lexicon_list")) {
this.lFlexion = dResult.lexicon_list;
}
},
display: function () {
oPage.clearTable();
let xTable = document.getElementById("table");
let n = 0;
if (this.lFlexion.length > 0) {
oWidgets.displayTable(this.lFlexion);
xTable.appendChild(oPage.createTableHeader());
for (let [sFlexion, sLemma, sTags] of this.lFlexion) {
xTable.appendChild(oPage.createRowNode(n, sFlexion, sLemma, sTags));
n += 1;
}
} else {
xTable.appendChild(createNode("tr", { textContent: "Aucun élément." }));
}
},
save: function () {
console.log("u");
oPage.hideSaveButton();
oWidgets.hideElement("save_button");
let lResult = [];
for (let e of this.lFlexion) {
if (e !== null) {
lResult.push(e);
}
}
browser.storage.local.set({ "lexicon_list": lResult });
this.lFlexion = lResult;
this.display();
oWidgets.displayTable(this.lFlexion);
},
build: function () {
return null;
},
export: function () {
let xBlob = new Blob(['{ "app": "grammalecte", "data": ' + JSON.stringify(this.lFlexion) + ' }'], {type: 'application/json'});
let sURL = URL.createObjectURL(xBlob);
browser.downloads.download({ filename: "grammalecte_dictionnaire_personnel.json", url: sURL, saveAs: true });
}
}
oLexicon.load();
oLexicon.display();
|