Grammalecte  Check-in [6524138639]

Overview
Comment:[fx] default gc options
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext2
Files: files | file ages | folders
SHA3-256: 65241386396e5637af6c7a3f05e96bd5200566ee0fa5a11f228ba5145e6a716d
User & Date: olr on 2017-08-29 09:49:33
Other Links: branch diff | manifest | tags
Context
2017-08-29
12:33
[fx] main panel: help section check-in: b8ce0aa31d user: olr tags: fx, webext2
09:49
[fx] default gc options check-in: 6524138639 user: olr tags: fx, webext2
06:18
[fx] copy text to clipboard check-in: 49c4a65f72 user: olr tags: fx, webext2
Changes

Modified gc_lang/fr/webext/background.js from [32e8b61dc7] to [8c06e3086c].

32
33
34
35
36
37
38

39
40

41
42
43
44
45
46
47
                    console.log(e.data);
                }
                break;
            case "textToTest":
            case "fullTests":
            case "getOptions":
            case "getDefaultOptions":

                // send result to panel
                browser.runtime.sendMessage(e.data);

                break;
            case "setOptions":
            case "setOption":
                browser.storage.local.set({"gc_options": result});
                break;
            default:
                console.log("Unknown command: " + sActionDone);







>


>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
                    console.log(e.data);
                }
                break;
            case "textToTest":
            case "fullTests":
            case "getOptions":
            case "getDefaultOptions":
            case "resetOptions":
                // send result to panel
                browser.runtime.sendMessage(e.data);
                browser.storage.local.set({"gc_options": result});
                break;
            case "setOptions":
            case "setOption":
                browser.storage.local.set({"gc_options": result});
                break;
            default:
                console.log("Unknown command: " + sActionDone);
97
98
99
100
101
102
103

104
105
106
107
108
109
110
        case "parseAndSpellcheck1":
        case "getListOfTokens":
        case "textToTest":
        case "getOptions":
        case "getDefaultOptions":
        case "setOptions":
        case "setOption":

        case "fullTests":
            xGCEWorker.postMessage(oRequest);
            break;
        default:
            console.log("[background] Unknown command: " + oRequest.sCommand);
    }
    //sendResponse({response: "response from background script"});







>







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        case "parseAndSpellcheck1":
        case "getListOfTokens":
        case "textToTest":
        case "getOptions":
        case "getDefaultOptions":
        case "setOptions":
        case "setOption":
        case "resetOptions":
        case "fullTests":
            xGCEWorker.postMessage(oRequest);
            break;
        default:
            console.log("[background] Unknown command: " + oRequest.sCommand);
    }
    //sendResponse({response: "response from background script"});

Modified gc_lang/fr/webext/content_scripts/gc_content.js from [acc5b2167c] to [caf52bce8a].

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

    addMessage (sMessage) {
        let xNode = createNode("div", {className: "grammalecte_gc_panel_message", textContent: sMessage});
        this.xParagraphList.appendChild(xNode);
    }

    _copyToClipboard (sText)  {
        // recipie from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js
        function setClipboardData (xEvent) {
            document.removeEventListener("copy", setClipboardData, true);
            xEvent.stopImmediatePropagation();
            xEvent.preventDefault();
            xEvent.clipboardData.setData("text/plain", sText);
        };








|







240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

    addMessage (sMessage) {
        let xNode = createNode("div", {className: "grammalecte_gc_panel_message", textContent: sMessage});
        this.xParagraphList.appendChild(xNode);
    }

    _copyToClipboard (sText)  {
        // recipe from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js
        function setClipboardData (xEvent) {
            document.removeEventListener("copy", setClipboardData, true);
            xEvent.stopImmediatePropagation();
            xEvent.preventDefault();
            xEvent.clipboardData.setData("text/plain", sText);
        };

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
            window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 2000);
        }
        catch (e) {
            showError(e);
        }
        this.stopWaitIcon();
    }


}


class GrammalecteTooltip {

    constructor (xContentNode) {
        this.xTooltip = createNode("div", {id: "grammalecte_tooltip"});







<
<







270
271
272
273
274
275
276


277
278
279
280
281
282
283
            window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 2000);
        }
        catch (e) {
            showError(e);
        }
        this.stopWaitIcon();
    }


}


class GrammalecteTooltip {

