Grammalecte  Check-in [74f2ec49cc]

Overview
Comment:[fx] minor coding style adjustments
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | comunicate
Files: files | file ages | folders
SHA3-256: 74f2ec49cc314b30e4c2ea8220cd9826315f009af32166c5df8525ec7a72d07a
User & Date: olr on 2018-11-12 12:22:34
Other Links: branch diff | manifest | tags
Context
2020-03-10
08:33
[fx] cancel code cosmetics check-in: 686c43591b user: olr tags: fx, comunicate
2018-11-12
12:22
[fx] minor coding style adjustments check-in: 74f2ec49cc user: olr tags: fx, comunicate
2018-11-11
11:47
[fx] minor coding style adjustments check-in: 2d45cbf498 user: olr tags: fx, comunicate
Changes

Modified gc_lang/fr/webext/content_scripts/event.js from [8bfc3ad28c] to [072a12ec6a].







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
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
147
148






var min = Math.ceil(0);
var max = Math.floor(9999999);
function uniqueID() {
    return Date.now().toString(36) + "-" + (Math.floor(Math.random() * (max - min)) + min).toString(36);
}

// ! Ecoute des messages venant du content script
let browserURL;
document.addEventListener("GrammalecteToPage", function respListener(event) {
    //console.log(event);
    var data = JSON.parse(event.detail);
    // Message envoyer dès que le script est injecté
    if (typeof data.init !== "undefined") {
        browserURL = data.init;
    }
    if (typeof data.tiny !== "undefined") {
        //console.log('Detect Tiny', data.tiny);
        TinyIDInPage(data.tiny);
    }
    //console.log("GrammalecteToPage",data);
});

// ! Permet d'envoyer des message vers le content script
// Retourne un identifiant unique au cas ou si besoin
// La ID unique peut être util si on permet d'intérogé grammalecte sans zone
function sendToGrammalecte(dataAction) {
    let dataToSend = dataAction;
    if (typeof dataToSend.IdAction === "undefined") {
        dataToSend.IdAction = uniqueID();
    }
    if (dataAction.elm) {
        if (!dataAction.elm.id) {
            dataAction.elm.id = uniqueID();
        }
        dataToSend.elm = dataAction.elm.id;
    }

    //console.log('dataToSend', dataToSend);
    var eventGrammalecte = new CustomEvent("GrammalecteEvent", { detail: JSON.stringify(dataToSend) });
    document.dispatchEvent(eventGrammalecte);
    return dataToSend.IdAction;
}

// ! Envoie de l'information que l'injection est bien faite ;)
// (peut être lu aussi bien par la page web que le content script)
var customAPILoaded = new CustomEvent("GLInjectedScriptIsReady");
document.dispatchEvent(customAPILoaded);

// Gros Hack : Auto add a button in tinymce ;)

// Page to test v4 https://www.quackit.com/html/html_editors/tinymce_editor.cfm
// https://www.responsivefilemanager.com/demo.php

// Page to test v3 http://www.imathas.com/editordemo/demo.html

