Grammalecte  Check-in [1debcdc72b]

Overview
Comment:[fx] test panel (done)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext2
Files: files | file ages | folders
SHA3-256: 1debcdc72b63a02c9b9999798cac62214ac06f0848d73ef12fa2f93e2e011235
User & Date: olr on 2017-08-07 13:13:56
Other Links: branch diff | manifest | tags
Context
2017-08-07
13:15
[fx] use strict and useless var check-in: 0289647400 user: olr tags: fx, webext2
13:13
[fx] test panel (done) check-in: 1debcdc72b user: olr tags: fx, webext2
07:57
[fx] panel: CSS adjustments check-in: 8a81843b4a user: olr tags: fx, webext2
Changes

Modified gc_lang/fr/webext/background.js from [03c66ef198] to [b24f208146].

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
..
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
// Background 

"use strict";









let xGCEWorker = new Worker("gce_worker.js");

xGCEWorker.onmessage = function (e) {

    switch (e.data[0]) {
        case "grammar_errors":
            console.log("GRAMMAR ERRORS");
            console.log(e.data[1].aGrammErr);

            break;
        case "spelling_and_grammar_errors":
            console.log("SPELLING AND GRAMMAR ERRORS");
            console.log(e.data[1].aSpellErr);
            console.log(e.data[1].aGrammErr);
            break;



        case "tests_results":
            console.log("TESTS RESULTS");
            console.log(e.data[1]);

            break;
        case "options":
            console.log("OPTIONS");
            console.log(e.data[1]);
            break;
        case "tokens":
            console.log("TOKENS");
................................................................................
        default:
            console.log("Unknown command: " + e.data[0]);
    }
};

xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);

xGCEWorker.postMessage(["parse", {sText: "J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}]);

xGCEWorker.postMessage(["parseAndSpellcheck", {sText: "C’est terribles, ils va tout perdrre.", sCountry: "FR", bDebug: false, bContext: false}]);

xGCEWorker.postMessage(["getListOfTokens", {sText: "J’en ai assez de ces âneries ! Merci bien. Ça suffira."}]);

xGCEWorker.postMessage(["fullTests"]);


/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
  console.log(`[background] received: ${oRequest.content}`);









  sendResponse({response: "response from background script"});
}

browser.runtime.onMessage.addListener(handleMessage);




>
>
>
>
>
>
>
>



>




>






>
>
>
|

|
>







 







<
<




<






|
>
>
>
>
>
>
>
>
>
|



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
..
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
// Background 

"use strict";

/*
    
*/
let funcSendResultBack = null;

/*
    Worker (separate thread to avoid freezing Firefox)
*/
let xGCEWorker = new Worker("gce_worker.js");

xGCEWorker.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    switch (e.data[0]) {
        case "grammar_errors":
            console.log("GRAMMAR ERRORS");
            console.log(e.data[1].aGrammErr);
            browser.runtime.sendMessage({sCommand: "grammar_errors", aGrammErr: e.data[1].aGrammErr});
            break;
        case "spelling_and_grammar_errors":
            console.log("SPELLING AND GRAMMAR ERRORS");
            console.log(e.data[1].aSpellErr);
            console.log(e.data[1].aGrammErr);
            break;
        case "text_to_test_result":
            browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: e.data[1]});
            break;
        case "fulltests_result":
            console.log("TESTS RESULTS");
            //console.log(e.data[1]);
            browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: e.data[1]});
            break;
        case "options":
            console.log("OPTIONS");
            console.log(e.data[1]);
            break;
        case "tokens":
            console.log("TOKENS");
................................................................................
        default:
            console.log("Unknown command: " + e.data[0]);
    }
};

xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);



xGCEWorker.postMessage(["parseAndSpellcheck", {sText: "C’est terribles, ils va tout perdrre.", sCountry: "FR", bDebug: false, bContext: false}]);

xGCEWorker.postMessage(["getListOfTokens", {sText: "J’en ai assez de ces âneries ! Merci bien. Ça suffira."}]);




/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
    console.log(xSender);
    console.log(sendResponse);
    switch(oRequest.sCommand) {
        case "text_to_test":
            xGCEWorker.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
            break;
        case "fulltests":
            xGCEWorker.postMessage(["fullTests"]);
            break;
    }
    //sendResponse({response: "response from background script"});
}

browser.runtime.onMessage.addListener(handleMessage);

Modified gc_lang/fr/webext/gce_worker.js from [2ab933f7e3] to [3fc4168020].

81
82
83
84
85
86
87



88
89
90
91
92
93
94
...
168
169
170
171
172
173
174













175
176
177
178
179
180
181
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
            break;
        case "setOption":
            setOption(oParam.sOptName, oParam.bValue);
            break;
        case "resetOptions":
            resetOptions();
            break;



        case "fullTests":
            fullTests();
            break;
        case "getListOfTokens":
            getListOfTokens(oParam.sText);
            break;
        default:
................................................................................
    console.log(mfsp.getMasForm("pointilleuse", false));
    console.log(phonet.getSimil("est"));
    let aRes = gc_engine.parse("Je suit...");
    for (let oErr of aRes) {
        console.log(text.getReadableError(oErr));
    }
}














function fullTests (sGCOptions='{"nbsp":true, "esp":true, "unit":true, "num":true}') {
    if (!gc_engine || !oDict) {
        postMessage(["error", "# Error: grammar checker or dictionary not loaded."]);
        return;
    }
    let dMemoOptions = gc_engine.getOptions();
................................................................................
    }
    let sMsg = "";
    for (let sRes of oTest.testParse()) {
        sMsg += sRes + "\n";
        console.log(sRes);
    }
    gc_engine.setOptions(dMemoOptions);
    postMessage(["tests_results", sMsg]);
}


// Lexicographer

function getListOfTokens (sText) {
    try {







>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
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
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
            break;
        case "setOption":
            setOption(oParam.sOptName, oParam.bValue);
            break;
        case "resetOptions":
            resetOptions();
            break;
        case "textToTest":
            textToTest(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
            break;
        case "fullTests":
            fullTests();
            break;
        case "getListOfTokens":
            getListOfTokens(oParam.sText);
            break;
        default:
................................................................................
    console.log(mfsp.getMasForm("pointilleuse", false));
    console.log(phonet.getSimil("est"));
    let aRes = gc_engine.parse("Je suit...");
    for (let oErr of aRes) {
        console.log(text.getReadableError(oErr));
    }
}

function textToTest (sText, sCountry, bDebug, bContext) {
    if (!gc_engine || !oDict) {
        postMessage(["error", "# Error: grammar checker or dictionary not loaded."]);
        return;
    }
    let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
    let sMsg = "";
    for (let oErr of aGrammErr) {
        sMsg += text.getReadableError(oErr) + "\n";
    }
    postMessage(["text_to_test_result", sMsg]);
}

function fullTests (sGCOptions='{"nbsp":true, "esp":true, "unit":true, "num":true}') {
    if (!gc_engine || !oDict) {
        postMessage(["error", "# Error: grammar checker or dictionary not loaded."]);
        return;
    }
    let dMemoOptions = gc_engine.getOptions();
................................................................................
    }
    let sMsg = "";
    for (let sRes of oTest.testParse()) {
        sMsg += sRes + "\n";
        console.log(sRes);
    }
    gc_engine.setOptions(dMemoOptions);
    postMessage(["fulltests_result", sMsg]);
}


// Lexicographer

function getListOfTokens (sText) {
    try {

Modified gc_lang/fr/webext/panel/main.css from [b87893cfe9] to [fb043edbec].

261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#test_cmd textarea {
    width: 100%;
    border: 2px solid hsl(0, 0%, 89%);
    border-radius: 3px;
    resize: vertical;
}

#test_results {
    padding: 15px;
    background-color: hsl(0, 0%, 96%);
}

#test_page .button {
    display: inline-block;
    padding: 5px 10px;







|







261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#test_cmd textarea {
    width: 100%;
    border: 2px solid hsl(0, 0%, 89%);
    border-radius: 3px;
    resize: vertical;
}

#tests_result {
    padding: 15px;
    background-color: hsl(0, 0%, 96%);
}

#test_page .button {
    display: inline-block;
    padding: 5px 10px;

Modified gc_lang/fr/webext/panel/main.html from [f1c096d913] to [941cf34c14].

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
          <h1>LEXICOGRAPHE</h1>
          <div id="tokens_list"></div>
        </section>

        <section id="test_page" class="page">
          <div id="test_cmd">
            <h1>TESTS</h1>
            <textarea id="text" rows="10"></textarea>
            <div id="testall" class="button blue">Tests complets</div> <div id="parse" class="button green fright">Analyser</div>
          </div>
          <div id="test_results">
          </div>
        </section>

        <section id="conj_page" class="page">
          <h1>CONJUGUEUR</h1>
          <p class="right" style="margin: 10px 30px 0 0">
            <input type="text" id="verb" name="verb" maxlength="40" value="" placeholder="entrez un verbe" autofocus />
            <a id="conjugate" href="#" onclick="return false;">Conjuguer</a>
          <p>

          <div class="clearer"></div>

          <p id="conj_smallnote" hidden>Ce verbe n’a pas encore été vérifié. C’est pourquoi les options “pronominal” et “temps composés” sont désactivées.</p>
          <p id="conj_options">
            <label for="oneg">Négation</label> <input type="checkbox" id="oneg" name="oneg" value="ON"  /> 







|
|

|
<