    constructor (xContentNode) {
        this.xTooltip = createNode("div", {id: "grammalecte_tooltip"});

Modified gc_lang/fr/webext/gce_worker.js from [615fe67e99] to [55db11ec7e].

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
        case "resetOptions":
            resetOptions(dInfo);
            break;
        case "textToTest":
            textToTest(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo);
            break;
        case "fullTests":
            fullTests('{"nbsp":true, "esp":true, "unit":true, "num":true}', dInfo);
            break;
        case "getListOfTokens":
            getListOfTokens(dParam.sText, dInfo);
            break;
        default:
            console.log("Unknown command: " + sCommand);
            showData(e.data);







|







113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
        case "resetOptions":
            resetOptions(dInfo);
            break;
        case "textToTest":
            textToTest(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo);
            break;
        case "fullTests":
            fullTests(dInfo);
            break;
        case "getListOfTokens":
            getListOfTokens(dParam.sText, dInfo);
            break;
        default:
            console.log("Unknown command: " + sCommand);
            showData(e.data);
247
248
249
250
251
252
253
254
255
256
257
258
259


260


261
262
263
264
265
266
267
268
269
    let sMsg = "";
    for (let oErr of aGrammErr) {
        sMsg += text.getReadableError(oErr) + "\n";
    }
    postMessage(createResponse("textToTest", sMsg, dInfo, true));
}

function fullTests (sGCOptions="", dInfo={}) {
    if (!gc_engine || !oDict) {
        postMessage(createResponse("fullTests", "# Grammar checker or dictionary not loaded.", dInfo, true));
        return;
    }
    let dMemoOptions = gc_engine.getOptions();


    if (sGCOptions) {


        gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
    }
    let sMsg = "";
    for (let sRes of oTest.testParse()) {
        sMsg += sRes + "\n";
        console.log(sRes);
    }
    gc_engine.setOptions(dMemoOptions);
    postMessage(createResponse("fullTests", sMsg, dInfo, true));







|





>
>
|
>
>
|
<







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
    let sMsg = "";
    for (let oErr of aGrammErr) {
        sMsg += text.getReadableError(oErr) + "\n";
    }
    postMessage(createResponse("textToTest", sMsg, dInfo, true));
}

function fullTests (dInfo={}) {
    if (!gc_engine || !oDict) {
        postMessage(createResponse("fullTests", "# Grammar checker or dictionary not loaded.", dInfo, true));
        return;
    }
    let dMemoOptions = gc_engine.getOptions();
    let dTestOptions = gc_engine.getDefaultOptions();
    dTestOptions.set("nbsp", true);
    dTestOptions.set("esp", true);
    dTestOptions.set("unit", true);
    dTestOptions.set("num", true);
    gc_engine.setOptions(dTestOptions);

    let sMsg = "";
    for (let sRes of oTest.testParse()) {
        sMsg += sRes + "\n";
        console.log(sRes);
    }
    gc_engine.setOptions(dMemoOptions);
    postMessage(createResponse("fullTests", sMsg, dInfo, true));

Modified gc_lang/fr/webext/panel/main.css from [74b12a3950] to [182d8e0b86].

192
193
194
195
196
197
198









199
200
201
202
203
204
205
.opt_subsection label {
    flex: 1;
    font-size: 12px;
}
.opt_subsection input {
    order: 1
}











/*
    Spell checking options
*/
#sc_options_page {
    display: none;







>
>
>
>
>
>
>
>
>







192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
.opt_subsection label {
    flex: 1;
    font-size: 12px;
}
.opt_subsection input {
    order: 1
}

#gc_options_page .button {
    margin: 20px 30px 0 30px;
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 16px;
    text-align: center;
    cursor: pointer;
}


/*
    Spell checking options
*/
#sc_options_page {
    display: none;

Modified gc_lang/fr/webext/panel/main.html from [4ad4566068] to [ffe15c1a20].

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
        </section> <!-- #help_page -->

        <section id="gc_options_page" class="page">
          <h1>OPTIONS GRAMMATICALES</h1>
          <div id="grammar_options">
            ${webextOptionsHTML}
          </div>
          <p class="center" style="margin: 10px 0;"><a id="default_options" href="#" onclick="return false;">Options par défaut</a></p>
        </section> <!-- #gc_options_page -->

        <section id="sc_options_page" class="page">
          <h1>OPTIONS ORTHOGRAPHIQUES</h1>
          <div id="spelling_options">
            <p id="dictionaries_info" data-l10n-id="dictionaries_info">*** non actif ***</p>
            <div class="dict_section" id="fr-FR-modern_box">







|







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
        </section> <!-- #help_page -->

        <section id="gc_options_page" class="page">
          <h1>OPTIONS GRAMMATICALES</h1>
          <div id="grammar_options">
            ${webextOptionsHTML}
          </div>
          <div id="default_options_button" class="button blue center">Options par défaut</div>
        </section> <!-- #gc_options_page -->

