Grammalecte  Check-in [6d2246be0e]

Overview
Comment:[fx] WebExt: adaptation to Chrome (write and read gc options)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 6d2246be0e19fd5898172260c944e773db42a5caf0654ce5d309b6fa98ee4122
User & Date: olr on 2017-09-27 09:10:44
Other Links: manifest | tags
Context
2017-09-27
10:20
[fx] WebExt: adaptation to Chrome: minimal version required check-in: e7592882ed user: olr tags: trunk, fx
09:10
[fx] WebExt: adaptation to Chrome (write and read gc options) check-in: 6d2246be0e user: olr tags: trunk, fx
2017-09-26
13:46
[fx] WebExt: a Map is not a Map anymore on Chrome (not working) check-in: e2850f295a user: olr tags: trunk, fx
Changes

Modified gc_core/js/helpers.js from [f725b5eed7] to [b352512c63].

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        }
    },

    // conversions
    objectToMap: function (obj) {
        let m = new Map();
        for (let param in obj) {
            //console.log(param + " " + obj[param]);
            m.set(param, obj[param]);
        }
        return m;
    },

    mapToObject: function (m) {
        let obj = {};







<







70
71
72
73
74
75
76

77
78
79
80
81
82
83
        }
    },

    // conversions
    objectToMap: function (obj) {
        let m = new Map();
        for (let param in obj) {

            m.set(param, obj[param]);
        }
        return m;
    },

    mapToObject: function (m) {
        let obj = {};

Modified gc_lang/fr/webext/background.js from [d893b16f09] to [7732c179f1].

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

xGCEWorker.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    try {
        let {sActionDone, result, dInfo} = e.data;
        switch (sActionDone) {
            case "init":
                browser.storage.local.set({"gc_options": result});
                break;
            case "parse":
            case "parseAndSpellcheck":
            case "parseAndSpellcheck1":
            case "getListOfTokens":
            case "getSpellSuggestions":
                // send result to content script







|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

xGCEWorker.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    try {
        let {sActionDone, result, dInfo} = e.data;
        switch (sActionDone) {
            case "init":
                storeGCOptions(result);
                break;
            case "parse":
            case "parseAndSpellcheck":
            case "parseAndSpellcheck1":
            case "getListOfTokens":
            case "getSpellSuggestions":
                // send result to content script
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
                browser.runtime.sendMessage(e.data);
                break;
            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("[background] Unknown command: " + sActionDone);
                console.log(e.data);
        }
    }
    catch (e) {







|



|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
                browser.runtime.sendMessage(e.data);
                break;
            case "getOptions":
            case "getDefaultOptions":
            case "resetOptions":
                // send result to panel
                browser.runtime.sendMessage(e.data);
                storeGCOptions(result);
                break;
            case "setOptions":
            case "setOption":
                storeGCOptions(result);
                break;
            default:
                console.log("[background] Unknown command: " + sActionDone);
                console.log(e.data);
        }
    }
    catch (e) {
258
259
260
261
262
263
264













265
266
267
268
269
270
271
    }
});


/*
    Actions
*/













function parseAndSpellcheckSelectedText (iTab, sText) {
    // send message to the tab
    let xTabPort = dConnx.get(iTab);
    xTabPort.postMessage({sActionDone: "openGCPanel", result: null, dInfo: null, bEnd: false, bError: false});
    // send command to the worker
    xGCEWorker.postMessage({
        sCommand: "parseAndSpellcheck",







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







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


/*
    Actions
*/

function storeGCOptions (dOptions) {
    if (bChrome) {
        // JS crap again. Chrome can’t store Map object.
        let obj = {};
        for (let [k, v] of dOptions) {
            obj[k] = v;
        }
        dOptions = obj;
    }
    browser.storage.local.set({"gc_options": dOptions});
}

function parseAndSpellcheckSelectedText (iTab, sText) {
    // send message to the tab
    let xTabPort = dConnx.get(iTab);
    xTabPort.postMessage({sActionDone: "openGCPanel", result: null, dInfo: null, bEnd: false, bError: false});
    // send command to the worker
    xGCEWorker.postMessage({
        sCommand: "parseAndSpellcheck",

Modified gc_lang/fr/webext/panel/main.js from [0dd514b39a] to [515cc52320].

147
148
149
150
151
152
153



154


155

156

157
158
159
160
161
162
163
164
165
166
167
168
169
function _setGCOptions (dSavedOptions) {
    if (dSavedOptions.hasOwnProperty("gc_options")) {
        setGCOptions(dSavedOptions.gc_options);
    }
}

function setGCOptions (dOptions) {



    console.log(typeof(dOptions));


    console.log(dOptions);

    /*for (let [sOpt, bVal] of dOptions) {

        if (document.getElementById("option_"+sOpt)) {
            document.getElementById("option_"+sOpt).checked = bVal;
        }
    }*/
    // JS bullshit never ends. For some reason, it’s not a Map anymore on Chrome! 
    for (let xOption of document.getElementsByClassName("gc_option")) {
        console.log(xOption.id);
        let sOpt = xOption.id.slice(7);
        if (dOptions.has(sOpt)) {
            xOption.checked = dOptions.get(sOpt);
        }
    }
}







>
>
>
|
>
>
|
>
|
>



<
<
<
<
<
<
<
<


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166








167
168
function _setGCOptions (dSavedOptions) {
    if (dSavedOptions.hasOwnProperty("gc_options")) {
        setGCOptions(dSavedOptions.gc_options);
    }
}

function setGCOptions (dOptions) {
    if (bChrome) {
        // JS crap again. Chrome can’t store Map object.
        let m = new Map();
        for (let param in dOptions) {
            m.set(param, dOptions[param]);
        }
        dOptions = m;
    }
    for (let [sOpt, bVal] of dOptions) {
        console.log(sOpt + ": " + bVal);
        if (document.getElementById("option_"+sOpt)) {
            document.getElementById("option_"+sOpt).checked = bVal;
        }








    }
}