Grammalecte  Diff

Differences From Artifact [3c0ad50206]:

To Artifact [56de373e52]:


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
    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: true, 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_")) {
                if (xElem.dataset.option) {
                    browser.runtime.sendMessage({
                        sCommand: "setOption",
                        dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked},
                        dInfo: {}
                    });
                }
            }

            else if (xElem.id.endsWith("_dic")) {
                if (xElem.dataset.dictionary) {
                    storeSCOptions();
                    browser.runtime.sendMessage({
                        sCommand: "setDictionaryOnOff",
                        dParam: {sDictionary: xElem.dataset.dictionary, bActivate: xElem.checked},
                        dInfo: {}
                    });
                }
            }











            else if (xElem.id.startsWith("ui_option_")) {
                storeUIOptions();
            }

            else if (xElem.id.startsWith("link_")) {
                browser.tabs.create({url: xElem.dataset.url});
            }
            else if (xElem.id == "conj_button") {
                browser.runtime.sendMessage({
                    sCommand: "openConjugueurTab",
                    dParam: {},







>















>
>
>
>
>
>
>
>
















>










>
>
>
>
>
>
>
>
>
>
>



>







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
    Events
*/
window.addEventListener(
    "click",
    function (xEvent) {
        let xElem = xEvent.target;
        if (xElem.id) {
            // tests
            if (xElem.id === "text_to_test_button") {
                browser.runtime.sendMessage({
                    sCommand: "textToTest",
                    dParam: {sText: document.getElementById("text_to_test").value, sCountry: "FR", bDebug: true, 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 == "restart_worker") {
                browser.runtime.sendMessage({
                    sCommand: "restartWorker",
                    dParam: { "nDelayLimit": 3 },
                    dInfo: {}
                });
            }
            // grammar options
            else if (xElem.id === "default_options_button") {
                browser.runtime.sendMessage({
                   sCommand: "resetOptions",
                   dParam: {},
                   dInfo: {}
                });
            }
            else if (xElem.id.startsWith("option_")) {
                if (xElem.dataset.option) {
                    browser.runtime.sendMessage({
                        sCommand: "setOption",
                        dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked},
                        dInfo: {}
                    });
                }
            }
            // dictionaries options
            else if (xElem.id.endsWith("_dic")) {
                if (xElem.dataset.dictionary) {
                    storeSCOptions();
                    browser.runtime.sendMessage({
                        sCommand: "setDictionaryOnOff",
                        dParam: {sDictionary: xElem.dataset.dictionary, bActivate: xElem.checked},
                        dInfo: {}
                    });
                }
            }
            else if (xElem.id.startsWith("spelling_")) {
                updateSpellingChoiceUI(xElem.id);
                let sMainDicName = document.getElementById(xElem.id).dataset.dicname;
                browser.storage.local.set({"main_dic_name": sMainDicName});
                browser.runtime.sendMessage({
                    sCommand: "setDictionary",
                    dParam: { sDictionary: "main", oDict: sMainDicName },
                    dInfo: { sExtPath: browser.extension.getURL("") }
                });
            }
            // UI options
            else if (xElem.id.startsWith("ui_option_")) {
                storeUIOptions();
            }
            //
            else if (xElem.id.startsWith("link_")) {
                browser.tabs.create({url: xElem.dataset.url});
            }
            else if (xElem.id == "conj_button") {
                browser.runtime.sendMessage({
                    sCommand: "openConjugueurTab",
                    dParam: {},
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
            else if (xElem.id == "dic_personal_button") {
                browser.runtime.sendMessage({
                    sCommand: "openLexiconEditor",
                    dParam: { "dictionary": "__personal__"},
                    dInfo: {}
                });
            }
            else if (xElem.id == "restart_worker") {
                browser.runtime.sendMessage({
                    sCommand: "restartWorker",
                    dParam: { "nDelayLimit": 3 },
                    dInfo: {}
                });
            }
        } else if (xElem.className.startsWith("select")) {
            showPage(xElem.dataset.page);
        }/* else if (xElem.tagName === "A") {
            openURL(xElem.getAttribute("href"));
        }*/
    },
    false







<
|
<
<
<
<
<







117
118
119
120
121
122
123

124





125
126
127
128
129
130
131
            else if (xElem.id == "dic_personal_button") {
                browser.runtime.sendMessage({
                    sCommand: "openLexiconEditor",
                    dParam: { "dictionary": "__personal__"},
                    dInfo: {}
                });
            }

        // change UI page





        } else if (xElem.className.startsWith("select")) {
            showPage(xElem.dataset.page);
        }/* else if (xElem.tagName === "A") {
            openURL(xElem.getAttribute("href"));
        }*/
    },
    false
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

/*
    SC Options
*/
function displaySCOptionsLoadedFromStorage () {
    if (bChrome) {
        browser.storage.local.get("sc_options", displaySCOptions);

        return;
    }
    let xPromise = browser.storage.local.get("sc_options");
    xPromise.then(displaySCOptions, showError);
}

function displaySCOptions (dOptions) {
    if (!dOptions.hasOwnProperty("sc_options")) {
        console.log("no sc options found");
        return;
    }
    dOptions = dOptions.sc_options;
    //document.getElementById("extended_dic").checked = dOptions.extended;
    document.getElementById("community_dic").checked = dOptions.community;
    document.getElementById("personal_dic").checked = dOptions.personal;










}

function storeSCOptions () {
    browser.storage.local.set({"sc_options": {
        extended: false,
        community: document.getElementById("community_dic").checked,
        personal: document.getElementById("personal_dic").checked
    }});
}








/*
    GC options
*/
function displayGCOptionsLoadedFromStorage () {
    if (bChrome) {







>


|
|



|
<
<
<
<
<
|
|
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>







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

/*
    SC Options
*/
function displaySCOptionsLoadedFromStorage () {
    if (bChrome) {
        browser.storage.local.get("sc_options", displaySCOptions);
        browser.storage.local.get("main_dic_name", displaySCOptions);
        return;
    }
    browser.storage.local.get("sc_options").then(displaySCOptions, showError);
    browser.storage.local.get("main_dic_name").then(displaySCOptions, showError);
}

function displaySCOptions (dOptions) {
    if (dOptions.hasOwnProperty("sc_options")) {





        document.getElementById("community_dic").checked = dOptions.sc_options.community;
        document.getElementById("personal_dic").checked = dOptions.sc_options.personal;
    }
    if (dOptions.hasOwnProperty("main_dic_name")) {
        switch (dOptions.main_dic_name) {
            case "fr-classic.json":  updateSpellingChoiceUI("spelling_classic"); break;
            case "fr-reform.json":  updateSpellingChoiceUI("spelling_reform"); break;
            case "fr-allvars.json":  updateSpellingChoiceUI("spelling_allvars"); break;
            default:
                console.log("Unknown dictionary name:", dOptions.main_dic_name);
        }
    }
}

function storeSCOptions () {
    browser.storage.local.set({"sc_options": {
        extended: false,
        community: document.getElementById("community_dic").checked,
        personal: document.getElementById("personal_dic").checked
    }});
}

function updateSpellingChoiceUI (sSpellingChoice) {
    document.getElementById("spelling_classic").className = (sSpellingChoice == "spelling_classic") ? "radiolike selected" : "radiolike";
    document.getElementById("spelling_reform").className = (sSpellingChoice == "spelling_reform") ? "radiolike selected" : "radiolike";
    document.getElementById("spelling_allvars").className = (sSpellingChoice == "spelling_allvars") ? "radiolike selected" : "radiolike";
}


/*
    GC options
*/
function displayGCOptionsLoadedFromStorage () {
    if (bChrome) {