        <section id="sc_options_page" class="page">
          <h1>OPTIONS ORTHOGRAPHIQUES</h1>
          <div id="spelling_options">
            <p id="dictionaries_info" data-l10n-id="dictionaries_info">*** non actif ***</p>
            <div class="dict_section" id="fr-FR-modern_box">
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        </section> <!-- #sc_options_page -->

        <section id="test_page" class="page">
          <div id="test_cmd">
            <h1>TESTS</h1>
            <div><a href="https://www.dicollecte.org/test.html" target="_blank">Page for tests</a></div>
            <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> <!-- #test_page -->

      </div> <!-- #page -->

    </div> <!-- #main -->

    <script src="main.js"></script>
  </body>

</html>
   







|













106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        </section> <!-- #sc_options_page -->

        <section id="test_page" class="page">
          <div id="test_cmd">
            <h1>TESTS</h1>
            <div><a href="https://www.dicollecte.org/test.html" target="_blank">Page for tests</a></div>
            <textarea id="text_to_test" rows="10"></textarea>
            <div id="fulltests_button" class="button blue">Tests complets</div> <div id="text_to_test_button" class="button green fright">Analyser</div>
          </div>
          <pre id="tests_result"></pre>
        </section> <!-- #test_page -->

      </div> <!-- #page -->

    </div> <!-- #main -->

    <script src="main.js"></script>
  </body>

</html>
   

Modified gc_lang/fr/webext/panel/main.js from [235cf872b7] to [dc636eef89].

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
    Events
*/
window.addEventListener(
    "click",
    function (xEvent) {
        let xElem = xEvent.target;
        if (xElem.id) {
            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},
                    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: {}
                });







|






|






>
>
>
>
>
>
>







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
    Events
*/
window.addEventListener(
    "click",
    function (xEvent) {
        let xElem = xEvent.target;
        if (xElem.id) {
            if (xElem.id === "text_to_test_button") {
                browser.runtime.sendMessage({
                    sCommand: "textToTest",
                    dParam: {sText: document.getElementById("text_to_test").value, sCountry: "FR", bDebug: false, bContext: false},
                    dInfo: {}
                });
            }
            else if (xElem.id === "fulltests_button") {
                document.getElementById("tests_result").textContent = "Veuillez patienter…";
                browser.runtime.sendMessage({
                    sCommand: "fullTests",
                    dParam: {},
                    dInfo: {}
                });
            }
            else if (xElem.id === "default_options_button") {
                browser.runtime.sendMessage({
                   sCommand: "resetOptions",
                   dParam: {},
                   dInfo: {}
                });
            }
            else if (xElem.id.startsWith("option_")) {
                browser.runtime.sendMessage({
                    sCommand: "setOption",
                    dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked},
                    dInfo: {}
                });
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








function handleMessage (oMessage, xSender, sendResponse) {
    let {sActionDone, result, dInfo, bEnd, bError} = oMessage;
    switch(sActionDone) {
        case "textToTest":
        case "fullTests":
            showTestResult(result);
            break;
        case "getOptions":
        case "getDefaultOptions":
            break;
        default:
            console.log("GRAMMALECTE. Unknown command: " + oMessage.sCommand);
    }
    sendResponse({sCommand: "none", result: "done"});
}

browser.runtime.onMessage.addListener(handleMessage);


/*
    Actions
*/

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















|
|


|

|


















|












|



<

|
<
<
<
<







>
>
>
>
>
>
>
>
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
function handleMessage (oMessage, xSender, sendResponse) {
    let {sActionDone, result, dInfo, bEnd, bError} = oMessage;
    switch(sActionDone) {
        case "textToTest":
        case "fullTests":
            showTestResult(result);
            break;
        case "resetOptions":
            setGCOptions(result);
            break;
        default:
            console.log("GRAMMALECTE. Unknown command: " + sActionDone);
    }
    //sendResponse({sCommand: "none", result: "done"});
}

browser.runtime.onMessage.addListener(handleMessage);


/*
    Actions
*/

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";
        if (sPageName == "gc_options_page") {
            setGCOptionsFromStorage();
        }
    }
    catch (e) {
        showError(e);
    }
}


function showTestResult (sText) {
    document.getElementById("tests_result").textContent = sText;
}

function setGCOptionsFromStorage () {
    let xPromise = browser.storage.local.get("gc_options");
    xPromise.then(
        function (dSavedOptions) {

            if (dSavedOptions.hasOwnProperty("gc_options")) {
                setGCOptions(dSavedOptions.gc_options);




            }
        },
        function (e) {
            showError(e);
        }
    );
}

function setGCOptions (dOptions) {
    for (let [sOpt, bVal] of dOptions) {
        if (document.getElementById("option_"+sOpt)) {
            document.getElementById("option_"+sOpt).checked = bVal;
        }
    }
}