function TinyOnEditor(event, editor = null) {
    let xEditorAdd = editor || event.editor;
    //console.log(xEditorAdd);

    if (typeof xEditorAdd.settings.Grammalecte === "undefined") {
        let aBtn;
        let plugSep;
        let bIsAdded = false;
        if (tinyMCE.majorVersion >= 4) {
            plugSep = " ";
            aBtn = ["toolbar3", "toolbar2", "toolbar1", "toolbar"];
        } else if (tinyMCE.majorVersion >= 3) {
            plugSep = ",";
            aBtn = ["theme_advanced_buttons3", "theme_advanced_buttons2", "theme_advanced_buttons1", "theme_advanced_buttons1_add_before"];
        }

        let eBtn;
        let iBtn = 0;
        let nBtn = aBtn.length;
        for (eBtn of aBtn) {
            if (!bIsAdded && (typeof xEditorAdd.settings[eBtn] !== "undefined" || iBtn == nBtn)) {
                bIsAdded = true;
                if (typeof xEditorAdd.settings[eBtn] !== "undefined" && xEditorAdd.settings[eBtn] !== "") {
                    xEditorAdd.settings[eBtn] = (xEditorAdd.settings[eBtn] + plugSep + "Grammalecte").trim();
                } else {
                    let m = /(.*)([0-9])/.exec(eBtn);
                    if (m.length === 3 && parseInt(m[2]) > 1 && xEditorAdd.settings[eBtn] === "") {
                        eBtn = m[1] + (parseInt(m[2]) - 1);
                        xEditorAdd.settings[eBtn] = (xEditorAdd.settings[eBtn] + plugSep + "Grammalecte").trim();
                    } else {
                        xEditorAdd.settings[eBtn] = "Grammalecte";
                    }
                }
            }
            iBtn++;
        }
        if (!bIsAdded) {
            //Valeur par defaut
            xEditorAdd.settings[eBtn] =
                "undo redo | styleselect | bold italic | alignleft" +
                " aligncenter alignright alignjustify | " +
                " bullist numlist outdent indent | link image" +
                " Grammalecte";
        }
        xEditorAdd.settings["Grammalecte"] = true;
    }

    xEditorAdd.addButton("Grammalecte", {
        text: "",
        icon: false,
        image: browserURL + "img/logo-16.png",
        //"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAC8UlEQVQ4jX3TbUgTcRwH8P89ddu5u9tt082aZmpFEU4tFz0QGTUwCi0heniR9MSUIKRaD0RvIlKigsooo+iNFa0XJYuwIjEK19OcDtPElsG0ktyp591t7u7+vUh7MPX3+vf5/n8/+P0BmKJIPUUVlh2rdVVeesWlzEybqg+bFOsoylnqPmNavGFfknV2Omu2Lvja3vxAURKJib3opHizu8riLK6gjRyuKgmoSoMRFENRUqfXTzvBGK62LC2uoFkOl4RhjQ8+qWt7dPNE3sbdp+2LXbsGe9qb4rIo/BfwFy6nWQ4ThWGNDzbcfu29dMDh2nHU7CypYNLmzTda0/L5cNuzmDQi/A4Y27k6eQxLI79wS/11D0AAMNvs6XT6ojVJjJEgTbMy2BT77xBMp09KcpaWV1uc41jQoi0NdUHfjeOO9WWn7AVF7s7n986SithPJGeupBh2PCSP/xxqxAp3eq6wuUV7Wc6MSZIEhA8vHjbfOe/OcW3zmAuKy+nUzAyD2bow8ODaEROFq8AyZ5WBYdEZXGqGxZ61HJV+9HYCJRbTNA0QBA40HWunaKN5dKg/DBKxeCIe09Th/m4MJwiMSZmLEzMQAABQRuNqgu8NYX3doTcMpvCkLbtQZ2AJkrPOZG1zlnY13T+Hy9EehY90h57eqcorcZ/lctZuMzAsOjLEqwNv66/6vZcPYRBC+C3cGaBxhSet2av1BpYgTTY7k5y2JPT41slIR6Axv8R9nnOs+4Pf+2r992uOxGVJwgAAAEINfgt3BGgsESWtWas1iGDyl+CT/u7WpvxNFRc4x7qtBoZFhSFejb7z1fq9NYfjsiT+cwcQavBruCOgU4SIGo18amuoq3Js3FNlynVtH385+s53ze+t8cRkURx3yMTTRBAEQVAUXbFlf3XystJKA2NExeFBdWASDAAA+MQACCEEmqbJ0b6PMC7JwhDU8YFHV5u9NZ64LErT/oW/63tPV6uJwmKoOND78u7Fg5NhAAD4CVbzY9cwrWQrAAAAAElFTkSuQmCC",
        onclick: function(e) {
            //console.log( xEditorAdd.getContent() );
            //console.log( xEditorAdd.getBody().innerText )
            let sText = xEditorAdd.getBody().innerText;
            let iframeElement;
            if (typeof xEditorAdd.iframeElement !== "undefined" && typeof xEditorAdd.iframeElement.id !== "undefined") {
                iframeElement = xEditorAdd.iframeElement.id;
            } else if (typeof xEditorAdd.editorId !== "undefined") {
                iframeElement = xEditorAdd.editorId + "_ifr";
            }

            sendToGrammalecte({ sTextToParse: sText, iframe: iframeElement });
        }
    });
}