|







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
          <h1>LEXICOGRAPHE</h1>
          <div id="tokens_list"></div>
        </section>

        <section id="test_page" class="page">
          <div id="test_cmd">
            <h1>TESTS</h1>
            <textarea id="text_to_test" rows="10"></textarea>
            <div id="fulltests" class="button blue">Tests complets</div> <div id="text_to_test" class="button green fright">Analyser</div>
          </div>
          <pre id="tests_result"></pre>

        </section>

        <section id="conj_page" class="page">
          <h1>CONJUGUEUR</h1>
          <p class="right" style="margin: 10px 30px 0 0">
            <input type="text" id="verb" name="verb" maxlength="40" value="" placeholder="entrez un verbe" autofocus />
            <a id="conjugate" href="#">Conjuguer</a>
          <p>

          <div class="clearer"></div>

          <p id="conj_smallnote" hidden>Ce verbe n’a pas encore été vérifié. C’est pourquoi les options “pronominal” et “temps composés” sont désactivées.</p>
          <p id="conj_options">
            <label for="oneg">Négation</label> <input type="checkbox" id="oneg" name="oneg" value="ON"  /> 

Modified gc_lang/fr/webext/panel/main.js from [f06df035f4] to [49ea22ef41].


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





















function showError (e) {
  console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}

function beastNameToURL(beastName) {
  switch (beastName) {
    case "Frog":
      return browser.extension.getURL("beasts/frog.jpg");
    case "Snake":
      return browser.extension.getURL("beasts/snake.jpg");
    case "Turtle":
      return browser.extension.getURL("beasts/turtle.jpg");
  }
}

window.addEventListener(
  "click",
  function (xEvent) {
    let xElem = xEvent.target;
    if (xElem.id) {
      if (xElem.id) {

      }
    } else if (xElem.className === "select") {
      showPage(xElem.dataset.page);
    } else if (xElem.tagName === "A") {
      openURL(xElem.getAttribute("href"));
    }
  },
  false
);

function showPage (sPageName) {
  try {
    // hide them all
    for (let xNodePage of document.getElementsByClassName("page")) {
      xNodePage.style.display = "None";
    }
    // show the one
    document.getElementById(sPageName).style.display = "block";
    sendMessage("Mon message");
    // specific modifications
    if (sPageName === "conj_page") {
      document.body.style.width = "600px";
      document.documentElement.style.width = "600px";
      //document.getElementById("movewindow").style.display = "none";
    } else {
      document.body.style.width = "530px";
      document.documentElement.style.width = "530px";
      //document.getElementById("movewindow").style.display = "block";
    }
  }
  catch (e) {
    showError(e);
  }
}

































function handleResponse(message) {
  console.log(`[Panel] received: ${message.response}`);

}

function handleError(error) {
  console.log(`[Panel] Error: ${error}`);

}

function sendMessage (sMessage) {
  let sending = browser.runtime.sendMessage({content: sMessage});
  sending.then(handleResponse, handleError);  
}



















>


|


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

|
|
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>


|
|
>


|
|
|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
// Main panel

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";

        // specific modifications
        if (sPageName === "conj_page") {
            document.body.style.width = "600px";
            document.documentElement.style.width = "600px";
            //document.getElementById("movewindow").style.display = "none";
        } else {
            document.body.style.width = "530px";
            document.documentElement.style.width = "530px";
            //document.getElementById("movewindow").style.display = "block";
        }
    }
    catch (e) {
        showError(e);
    }
}


/*
    Events
*/
window.addEventListener(
    "click",
    function (xEvent) {
        let xElem = xEvent.target;
        if (xElem.id) {
            switch (xElem.id) {
                case "text_to_test":
                    browser.runtime.sendMessage({sCommand: "text_to_test", sText: document.getElementById("text_to_test").value});
                    break;
                case "fulltests":
                    document.getElementById("tests_result").textContent = "Veuillez patienter…";
                    browser.runtime.sendMessage({sCommand: "fulltests"});
                    break;
            }
        } else if (xElem.className === "select") {
            showPage(xElem.dataset.page);
        } else if (xElem.tagName === "A") {
            openURL(xElem.getAttribute("href"));
        }
    },
    false
);


/* 
    Message sender
    and response handling
*/
function handleResponse (oResponse) {
    console.log(`[Panel] received:`);
    console.log(oResponse);
}

function handleError (error) {
    console.log(`[Panel] Error:`);
    console.log(error);
}

function sendMessageAndWaitResponse (oData) {
    let xPromise = browser.runtime.sendMessage(oData);
    xPromise.then(handleResponse, handleError);  
}


/*
    Messages received
*/
function handleMessage (oMessage, xSender, sendResponse) {
    //console.log(xSender);
    switch(oMessage.sCommand) {
        case "text_to_test_result":
            document.getElementById("tests_result").textContent = oMessage.sResult;
            break;
        case "fulltests_result":
            document.getElementById("tests_result").textContent = oMessage.sResult;
            break;
    }
    sendResponse({sCommand: "none", sResult: "done"});
}

browser.runtime.onMessage.addListener(handleMessage);