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
|
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
|
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
// Main panel
"use strict";
/*
Common functions
*/
function showError (e) {
console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}
function showPage (sPageName) {
try {
// hide them all
for (let xNodePage of document.getElementsByClassName("page")) {
xNodePage.style.display = "none";
}
// show the selected one
document.getElementById(sPageName).style.display = "block";
}
catch (e) {
showError(e);
}
}
function startWaitIcon () {
document.getElementById("waiticon").hidden = false;
}
function stopWaitIcon () {
document.getElementById("waiticon").hidden = true;
}
/*
Events
*/
window.addEventListener(
"click",
function (xEvent) {
let xElem = xEvent.target;
if (xElem.id) {
switch (xElem.id) {
case "text_to_test":
browser.runtime.sendMessage({sCommand: "textToTest", dParam: {sText: document.getElementById("text_to_test").value, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
if (xElem.id === "text_to_test") {
browser.runtime.sendMessage({
sCommand: "textToTest",
dParam: {sText: document.getElementById("text_to_test").value, sCountry: "FR", bDebug: false, bContext: false},
break;
case "fulltests":
document.getElementById("tests_result").textContent = "Veuillez patienter…";
browser.runtime.sendMessage({sCommand: "fullTests", dParam: {}, dInfo: {}});
break;
dInfo: {}
});
}
else if (xElem.id === "fulltests") {
document.getElementById("tests_result").textContent = "Veuillez patienter…";
browser.runtime.sendMessage({
sCommand: "fullTests",
dParam: {},
dInfo: {}
});
}
else if (xElem.id.startsWith("option_")) {
browser.runtime.sendMessage({
sCommand: "setOption",
dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked},
dInfo: {}
});
}
} else if (xElem.className.startsWith("select")) {
showPage(xElem.dataset.page);
}/* else if (xElem.tagName === "A") {
openURL(xElem.getAttribute("href"));
}*/
},
|
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
|
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
|
+
-
-
-
+
+
+
+
-
-
+
+
+
+
-
+
+
+
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
/*
Messages received
*/
function handleMessage (oMessage, xSender, sendResponse) {
let {sActionDone, result, dInfo, bEnd, bError} = oMessage;
switch(oMessage.sCommand) {
case "text_to_test_result":
showTestResult(oMessage.sResult);
switch(sActionDone) {
case "textToTest":
case "fullTests":
showTestResult(result);
break;
case "fulltests_result":
showTestResult(oMessage.sResult);
case "getOptions":
case "getDefaultOptions":
break;
default:
console.log("GRAMMALECTE. Unknown command: " + oMessage.sCommand);
}
sendResponse({sCommand: "none", sResult: "done"});
sendResponse({sCommand: "none", result: "done"});
}
browser.runtime.onMessage.addListener(handleMessage);
/*
Actions
*/
DEDICATED FUNCTIONS
function showPage (sPageName) {
try {
// hide them all
for (let xNodePage of document.getElementsByClassName("page")) {
xNodePage.style.display = "none";
}
*/
/*
Test page
// show the selected one
document.getElementById(sPageName).style.display = "block";
if (sPageName == "gc_options_page") {
setGCOptions();
}
}
catch (e) {
showError(e);
}
}
*/
function showTestResult (sText) {
document.getElementById("tests_result").textContent = sText;
}
function setGCOptions () {
let xPromise = browser.storage.local.get("gc_options");
xPromise.then(
function (dSavedOptions) {
console.log(dSavedOptions);
if (dSavedOptions.hasOwnProperty("gc_options")) {
for (let [sOpt, bVal] of dSavedOptions.gc_options) {
if (document.getElementById("option_"+sOpt)) {
document.getElementById("option_"+sOpt).checked = bVal;
}
}
}
},
function (e) {
showError(e);
}
);
}
|