function TinyInPage() {
    for (var i = tinyMCE.editors.length - 1; i > -1; i--) {
        let idTiny = tinyMCE.editors[i].id;
        if (typeof tinyMCE.editors[i].settings.Grammalecte === "undefined") {
            TinyIDInPage(idTiny);
        }
    }
}

function TinyIDInPage(idTiny) {
    if (tinyMCE.majorVersion >= 4) {
        tinyMCE.EditorManager.execCommand("mceFocus", true, idTiny);
        tinyMCE.EditorManager.execCommand("mceRemoveEditor", true, idTiny);
        tinyMCE.EditorManager.execCommand("mceAddEditor", false, idTiny);
    } else if (tinyMCE.majorVersion >= 3) {
        tinyMCE.execCommand("mceFocus", false, idTiny);
        tinyMCE.execCommand("mceRemoveControl", true, idTiny);
        tinyMCE.execCommand("mceAddControl", false, idTiny);
    }
}

if (typeof tinyMCE !== "undefined" && tinyMCE.majorVersion && tinyMCE.majorVersion >= 3 && tinyMCE.majorVersion <= 5) {
    //console.log("Have TinyMCE");
    if (tinyMCE.majorVersion >= 4) {
        tinyMCE.on("AddEditor", TinyOnEditor);
>
>
>
>
>
>
|
|
<
|


|
|
|

|

|
|

|
|
|

|





|
|
|
|

|
|
|

|

<
|
|

|


|











|


<


|


|


|



|

<
|
|

|
|

|
|
|
|

|







|











|

|
|
|







<





|
|
|

|




|

|
|
|

|
|
|







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
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
147
148
149
// Injected script into web page

"use strict";


function uniqueID () {
    let nMin = Math.ceil(0);
    let nMax = Math.floor(9999999);

    return Date.now().toString(36) + "-" + (Math.floor(Math.random() * (nMax - nMin)) + nMin).toString(36);
}

// ! Ecoute des messages venant du content-script
let sBrowserURL;
document.addEventListener("GrammalecteToPage", function respListener (event) {
    //console.log(event);
    let oData = JSON.parse(event.detail);
    // Message envoyer dès que le script est injecté
    if (typeof oData.init !== "undefined") {
        sBrowserURL = oData.init;
    }
    if (typeof oData.tiny !== "undefined") {
        //console.log('Detect Tiny', oData.tiny);
        TinyIDInPage(oData.tiny);
    }
    //console.log("GrammalecteToPage", oData);
});

// ! Permet d'envoyer des message vers le content script
// Retourne un identifiant unique au cas ou si besoin
// La ID unique peut être util si on permet d'intérogé grammalecte sans zone
function sendToGrammalecte (oDataAction) {
    let oDataToSend = oDataAction;
    if (typeof oDataToSend.sActionId === "undefined") {
        oDataToSend.sActionId = uniqueID();
    }
    if (oDataAction.elm) {
        if (!oDataAction.elm.id) {
            oDataAction.elm.id = uniqueID();
        }
        oDataToSend.elm = oDataAction.elm.id;
    }

    //console.log('oDataToSend', oDataToSend);
    let eventGrammalecte = new CustomEvent("GrammalecteEvent", { detail: JSON.stringify(oDataToSend) });
    document.dispatchEvent(eventGrammalecte);
    return oDataToSend.sActionId;
}

// ! Envoie de linformation que l'injection est bien faite ;)
// (peut être lu aussi bien par la page web que le content script)
var customAPILoaded = new CustomEvent("GLInjectedScriptIsReady");
document.dispatchEvent(customAPILoaded);

// Gros Hack : Auto add a button in tinymce ;)

// Page to test v4 https://www.quackit.com/html/html_editors/tinymce_editor.cfm
// https://www.responsivefilemanager.com/demo.php

// Page to test v3 http://www.imathas.com/editordemo/demo.html

function TinyOnEditor (event, editor=null) {
    let xEditorAdd = editor || event.editor;
    //console.log(xEditorAdd);

    if (typeof xEditorAdd.settings.Grammalecte === "undefined") {
        let aBtn;
        let cPlugSep;
        let bIsAdded = false;
        if (tinyMCE.majorVersion >= 4) {
            cPlugSep = " ";
            aBtn = ["toolbar3", "toolbar2", "toolbar1", "toolbar"];
        } else if (tinyMCE.majorVersion >= 3) {
            cPlugSep = ",";
            aBtn = ["theme_advanced_buttons3", "theme_advanced_buttons2", "theme_advanced_buttons1", "theme_advanced_buttons1_add_before"];
        }

        let sBtn;
        let iBtn = 0;

        for (sBtn of aBtn) {
            if (!bIsAdded && (typeof xEditorAdd.settings[sBtn] !== "undefined" || iBtn == aBtn.length)) {
                bIsAdded = true;
                if (typeof xEditorAdd.settings[sBtn] !== "undefined" && xEditorAdd.settings[sBtn] !== "") {
                    xEditorAdd.settings[sBtn] = (xEditorAdd.settings[sBtn] + cPlugSep + "Grammalecte").trim();
                } else {
                    let m = /(.*)([0-9])/.exec(sBtn);
                    if (m.length === 3 && parseInt(m[2]) > 1 && xEditorAdd.settings[sBtn] === "") {
                        sBtn = m[1] + (parseInt(m[2]) - 1);
                        xEditorAdd.settings[sBtn] = (xEditorAdd.settings[sBtn] + cPlugSep + "Grammalecte").trim();
                    } else {
                        xEditorAdd.settings[sBtn] = "Grammalecte";
                    }
                }
            }
            iBtn++;
        }
        if (!bIsAdded) {
            //Valeur par defaut
            xEditorAdd.settings[sBtn] =
                "undo redo | styleselect | bold italic | alignleft" +
                " aligncenter alignright alignjustify | " +
                " bullist numlist outdent indent | link image" +
                " Grammalecte";
        }
        xEditorAdd.settings["Grammalecte"] = true;
    }

    xEditorAdd.addButton("Grammalecte", {
        text: "",
        icon: false,
        image: sBrowserURL + "img/logo-16.png",
        //"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAC8UlEQVQ4jX3TbUgTcRwH8P89ddu5u9tt082aZmpFEU4tFz0QGTUwCi0heniR9MSUIKRaD0RvIlKigsooo+iNFa0XJYuwIjEK19OcDtPElsG0ktyp591t7u7+vUh7MPX3+vf5/n8/+P0BmKJIPUUVlh2rdVVeesWlzEybqg+bFOsoylnqPmNavGFfknV2Omu2Lvja3vxAURKJib3opHizu8riLK6gjRyuKgmoSoMRFENRUqfXTzvBGK62LC2uoFkOl4RhjQ8+qWt7dPNE3sbdp+2LXbsGe9qb4rIo/BfwFy6nWQ4ThWGNDzbcfu29dMDh2nHU7CypYNLmzTda0/L5cNuzmDQi/A4Y27k6eQxLI79wS/11D0AAMNvs6XT6ojVJjJEgTbMy2BT77xBMp09KcpaWV1uc41jQoi0NdUHfjeOO9WWn7AVF7s7n986SithPJGeupBh2PCSP/xxqxAp3eq6wuUV7Wc6MSZIEhA8vHjbfOe/OcW3zmAuKy+nUzAyD2bow8ODaEROFq8AyZ5WBYdEZXGqGxZ61HJV+9HYCJRbTNA0QBA40HWunaKN5dKg/DBKxeCIe09Th/m4MJwiMSZmLEzMQAABQRuNqgu8NYX3doTcMpvCkLbtQZ2AJkrPOZG1zlnY13T+Hy9EehY90h57eqcorcZ/lctZuMzAsOjLEqwNv66/6vZcPYRBC+C3cGaBxhSet2av1BpYgTTY7k5y2JPT41slIR6Axv8R9nnOs+4Pf+2r992uOxGVJwgAAAEINfgt3BGgsESWtWas1iGDyl+CT/u7WpvxNFRc4x7qtBoZFhSFejb7z1fq9NYfjsiT+cwcQavBruCOgU4SIGo18amuoq3Js3FNlynVtH385+s53ze+t8cRkURx3yMTTRBAEQVAUXbFlf3XystJKA2NExeFBdWASDAAA+MQACCEEmqbJ0b6PMC7JwhDU8YFHV5u9NZ64LErT/oW/63tPV6uJwmKoOND78u7Fg5NhAAD4CVbzY9cwrWQrAAAAAElFTkSuQmCC",
        onclick: function (e) {
            //console.log(xEditorAdd.getContent());
            //console.log(xEditorAdd.getBody().innerText);
            let sText = xEditorAdd.getBody().innerText;
            let iframeElement;
            if (typeof xEditorAdd.iframeElement !== "undefined" && typeof xEditorAdd.iframeElement.id !== "undefined") {
                iframeElement = xEditorAdd.iframeElement.id;
            } else if (typeof xEditorAdd.editorId !== "undefined") {
                iframeElement = xEditorAdd.editorId + "_ifr";
            }

            sendToGrammalecte({ sTextToParse: sText, iframe: iframeElement });
        }
    });
}

function TinyInPage () {
    for (let i = tinyMCE.editors.length - 1;  i > -1;  i--) {
        let sTinyId = tinyMCE.editors[i].id;
        if (typeof tinyMCE.editors[i].settings.Grammalecte === "undefined") {
            TinyIDInPage(sTinyId);
        }
    }
}

function TinyIDInPage (sTinyId) {
    if (tinyMCE.majorVersion >= 4) {
        tinyMCE.EditorManager.execCommand("mceFocus", true, sTinyId);
        tinyMCE.EditorManager.execCommand("mceRemoveEditor", true, sTinyId);
        tinyMCE.EditorManager.execCommand("mceAddEditor", false, sTinyId);
    } else if (tinyMCE.majorVersion >= 3) {
        tinyMCE.execCommand("mceFocus", false, sTinyId);
        tinyMCE.execCommand("mceRemoveControl", true, sTinyId);
        tinyMCE.execCommand("mceAddControl", false, sTinyId);
    }
}

if (typeof tinyMCE !== "undefined" && tinyMCE.majorVersion && tinyMCE.majorVersion >= 3 && tinyMCE.majorVersion <= 5) {
    //console.log("Have TinyMCE");
    if (tinyMCE.majorVersion >= 4) {
        tinyMCE.on("AddEditor", TinyOnEditor);

Modified gc_lang/fr/webext/content_scripts/init.js from [324ce24005] to [4d30429eeb].

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
        });
        this.xObserver.observe(document.body, {
            childList: true,
            subtree: true
        });
    },

    rescanPage: function() {
        if (this.oTFPanel !== null) {
            this.oTFPanel.hide();
        }
        if (this.oLxgPanel !== null) {
            this.oLxgPanel.hide();
        }
        if (this.oGCPanel !== null) {
            this.oGCPanel.hide();
        }
        for (let oMenu of this.lMenu) {
            oMenu.deleteNodes();
        }
        this.lMenu.length = 0; // to clear an array
        this.listenRightClick();
        this.createMenus();
    },

    createTFPanel: function() {
        if (this.oTFPanel === null) {
            this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 615, false);
            //this.oTFPanel.logInnerHTML();
            this.oTFPanel.insertIntoPage();
            window.setTimeout(
                function(self) {
                    self.oTFPanel.adjustHeight();







|

















|







160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
        });
        this.xObserver.observe(document.body, {
            childList: true,
            subtree: true
        });
    },

    rescanPage: function () {
        if (this.oTFPanel !== null) {
            this.oTFPanel.hide();
        }
        if (this.oLxgPanel !== null) {
            this.oLxgPanel.hide();
        }
        if (this.oGCPanel !== null) {
            this.oGCPanel.hide();
        }
        for (let oMenu of this.lMenu) {
            oMenu.deleteNodes();
        }
        this.lMenu.length = 0; // to clear an array
        this.listenRightClick();
        this.createMenus();
    },

    createTFPanel: function () {
        if (this.oTFPanel === null) {
            this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 615, false);
            //this.oTFPanel.logInnerHTML();
            this.oTFPanel.insertIntoPage();
            window.setTimeout(
                function(self) {
                    self.oTFPanel.adjustHeight();
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
        this.createGCPanel();
        this.oGCPanel.clear();
        this.oGCPanel.show();
        this.oGCPanel.start(xNode);
        this.oGCPanel.startWaitIcon();
    },

    startLxgPanel: function() {
        this.createLxgPanel();
        this.oLxgPanel.clear();
        this.oLxgPanel.show();
        this.oLxgPanel.startWaitIcon();
    },

    startFTPanel: function (xNode = null) {







|







222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
        this.createGCPanel();
        this.oGCPanel.clear();
        this.oGCPanel.show();
        this.oGCPanel.start(xNode);
        this.oGCPanel.startWaitIcon();
    },

    startLxgPanel: function () {
        this.createLxgPanel();
        this.oLxgPanel.clear();
        this.oLxgPanel.show();
        this.oLxgPanel.startWaitIcon();
    },

    startFTPanel: function (xNode = null) {
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
        let nPos = sPageText.indexOf("__grammalecte_panel__");
        if (nPos >= 0) {
            sPageText = sPageText.slice(0, nPos);
        }
        return sPageText;
    },

    createNode: function(sType, oAttr, oDataset=null) {
        try {
            let xNode = document.createElement(sType);
            Object.assign(xNode, oAttr);
            if (oDataset) {
                Object.assign(xNode.dataset, oDataset);
            }
            return xNode;







|







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
        let nPos = sPageText.indexOf("__grammalecte_panel__");
        if (nPos >= 0) {
            sPageText = sPageText.slice(0, nPos);
        }
        return sPageText;
    },

    createNode: function (sType, oAttr, oDataset=null) {
        try {
            let xNode = document.createElement(sType);
            Object.assign(xNode, oAttr);
            if (oDataset) {
                Object.assign(xNode.dataset, oDataset);
            }
            return xNode;
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
let bInjectedScriptReady = false;
let lBufferMsg = [];

// ! Permet d’envoyer des messages vers le script injecté
// (peut aussi être lu par un script sur la page web)
function sendToWebpage (oDataAction) {
    let oDataToSend = oDataAction;
    if (typeof oDataToSend.IdAction === "undefined") {
        oDataToSend.IdAction = uniqueID();
    }
    if (oDataAction.elm) {
        if (!oDataAction.elm.id) {
            oDataAction.elm.id = uniqueID();
        }
        oDataToSend.elm = oDataAction.elm.id;
    }

    if (!bInjectedScriptReady) {
        lBufferMsg.push(oDataToSend);
    } else {
        //console.log('sendToWebpage', oDataToSend);
        let eventGrammalecte = new CustomEvent("GrammalecteToPage", { detail: JSON.stringify(oDataToSend) });
        document.dispatchEvent(eventGrammalecte);
    }

    return oDataToSend.IdAction;
}

// ! Les messages ne peuvent être envoyés qu’après l’injection du script
document.addEventListener("GLInjectedScriptIsReady", function () {
    //console.log("GLInjectedScriptIsReady EXT");
    bInjectedScriptReady = true;
    if (lBufferMsg.length > 0) {







|
|
















|







464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
let bInjectedScriptReady = false;
let lBufferMsg = [];

// ! Permet d’envoyer des messages vers le script injecté
// (peut aussi être lu par un script sur la page web)
function sendToWebpage (oDataAction) {
    let oDataToSend = oDataAction;
    if (typeof oDataToSend.sActionId === "undefined") {
        oDataToSend.sActionId = uniqueID();
    }
    if (oDataAction.elm) {
        if (!oDataAction.elm.id) {
            oDataAction.elm.id = uniqueID();
        }
        oDataToSend.elm = oDataAction.elm.id;
    }

    if (!bInjectedScriptReady) {
        lBufferMsg.push(oDataToSend);
    } else {
        //console.log('sendToWebpage', oDataToSend);
        let eventGrammalecte = new CustomEvent("GrammalecteToPage", { detail: JSON.stringify(oDataToSend) });
        document.dispatchEvent(eventGrammalecte);
    }

    return oDataToSend.sActionId;
}

// ! Les messages ne peuvent être envoyés qu’après l’injection du script
document.addEventListener("GLInjectedScriptIsReady", function () {
    //console.log("GLInjectedScriptIsReady EXT");
    bInjectedScriptReady = true;
    if (lBufferMsg.length > 0) {