Index: gc_lang/fr/mailext/background.js ================================================================== --- gc_lang/fr/mailext/background.js +++ gc_lang/fr/mailext/background.js @@ -16,14 +16,14 @@ this.xGCEWorker.onmessage = function (e) { // Messages received from the Worker // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent try { this.nLastTimeWorkerResponse = Date.now(); - let {sActionDone, result, dInfo, bEnd, bError} = e.data; + let {sActionDone, result, oInfo, bEnd, bError} = e.data; if (bError) { console.log(result); - console.log(dInfo); + console.log(oInfo); return; } switch (sActionDone) { case "init": storeGCOptions(result); @@ -34,12 +34,12 @@ case "parseFull": case "getListOfTokens": case "getSpellSuggestions": case "getVerb": // send result to content script - if (typeof(dInfo.iReturnPort) === "number") { - let xPort = dConnx.get(dInfo.iReturnPort); + if (typeof(oInfo.iReturnPort) === "number") { + let xPort = dConnx.get(oInfo.iReturnPort); xPort.postMessage(e.data); } else { console.log("[background] don’t know where to send results"); console.log(e.data); } @@ -139,12 +139,12 @@ console.log("# Error: the saved options was an empty object."); dOptions = null; } oWorkerHandler.xGCEWorker.postMessage({ sCommand: "init", - dParam: {sExtensionPath: browser.extension.getURL(""), dOptions: dOptions, sContext: "Firefox"}, - dInfo: {} + oParam: {sExtensionPath: browser.extension.getURL(""), dOptions: dOptions, sContext: "Firefox"}, + oInfo: {} }); } catch (e) { console.log("initGrammarChecker failed"); showError(e); @@ -151,28 +151,28 @@ } }, _setSpellingDictionaries: function (oData) { if (oData.hasOwnProperty("community_dictionary")) { - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "community", oDict: oData["community_dictionary"] }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", oParam: { sDictionary: "community", oDict: oData["community_dictionary"] }, oInfo: {} }); } if (oData.hasOwnProperty("personal_dictionary")) { - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "personal", oDict: oData["personal_dictionary"] }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", oParam: { sDictionary: "personal", oDict: oData["personal_dictionary"] }, oInfo: {} }); } }, _initSCOptions: function (oData) { if (!oData.hasOwnProperty("sc_options")) { browser.storage.local.set({"sc_options": { community: true, personal: true }}); - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "community", bActivate: true }, dInfo: {} }); - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "personal", bActivate: true }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", oParam: { sDictionary: "community", bActivate: true }, oInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", oParam: { sDictionary: "personal", bActivate: true }, oInfo: {} }); } else { - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "community", bActivate: oData.sc_options["community"] }, dInfo: {} }); - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "personal", bActivate: oData.sc_options["personal"] }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", oParam: { sDictionary: "community", bActivate: oData.sc_options["community"] }, oInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", oParam: { sDictionary: "personal", bActivate: oData.sc_options["personal"] }, oInfo: {} }); } } } // start the Worker for the GC Index: gc_lang/fr/mailext/content/lex_editor.js ================================================================== --- gc_lang/fr/mailext/content/lex_editor.js +++ gc_lang/fr/mailext/content/lex_editor.js @@ -474,11 +474,11 @@ let oDAWG = new DAWG(lEntry, "S", "fr", "Français", "fr.personal", "Dictionnaire personnel", xProgressNode); let oJSON = oDAWG.createBinaryJSON(1); oFileHandler.saveFile("fr.personal.json", JSON.stringify(oJSON)); this.oIBDAWG = new IBDAWG(oJSON); this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate); - //browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sType: "personal", oDict: oJSON}, dInfo: {} }); + //browser.runtime.sendMessage({ sCommand: "setDictionary", oParam: {sType: "personal", oDict: oJSON}, oInfo: {} }); enableElement("export_button"); } else { oFileHandler.deleteFile("fr.personal.json"); this.setDictData(0, "[néant]"); disableElement("export_button"); Index: gc_lang/fr/mailext/gce_worker.js ================================================================== --- gc_lang/fr/mailext/gce_worker.js +++ gc_lang/fr/mailext/gce_worker.js @@ -56,15 +56,15 @@ for we need the path of the extension to load data stored in JSON files. This path is retrieved in background.js and passed with the event “init”. */ -function createResponse (sActionDone, result, dInfo, bEnd, bError=false) { +function createResponse (sActionDone, result, oInfo, bEnd, bError=false) { return { "sActionDone": sActionDone, "result": result, // can be of any type - "dInfo": dInfo, + "oInfo": oInfo, "bEnd": bEnd, "bError": bError }; } @@ -87,62 +87,62 @@ /* Message Event Object https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent */ onmessage = function (e) { - let {sCommand, dParam, dInfo} = e.data; + let {sCommand, oParam, oInfo} = e.data; switch (sCommand) { case "init": - init(dParam.sExtensionPath, dParam.dOptions, dParam.sContext, dInfo); + init(oParam.sExtensionPath, oParam.dOptions, oParam.sContext, oInfo); break; case "parse": - parse(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + parse(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "parseAndSpellcheck": - parseAndSpellcheck(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + parseAndSpellcheck(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "parseAndSpellcheck1": - parseAndSpellcheck1(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + parseAndSpellcheck1(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "parseFull": - parseFull(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + parseFull(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "getListOfTokens": - getListOfTokens(dParam.sText, dInfo); + getListOfTokens(oParam.sText, oInfo); break; case "getOptions": - getOptions(dInfo); + getOptions(oInfo); break; case "getDefaultOptions": - getDefaultOptions(dInfo); + getDefaultOptions(oInfo); break; case "setOptions": - setOptions(dParam.sOptions, dInfo); + setOptions(oParam.sOptions, oInfo); break; case "setOption": - setOption(dParam.sOptName, dParam.bValue, dInfo); + setOption(oParam.sOptName, oParam.bValue, oInfo); break; case "resetOptions": - resetOptions(dInfo); + resetOptions(oInfo); break; case "textToTest": - textToTest(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + textToTest(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "fullTests": - fullTests(dInfo); + fullTests(oInfo); break; case "setDictionary": - setDictionary(dParam.sDictionary, dParam.oDict, dInfo); + setDictionary(oParam.sDictionary, oParam.oDict, oInfo); break; case "setDictionaryOnOff": - setDictionaryOnOff(dParam.sDictionary, dParam.bActivate, dInfo); + setDictionaryOnOff(oParam.sDictionary, oParam.bActivate, oInfo); break; case "getSpellSuggestions": - getSpellSuggestions(dParam.sWord, dInfo); + getSpellSuggestions(oParam.sWord, oInfo); break; case "getVerb": - getVerb(dParam.sVerb, dParam.bPro, dParam.bNeg, dParam.bTpsCo, dParam.bInt, dParam.bFem, dInfo); + getVerb(oParam.sVerb, oParam.bPro, oParam.bNeg, oParam.bTpsCo, oParam.bInt, oParam.bFem, oInfo); break; default: console.log("[Worker] Unknown command: " + sCommand); showData(e.data); } @@ -166,11 +166,11 @@ The answer is received by the background in another function (onmessage). That’s why the full text to analyze is send in one block, but analyse is returned paragraph by paragraph. */ -function init (sExtensionPath, dOptions=null, sContext="JavaScript", dInfo={}) { +function init (sExtensionPath, dOptions=null, sContext="JavaScript", oInfo={}) { try { if (!bInitDone) { console.log("[Worker] Loading… Extension path: " + sExtensionPath); conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json")); phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json")); @@ -193,108 +193,108 @@ } else { console.log("[Worker] Already initialized…") } // we always retrieve options from the gc_engine, for setOptions filters obsolete options dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("init", dOptions, dInfo, true)); - } - catch (e) { - console.error(e); - postMessage(createResponse("init", createErrorResult(e, "init failed"), dInfo, true, true)); - } -} - - -function parse (sText, sCountry, bDebug, bContext, dInfo={}) { - sText = sText.replace(/­/g, "").normalize("NFC"); - for (let sParagraph of text.getParagraph(sText)) { - let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, bContext); - postMessage(createResponse("parse", aGrammErr, dInfo, false)); - } - postMessage(createResponse("parse", null, dInfo, true)); -} - -function parseAndSpellcheck (sText, sCountry, bDebug, bContext, dInfo={}) { - let i = 0; - sText = sText.replace(/­/g, "").normalize("NFC"); - for (let sParagraph of text.getParagraph(sText)) { - let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); - let aSpellErr = oSpellChecker.parseParagraph(sParagraph); - postMessage(createResponse("parseAndSpellcheck", {sParagraph: sParagraph, iParaNum: i, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, dInfo, false)); - i += 1; - } - postMessage(createResponse("parseAndSpellcheck", null, dInfo, true)); -} - -function parseAndSpellcheck1 (sParagraph, sCountry, bDebug, bContext, dInfo={}) { - sParagraph = sParagraph.replace(/­/g, "").normalize("NFC"); - let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); - let aSpellErr = oSpellChecker.parseParagraph(sParagraph); - postMessage(createResponse("parseAndSpellcheck1", {sParagraph: sParagraph, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, dInfo, true)); -} - -function parseFull (sText, sCountry, bDebug, bContext, dInfo={}) { - let i = 0; - sText = sText.replace(/­/g, "").normalize("NFC"); - for (let sParagraph of text.getParagraph(sText)) { - let lSentence = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext, true); - console.log("*", lSentence); - postMessage(createResponse("parseFull", {sParagraph: sParagraph, iParaNum: i, lSentence: lSentence}, dInfo, false)); - i += 1; - } - postMessage(createResponse("parseFull", null, dInfo, true)); -} - -function getListOfTokens (sText, dInfo={}) { + postMessage(createResponse("init", dOptions, oInfo, true)); + } + catch (e) { + console.error(e); + postMessage(createResponse("init", createErrorResult(e, "init failed"), oInfo, true, true)); + } +} + + +function parse (sText, sCountry, bDebug, bContext, oInfo={}) { + sText = sText.replace(/­/g, "").normalize("NFC"); + for (let sParagraph of text.getParagraph(sText)) { + let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, bContext); + postMessage(createResponse("parse", aGrammErr, oInfo, false)); + } + postMessage(createResponse("parse", null, oInfo, true)); +} + +function parseAndSpellcheck (sText, sCountry, bDebug, bContext, oInfo={}) { + let i = 0; + sText = sText.replace(/­/g, "").normalize("NFC"); + for (let sParagraph of text.getParagraph(sText)) { + let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); + let aSpellErr = oSpellChecker.parseParagraph(sParagraph); + postMessage(createResponse("parseAndSpellcheck", {sParagraph: sParagraph, iParaNum: i, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, oInfo, false)); + i += 1; + } + postMessage(createResponse("parseAndSpellcheck", null, oInfo, true)); +} + +function parseAndSpellcheck1 (sParagraph, sCountry, bDebug, bContext, oInfo={}) { + sParagraph = sParagraph.replace(/­/g, "").normalize("NFC"); + let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); + let aSpellErr = oSpellChecker.parseParagraph(sParagraph); + postMessage(createResponse("parseAndSpellcheck1", {sParagraph: sParagraph, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, oInfo, true)); +} + +function parseFull (sText, sCountry, bDebug, bContext, oInfo={}) { + let i = 0; + sText = sText.replace(/­/g, "").normalize("NFC"); + for (let sParagraph of text.getParagraph(sText)) { + let lSentence = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext, true); + console.log("*", lSentence); + postMessage(createResponse("parseFull", {sParagraph: sParagraph, iParaNum: i, lSentence: lSentence}, oInfo, false)); + i += 1; + } + postMessage(createResponse("parseFull", null, oInfo, true)); +} + +function getListOfTokens (sText, oInfo={}) { // lexicographer try { sText = sText.replace(/­/g, "").normalize("NFC"); for (let sParagraph of text.getParagraph(sText)) { if (sParagraph.trim() !== "") { - postMessage(createResponse("getListOfTokens", oLxg.getListOfTokensReduc(sParagraph, true), dInfo, false)); + postMessage(createResponse("getListOfTokens", oLxg.getListOfTokensReduc(sParagraph, true), oInfo, false)); } } - postMessage(createResponse("getListOfTokens", null, dInfo, true)); + postMessage(createResponse("getListOfTokens", null, oInfo, true)); } catch (e) { console.error(e); - postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), dInfo, true, true)); + postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), oInfo, true, true)); } } -function getOptions (dInfo={}) { +function getOptions (oInfo={}) { let dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("getOptions", dOptions, dInfo, true)); + postMessage(createResponse("getOptions", dOptions, oInfo, true)); } -function getDefaultOptions (dInfo={}) { +function getDefaultOptions (oInfo={}) { let dOptions = helpers.mapToObject(gc_engine.getDefaultOptions()); - postMessage(createResponse("getDefaultOptions", dOptions, dInfo, true)); + postMessage(createResponse("getDefaultOptions", dOptions, oInfo, true)); } -function setOptions (dOptions, dInfo={}) { +function setOptions (dOptions, oInfo={}) { if (!(dOptions instanceof Map)) { dOptions = helpers.objectToMap(dOptions); } gc_engine.setOptions(dOptions); dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("setOptions", dOptions, dInfo, true)); + postMessage(createResponse("setOptions", dOptions, oInfo, true)); } -function setOption (sOptName, bValue, dInfo={}) { +function setOption (sOptName, bValue, oInfo={}) { console.log(sOptName+": "+bValue); if (sOptName) { gc_engine.setOption(sOptName, bValue); let dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("setOption", dOptions, dInfo, true)); + postMessage(createResponse("setOption", dOptions, oInfo, true)); } } -function resetOptions (dInfo={}) { +function resetOptions (oInfo={}) { gc_engine.resetOptions(); let dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("resetOptions", dOptions, dInfo, true)); + postMessage(createResponse("resetOptions", dOptions, oInfo, true)); } function tests () { console.log(conj.getConj("devenir", ":E", ":2s")); console.log(mfsp.getMasForm("emmerdeuse", true)); @@ -304,13 +304,13 @@ for (let oErr of aRes) { console.log(text.getReadableError(oErr)); } } -function textToTest (sText, sCountry, bDebug, bContext, dInfo={}) { +function textToTest (sText, sCountry, bDebug, bContext, oInfo={}) { if (!gc_engine) { - postMessage(createResponse("textToTest", "# Grammar checker not loaded.", dInfo, true)); + postMessage(createResponse("textToTest", "# Grammar checker not loaded.", oInfo, true)); return; } sText = sText.replace(/­/g, "").normalize("NFC"); let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext); let sMsg = ""; @@ -318,16 +318,16 @@ sMsg += text.getReadableError(oErr) + "\n"; } if (sMsg == "") { sMsg = "Aucune erreur détectée."; } - postMessage(createResponse("textToTest", sMsg, dInfo, true)); + postMessage(createResponse("textToTest", sMsg, oInfo, true)); } -function fullTests (dInfo={}) { +function fullTests (oInfo={}) { if (!gc_engine) { - postMessage(createResponse("fullTests", "# Grammar checker not loaded.", dInfo, true)); + postMessage(createResponse("fullTests", "# Grammar checker not loaded.", oInfo, true)); return; } let dMemoOptions = gc_engine.getOptions(); let dTestOptions = gc_engine.getDefaultOptions(); dTestOptions.set("nbsp", true); @@ -339,25 +339,25 @@ for (let sRes of oTest.testParse()) { sMsg += sRes + "\n"; console.log(sRes); } gc_engine.setOptions(dMemoOptions); - postMessage(createResponse("fullTests", sMsg, dInfo, true)); + postMessage(createResponse("fullTests", sMsg, oInfo, true)); } // SpellChecker -function setDictionary (sDictionary, oDict, dInfo) { +function setDictionary (sDictionary, oDict, oInfo) { if (!oSpellChecker) { - postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", dInfo, true)); + postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", oInfo, true)); return; } //console.log("setDictionary", sDictionary); switch (sDictionary) { case "main": - oSpellChecker.setMainDictionary(oDict, dInfo["sExtPath"]+"/grammalecte/graphspell/_dictionaries"); + oSpellChecker.setMainDictionary(oDict, oInfo["sExtPath"]+"/grammalecte/graphspell/_dictionaries"); break; case "community": oSpellChecker.setCommunityDictionary(oDict); break; case "personal": @@ -364,16 +364,16 @@ oSpellChecker.setPersonalDictionary(oDict); break; default: console.log("[worker] setDictionary: Unknown dictionary <"+sDictionary+">"); } - postMessage(createResponse("setDictionary", true, dInfo, true)); + postMessage(createResponse("setDictionary", true, oInfo, true)); } -function setDictionaryOnOff (sDictionary, bActivate, dInfo) { +function setDictionaryOnOff (sDictionary, bActivate, oInfo) { if (!oSpellChecker) { - postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", dInfo, true)); + postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", oInfo, true)); return; } //console.log("setDictionaryOnOff", sDictionary, bActivate); switch (sDictionary) { case "community": @@ -391,38 +391,38 @@ } break; default: console.log("[worker] setDictionaryOnOff: Unknown dictionary <"+sDictionary+">"); } - postMessage(createResponse("setDictionaryOnOff", true, dInfo, true)); + postMessage(createResponse("setDictionaryOnOff", true, oInfo, true)); } -function getSpellSuggestions (sWord, dInfo) { +function getSpellSuggestions (sWord, oInfo) { if (!oSpellChecker) { - postMessage(createResponse("getSpellSuggestions", "# Error. SpellChecker not loaded.", dInfo, true)); + postMessage(createResponse("getSpellSuggestions", "# Error. SpellChecker not loaded.", oInfo, true)); return; } let i = 0; for (let aSugg of oSpellChecker.suggest(sWord)) { - postMessage(createResponse("getSpellSuggestions", {sWord: sWord, aSugg: aSugg, iSuggBlock: i}, dInfo, true)); + postMessage(createResponse("getSpellSuggestions", {sWord: sWord, aSugg: aSugg, iSuggBlock: i}, oInfo, true)); i += 1; } } // Conjugueur -function getVerb (sWord, bPro, bNeg, bTpsCo, bInt, bFem, dInfo) { +function getVerb (sWord, bPro, bNeg, bTpsCo, bInt, bFem, oInfo) { try { let oVerb = null; let oConjTable = null; if (conj.isVerb(sWord)) { oVerb = new Verb(sWord); oConjTable = oVerb.createConjTable(bPro, bNeg, bTpsCo, bInt, bFem); } - postMessage(createResponse("getVerb", { oVerb: oVerb, oConjTable: oConjTable }, dInfo, true)); + postMessage(createResponse("getVerb", { oVerb: oVerb, oConjTable: oConjTable }, oInfo, true)); } catch (e) { console.error(e); - postMessage(createResponse("getVerb", createErrorResult(e, "no verb"), dInfo, true, true)); + postMessage(createResponse("getVerb", createErrorResult(e, "no verb"), oInfo, true, true)); } } Index: gc_lang/fr/tb/content/lex_editor.js ================================================================== --- gc_lang/fr/tb/content/lex_editor.js +++ gc_lang/fr/tb/content/lex_editor.js @@ -481,11 +481,11 @@ let oDAWG = new DAWG(lEntry, "S", "fr", "Français", "fr.personal", "Dictionnaire personnel", xProgressNode); let oJSON = oDAWG.createBinaryJSON(1); oFileHandler.saveFile("fr.personal.json", JSON.stringify(oJSON)); this.oIBDAWG = new IBDAWG(oJSON); this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate); - //browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sType: "personal", oDict: oJSON}, dInfo: {} }); + //browser.runtime.sendMessage({ sCommand: "setDictionary", oParam: {sType: "personal", oDict: oJSON}, oInfo: {} }); enableElement("export_button"); } else { oFileHandler.deleteFile("fr.personal.json"); this.setDictData(0, "[néant]"); disableElement("export_button"); Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -28,14 +28,14 @@ this.xGCEWorker.onmessage = function (e) { // Messages received from the Worker // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent try { this.nLastTimeWorkerResponse = Date.now(); - let {sActionDone, result, dInfo, bEnd, bError} = e.data; + let {sActionDone, result, oInfo, bEnd, bError} = e.data; if (bError) { console.log(result); - console.log(dInfo); + console.log(oInfo); return; } switch (sActionDone) { case "init": storeGCOptions(result); @@ -46,12 +46,12 @@ case "parseFull": case "getListOfTokens": case "getSpellSuggestions": case "getVerb": // send result to content script - if (typeof(dInfo.iReturnPort) === "number") { - let xPort = dConnx.get(dInfo.iReturnPort); + if (typeof(oInfo.iReturnPort) === "number") { + let xPort = dConnx.get(oInfo.iReturnPort); xPort.postMessage(e.data); } else { console.log("[background] don’t know where to send results"); console.log(e.data); } @@ -167,12 +167,12 @@ console.log("# Error: the saved options was an empty object."); dOptions = null; } oWorkerHandler.xGCEWorker.postMessage({ sCommand: "init", - dParam: {sExtensionPath: browser.extension.getURL(""), dOptions: dOptions, sContext: "Firefox"}, - dInfo: {} + oParam: {sExtensionPath: browser.extension.getURL(""), dOptions: dOptions, sContext: "Firefox"}, + oInfo: {} }); } catch (e) { console.log("initGrammarChecker failed"); showError(e); @@ -182,35 +182,35 @@ _setSpellingDictionaries: function (oData) { if (oData.hasOwnProperty("oPersonalDictionary")) { // deprecated (to be removed in 2020) console.log("personal dictionary migration"); browser.storage.local.set({ "personal_dictionary": oData["oPersonalDictionary"] }); - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "personal", oDict: oData["oPersonalDictionary"] }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", oParam: { sDictionary: "personal", oDict: oData["oPersonalDictionary"] }, oInfo: {} }); browser.storage.local.remove("oPersonalDictionary"); } if (oData.hasOwnProperty("main_dic_name")) { - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "main", oDict: oData["main_dic_name"] }, dInfo: {sExtPath: browser.extension.getURL("")} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", oParam: { sDictionary: "main", oDict: oData["main_dic_name"] }, oInfo: {sExtPath: browser.extension.getURL("")} }); } if (oData.hasOwnProperty("community_dictionary")) { - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "community", oDict: oData["community_dictionary"] }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", oParam: { sDictionary: "community", oDict: oData["community_dictionary"] }, oInfo: {} }); } if (oData.hasOwnProperty("personal_dictionary")) { - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "personal", oDict: oData["personal_dictionary"] }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", oParam: { sDictionary: "personal", oDict: oData["personal_dictionary"] }, oInfo: {} }); } }, _initSCOptions: function (oData) { if (!oData.hasOwnProperty("sc_options")) { browser.storage.local.set({"sc_options": { community: true, personal: true }}); - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "community", bActivate: true }, dInfo: {} }); - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "personal", bActivate: true }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", oParam: { sDictionary: "community", bActivate: true }, oInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", oParam: { sDictionary: "personal", bActivate: true }, oInfo: {} }); } else { - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "community", bActivate: oData.sc_options["community"] }, dInfo: {} }); - oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "personal", bActivate: oData.sc_options["personal"] }, dInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", oParam: { sDictionary: "community", bActivate: oData.sc_options["community"] }, oInfo: {} }); + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", oParam: { sDictionary: "personal", bActivate: oData.sc_options["personal"] }, oInfo: {} }); } } } // start the Worker for the GC @@ -244,11 +244,11 @@ Messages from the extension (not the Worker) */ function handleMessage (oRequest, xSender, sendResponse) { // message from panels //console.log(xSender); - let {sCommand, dParam, dInfo} = oRequest; + let {sCommand, oParam, oInfo} = oRequest; switch (sCommand) { case "getOptions": case "getDefaultOptions": case "setOptions": case "setOption": @@ -258,20 +258,20 @@ case "setDictionary": case "setDictionaryOnOff": oWorkerHandler.xGCEWorker.postMessage(oRequest); break; case "restartWorker": - oWorkerHandler.restart(dParam["nDelayLimit"]); + oWorkerHandler.restart(oParam["nDelayLimit"]); break; case "openURL": - browser.tabs.create({url: dParam.sURL}); + browser.tabs.create({url: oParam.sURL}); break; case "openConjugueurTab": openConjugueurTab(); break; case "openLexiconEditor": - openLexiconEditor(dParam["dictionary"]); + openLexiconEditor(oParam["dictionary"]); break; case "openDictionaries": openDictionaries(); break; default: @@ -287,27 +287,27 @@ function handleConnexion (xPort) { // Messages from tabs let iPortId = xPort.sender.tab.id; // identifier for the port: each port can be found at dConnx[iPortId] dConnx.set(iPortId, xPort); xPort.onMessage.addListener(function (oRequest) { - let {sCommand, dParam, dInfo} = oRequest; + let {sCommand, oParam, oInfo} = oRequest; switch (sCommand) { case "parse": case "parseAndSpellcheck": case "parseAndSpellcheck1": case "parseFull": case "getListOfTokens": case "getSpellSuggestions": case "getVerb": - oRequest.dInfo.iReturnPort = iPortId; // we pass the id of the return port to receive answer + oRequest.oInfo.iReturnPort = iPortId; // we pass the id of the return port to receive answer oWorkerHandler.xGCEWorker.postMessage(oRequest); break; case "restartWorker": - oWorkerHandler.restart(dParam["nDelayLimit"]); + oWorkerHandler.restart(oParam["nDelayLimit"]); break; case "openURL": - browser.tabs.create({url: dParam.sURL}); + browser.tabs.create({url: oParam.sURL}); break; case "openConjugueurTab": openConjugueurTab(); break; case "openConjugueurWindow": @@ -362,12 +362,12 @@ break; case "grammar_checker_selection": sendCommandToTab(xTab.id, xInfo.menuItemId, xInfo.selectionText); oWorkerHandler.xGCEWorker.postMessage({ sCommand: "parseAndSpellcheck", - dParam: {sText: xInfo.selectionText, sCountry: "FR", bDebug: false, bContext: false}, - dInfo: {iReturnPort: xTab.id} + oParam: {sText: xInfo.selectionText, sCountry: "FR", bDebug: false, bContext: false}, + oInfo: {iReturnPort: xTab.id} }); break; // tools case "conjugueur_window": openConjugueurWindow(); @@ -442,11 +442,11 @@ browser.storage.local.set({"gc_options": dOptions}); } function sendCommandToTab (iTab, sCommand, result=null) { let xTabPort = dConnx.get(iTab); - xTabPort.postMessage({sActionDone: sCommand, result: result, dInfo: null, bEnd: false, bError: false}); + xTabPort.postMessage({sActionDone: sCommand, result: result, oInfo: null, bEnd: false, bError: false}); } function sendCommandToCurrentTab (sCommand) { if (bChrome) { browser.tabs.query({ currentWindow: true, active: true }, (lTabs) => { @@ -465,11 +465,11 @@ }, showError); } function sendCommandToAllTabs (sCommand) { for (let [iTab, xTabPort] of dConnx.entries()) { - xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false}); + xTabPort.postMessage({sActionDone: sCommand, result: null, oInfo: null, bEnd: false, bError: false}); } } function openLexiconEditor (sName="__personal__") { if (nTabLexiconEditor === null) { Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -310,96 +310,96 @@ /* Send messages to the background object { sCommand: the action to perform - dParam: parameters necessary for the execution of the action - dInfo: all kind of informations that needs to be sent back (usually to know where to use the result) + oParam: parameters necessary for the execution of the action + oInfo: all kind of informations that needs to be sent back (usually to know where to use the result) } */ parseAndSpellcheck: function (sText, sDestination) { this.xConnect.postMessage({ sCommand: "parseAndSpellcheck", - dParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, - dInfo: { sDestination: sDestination } + oParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, + oInfo: { sDestination: sDestination } }); }, parseAndSpellcheck1: function (sText, sDestination, sParagraphId) { this.xConnect.postMessage({ sCommand: "parseAndSpellcheck1", - dParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, - dInfo: { sDestination: sDestination, sParagraphId: sParagraphId } + oParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, + oInfo: { sDestination: sDestination, sParagraphId: sParagraphId } }); }, getListOfTokens: function (sText) { - this.xConnect.postMessage({ sCommand: "getListOfTokens", dParam: { sText: sText }, dInfo: {} }); + this.xConnect.postMessage({ sCommand: "getListOfTokens", oParam: { sText: sText }, oInfo: {} }); }, parseFull: function (sText) { this.xConnect.postMessage({ sCommand: "parseFull", - dParam: { sText: sTex, sCountry: "FR", bDebug: false, bContext: false }, - dInfo: {} + oParam: { sText: sTex, sCountry: "FR", bDebug: false, bContext: false }, + oInfo: {} }); }, getVerb: function (sVerb, bStart=true, bPro=false, bNeg=false, bTpsCo=false, bInt=false, bFem=false) { this.xConnect.postMessage({ sCommand: "getVerb", - dParam: { sVerb: sVerb, bPro: bPro, bNeg: bNeg, bTpsCo: bTpsCo, bInt: bInt, bFem: bFem }, - dInfo: { bStart: bStart } + oParam: { sVerb: sVerb, bPro: bPro, bNeg: bNeg, bTpsCo: bTpsCo, bInt: bInt, bFem: bFem }, + oInfo: { bStart: bStart } }); }, getSpellSuggestions: function (sWord, sDestination, sErrorId) { - this.xConnect.postMessage({ sCommand: "getSpellSuggestions", dParam: { sWord: sWord }, dInfo: { sDestination: sDestination, sErrorId: sErrorId } }); + this.xConnect.postMessage({ sCommand: "getSpellSuggestions", oParam: { sWord: sWord }, oInfo: { sDestination: sDestination, sErrorId: sErrorId } }); }, openURL: function (sURL) { - this.xConnect.postMessage({ sCommand: "openURL", dParam: { "sURL": sURL }, dInfo: null }); + this.xConnect.postMessage({ sCommand: "openURL", oParam: { "sURL": sURL }, oInfo: null }); }, openLexiconEditor: function () { - this.xConnect.postMessage({ sCommand: "openLexiconEditor", dParam: null, dInfo: null }); + this.xConnect.postMessage({ sCommand: "openLexiconEditor", oParam: null, oInfo: null }); }, restartWorker: function (nTimeDelay=10) { - this.xConnect.postMessage({ sCommand: "restartWorker", dParam: { "nTimeDelay": nTimeDelay }, dInfo: {} }); + this.xConnect.postMessage({ sCommand: "restartWorker", oParam: { "nTimeDelay": nTimeDelay }, oInfo: {} }); }, /* Messages from the background */ listen: function () { this.xConnect.onMessage.addListener(function (oMessage) { - let {sActionDone, result, dInfo, bEnd, bError} = oMessage; + let {sActionDone, result, oInfo, bEnd, bError} = oMessage; switch (sActionDone) { case "init": oGrammalecte.sExtensionUrl = oMessage.sUrl; oGrammalecte.listenRightClick(); oGrammalecte.createButtons(); oGrammalecte.observePage(); break; case "parseAndSpellcheck": - if (dInfo.sDestination == "__GrammalectePanel__") { + if (oInfo.sDestination == "__GrammalectePanel__") { if (!bEnd) { oGrammalecte.oGCPanel.addParagraphResult(result); } else { oGrammalecte.oGCPanel.stopWaitIcon(); oGrammalecte.oGCPanel.endTimer(); } } - else if (dInfo.sDestination && document.getElementById(dInfo.sDestination)) { - const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "errors", oResult: result, oInfo: dInfo }) }); - document.getElementById(dInfo.sDestination).dispatchEvent(xEvent); + else if (oInfo.sDestination && document.getElementById(oInfo.sDestination)) { + const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "errors", oResult: result, oInfo: oInfo }) }); + document.getElementById(oInfo.sDestination).dispatchEvent(xEvent); } break; case "parseAndSpellcheck1": - if (dInfo.sDestination == "__GrammalectePanel__") { - oGrammalecte.oGCPanel.refreshParagraph(dInfo.sParagraphId, result); + if (oInfo.sDestination == "__GrammalectePanel__") { + oGrammalecte.oGCPanel.refreshParagraph(oInfo.sParagraphId, result); } break; case "parseFull": // TODO break; @@ -410,20 +410,20 @@ oGrammalecte.oGCPanel.stopWaitIcon(); oGrammalecte.oGCPanel.endTimer(); } break; case "getSpellSuggestions": - if (dInfo.sDestination == "__GrammalectePanel__") { - oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, result.iSuggBlock, dInfo.sErrorId); + if (oInfo.sDestination == "__GrammalectePanel__") { + oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, result.iSuggBlock, oInfo.sErrorId); } - else if (dInfo.sDestination && document.getElementById(dInfo.sDestination)) { - const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "spellsugg", oResult: result, oInfo: dInfo }) }); - document.getElementById(dInfo.sDestination).dispatchEvent(xEvent); + else if (oInfo.sDestination && document.getElementById(oInfo.sDestination)) { + const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "spellsugg", oResult: result, oInfo: oInfo }) }); + document.getElementById(oInfo.sDestination).dispatchEvent(xEvent); } break; case "getVerb": - if (dInfo.bStart) { + if (oInfo.bStart) { oGrammalecte.oGCPanel.conjugateWith(result.oVerb, result.oConjTable); } else { oGrammalecte.oGCPanel.displayConj(result.oConjTable); } break; Index: gc_lang/fr/webext/gce_worker.js ================================================================== --- gc_lang/fr/webext/gce_worker.js +++ gc_lang/fr/webext/gce_worker.js @@ -56,15 +56,15 @@ for we need the path of the extension to load data stored in JSON files. This path is retrieved in background.js and passed with the event “init”. */ -function createResponse (sActionDone, result, dInfo, bEnd, bError=false) { +function createResponse (sActionDone, result, oInfo, bEnd, bError=false) { return { "sActionDone": sActionDone, "result": result, // can be of any type - "dInfo": dInfo, + "oInfo": oInfo, "bEnd": bEnd, "bError": bError }; } @@ -87,62 +87,62 @@ /* Message Event Object https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent */ onmessage = function (e) { - let {sCommand, dParam, dInfo} = e.data; + let {sCommand, oParam, oInfo} = e.data; switch (sCommand) { case "init": - init(dParam.sExtensionPath, dParam.dOptions, dParam.sContext, dInfo); + init(oParam.sExtensionPath, oParam.dOptions, oParam.sContext, oInfo); break; case "parse": - parse(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + parse(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "parseAndSpellcheck": - parseAndSpellcheck(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + parseAndSpellcheck(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "parseAndSpellcheck1": - parseAndSpellcheck1(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + parseAndSpellcheck1(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "parseFull": - parseFull(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + parseFull(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "getListOfTokens": - getListOfTokens(dParam.sText, dInfo); + getListOfTokens(oParam.sText, oInfo); break; case "getOptions": - getOptions(dInfo); + getOptions(oInfo); break; case "getDefaultOptions": - getDefaultOptions(dInfo); + getDefaultOptions(oInfo); break; case "setOptions": - setOptions(dParam.sOptions, dInfo); + setOptions(oParam.sOptions, oInfo); break; case "setOption": - setOption(dParam.sOptName, dParam.bValue, dInfo); + setOption(oParam.sOptName, oParam.bValue, oInfo); break; case "resetOptions": - resetOptions(dInfo); + resetOptions(oInfo); break; case "textToTest": - textToTest(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); + textToTest(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext, oInfo); break; case "fullTests": - fullTests(dInfo); + fullTests(oInfo); break; case "setDictionary": - setDictionary(dParam.sDictionary, dParam.oDict, dInfo); + setDictionary(oParam.sDictionary, oParam.oDict, oInfo); break; case "setDictionaryOnOff": - setDictionaryOnOff(dParam.sDictionary, dParam.bActivate, dInfo); + setDictionaryOnOff(oParam.sDictionary, oParam.bActivate, oInfo); break; case "getSpellSuggestions": - getSpellSuggestions(dParam.sWord, dInfo); + getSpellSuggestions(oParam.sWord, oInfo); break; case "getVerb": - getVerb(dParam.sVerb, dParam.bPro, dParam.bNeg, dParam.bTpsCo, dParam.bInt, dParam.bFem, dInfo); + getVerb(oParam.sVerb, oParam.bPro, oParam.bNeg, oParam.bTpsCo, oParam.bInt, oParam.bFem, oInfo); break; default: console.log("[Worker] Unknown command: " + sCommand); showData(e.data); } @@ -166,11 +166,11 @@ The answer is received by the background in another function (onmessage). That’s why the full text to analyze is send in one block, but analyse is returned paragraph by paragraph. */ -function init (sExtensionPath, dOptions=null, sContext="JavaScript", dInfo={}) { +function init (sExtensionPath, dOptions=null, sContext="JavaScript", oInfo={}) { try { if (!bInitDone) { //console.log("[Worker] Loading… Extension path: " + sExtensionPath); conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json")); phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json")); @@ -193,108 +193,108 @@ } else { console.log("[Worker] Already initialized…") } // we always retrieve options from the gc_engine, for setOptions filters obsolete options dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("init", dOptions, dInfo, true)); - } - catch (e) { - console.error(e); - postMessage(createResponse("init", createErrorResult(e, "init failed"), dInfo, true, true)); - } -} - - -function parse (sText, sCountry, bDebug, bContext, dInfo={}) { - sText = sText.replace(/­/g, "").normalize("NFC"); - for (let sParagraph of text.getParagraph(sText)) { - let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, bContext); - postMessage(createResponse("parse", aGrammErr, dInfo, false)); - } - postMessage(createResponse("parse", null, dInfo, true)); -} - -function parseAndSpellcheck (sText, sCountry, bDebug, bContext, dInfo={}) { - let i = 0; - sText = sText.replace(/­/g, "").normalize("NFC"); - for (let sParagraph of text.getParagraph(sText)) { - let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); - let aSpellErr = oSpellChecker.parseParagraph(sParagraph); - postMessage(createResponse("parseAndSpellcheck", {sParagraph: sParagraph, iParaNum: i, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, dInfo, false)); - i += 1; - } - postMessage(createResponse("parseAndSpellcheck", null, dInfo, true)); -} - -function parseAndSpellcheck1 (sParagraph, sCountry, bDebug, bContext, dInfo={}) { - sParagraph = sParagraph.replace(/­/g, "").normalize("NFC"); - let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); - let aSpellErr = oSpellChecker.parseParagraph(sParagraph); - postMessage(createResponse("parseAndSpellcheck1", {sParagraph: sParagraph, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, dInfo, true)); -} - -function parseFull (sText, sCountry, bDebug, bContext, dInfo={}) { - let i = 0; - sText = sText.replace(/­/g, "").normalize("NFC"); - for (let sParagraph of text.getParagraph(sText)) { - let lSentence = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext, true); - console.log("*", lSentence); - postMessage(createResponse("parseFull", {sParagraph: sParagraph, iParaNum: i, lSentence: lSentence}, dInfo, false)); - i += 1; - } - postMessage(createResponse("parseFull", null, dInfo, true)); -} - -function getListOfTokens (sText, dInfo={}) { + postMessage(createResponse("init", dOptions, oInfo, true)); + } + catch (e) { + console.error(e); + postMessage(createResponse("init", createErrorResult(e, "init failed"), oInfo, true, true)); + } +} + + +function parse (sText, sCountry, bDebug, bContext, oInfo={}) { + sText = sText.replace(/­/g, "").normalize("NFC"); + for (let sParagraph of text.getParagraph(sText)) { + let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, bContext); + postMessage(createResponse("parse", aGrammErr, oInfo, false)); + } + postMessage(createResponse("parse", null, oInfo, true)); +} + +function parseAndSpellcheck (sText, sCountry, bDebug, bContext, oInfo={}) { + let i = 0; + sText = sText.replace(/­/g, "").normalize("NFC"); + for (let sParagraph of text.getParagraph(sText)) { + let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); + let aSpellErr = oSpellChecker.parseParagraph(sParagraph); + postMessage(createResponse("parseAndSpellcheck", {sParagraph: sParagraph, iParaNum: i, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, oInfo, false)); + i += 1; + } + postMessage(createResponse("parseAndSpellcheck", null, oInfo, true)); +} + +function parseAndSpellcheck1 (sParagraph, sCountry, bDebug, bContext, oInfo={}) { + sParagraph = sParagraph.replace(/­/g, "").normalize("NFC"); + let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); + let aSpellErr = oSpellChecker.parseParagraph(sParagraph); + postMessage(createResponse("parseAndSpellcheck1", {sParagraph: sParagraph, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, oInfo, true)); +} + +function parseFull (sText, sCountry, bDebug, bContext, oInfo={}) { + let i = 0; + sText = sText.replace(/­/g, "").normalize("NFC"); + for (let sParagraph of text.getParagraph(sText)) { + let lSentence = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext, true); + console.log("*", lSentence); + postMessage(createResponse("parseFull", {sParagraph: sParagraph, iParaNum: i, lSentence: lSentence}, oInfo, false)); + i += 1; + } + postMessage(createResponse("parseFull", null, oInfo, true)); +} + +function getListOfTokens (sText, oInfo={}) { // lexicographer try { sText = sText.replace(/­/g, "").normalize("NFC"); for (let sParagraph of text.getParagraph(sText)) { if (sParagraph.trim() !== "") { - postMessage(createResponse("getListOfTokens", oLxg.getListOfTokensReduc(sParagraph, true), dInfo, false)); + postMessage(createResponse("getListOfTokens", oLxg.getListOfTokensReduc(sParagraph, true), oInfo, false)); } } - postMessage(createResponse("getListOfTokens", null, dInfo, true)); + postMessage(createResponse("getListOfTokens", null, oInfo, true)); } catch (e) { console.error(e); - postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), dInfo, true, true)); + postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), oInfo, true, true)); } } -function getOptions (dInfo={}) { +function getOptions (oInfo={}) { let dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("getOptions", dOptions, dInfo, true)); + postMessage(createResponse("getOptions", dOptions, oInfo, true)); } -function getDefaultOptions (dInfo={}) { +function getDefaultOptions (oInfo={}) { let dOptions = helpers.mapToObject(gc_engine.getDefaultOptions()); - postMessage(createResponse("getDefaultOptions", dOptions, dInfo, true)); + postMessage(createResponse("getDefaultOptions", dOptions, oInfo, true)); } -function setOptions (dOptions, dInfo={}) { +function setOptions (dOptions, oInfo={}) { if (!(dOptions instanceof Map)) { dOptions = helpers.objectToMap(dOptions); } gc_engine.setOptions(dOptions); dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("setOptions", dOptions, dInfo, true)); + postMessage(createResponse("setOptions", dOptions, oInfo, true)); } -function setOption (sOptName, bValue, dInfo={}) { +function setOption (sOptName, bValue, oInfo={}) { console.log(sOptName+": "+bValue); if (sOptName) { gc_engine.setOption(sOptName, bValue); let dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("setOption", dOptions, dInfo, true)); + postMessage(createResponse("setOption", dOptions, oInfo, true)); } } -function resetOptions (dInfo={}) { +function resetOptions (oInfo={}) { gc_engine.resetOptions(); let dOptions = helpers.mapToObject(gc_engine.getOptions()); - postMessage(createResponse("resetOptions", dOptions, dInfo, true)); + postMessage(createResponse("resetOptions", dOptions, oInfo, true)); } function tests () { console.log(conj.getConj("devenir", ":E", ":2s")); console.log(mfsp.getMasForm("emmerdeuse", true)); @@ -304,13 +304,13 @@ for (let oErr of aRes) { console.log(text.getReadableError(oErr)); } } -function textToTest (sText, sCountry, bDebug, bContext, dInfo={}) { +function textToTest (sText, sCountry, bDebug, bContext, oInfo={}) { if (!gc_engine) { - postMessage(createResponse("textToTest", "# Grammar checker not loaded.", dInfo, true)); + postMessage(createResponse("textToTest", "# Grammar checker not loaded.", oInfo, true)); return; } sText = sText.replace(/­/g, "").normalize("NFC"); let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext); let sMsg = ""; @@ -318,16 +318,16 @@ sMsg += text.getReadableError(oErr) + "\n"; } if (sMsg == "") { sMsg = "Aucune erreur détectée."; } - postMessage(createResponse("textToTest", sMsg, dInfo, true)); + postMessage(createResponse("textToTest", sMsg, oInfo, true)); } -function fullTests (dInfo={}) { +function fullTests (oInfo={}) { if (!gc_engine) { - postMessage(createResponse("fullTests", "# Grammar checker not loaded.", dInfo, true)); + postMessage(createResponse("fullTests", "# Grammar checker not loaded.", oInfo, true)); return; } let dMemoOptions = gc_engine.getOptions(); let dTestOptions = gc_engine.getDefaultOptions(); dTestOptions.set("nbsp", true); @@ -339,25 +339,25 @@ for (let sRes of oTest.testParse()) { sMsg += sRes + "\n"; console.log(sRes); } gc_engine.setOptions(dMemoOptions); - postMessage(createResponse("fullTests", sMsg, dInfo, true)); + postMessage(createResponse("fullTests", sMsg, oInfo, true)); } // SpellChecker -function setDictionary (sDictionary, oDict, dInfo) { +function setDictionary (sDictionary, oDict, oInfo) { if (!oSpellChecker) { - postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", dInfo, true)); + postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", oInfo, true)); return; } //console.log("setDictionary", sDictionary); switch (sDictionary) { case "main": - oSpellChecker.setMainDictionary(oDict, dInfo["sExtPath"]+"/grammalecte/graphspell/_dictionaries"); + oSpellChecker.setMainDictionary(oDict, oInfo["sExtPath"]+"/grammalecte/graphspell/_dictionaries"); break; case "community": oSpellChecker.setCommunityDictionary(oDict); break; case "personal": @@ -364,16 +364,16 @@ oSpellChecker.setPersonalDictionary(oDict); break; default: console.log("[worker] setDictionary: Unknown dictionary <"+sDictionary+">"); } - postMessage(createResponse("setDictionary", true, dInfo, true)); + postMessage(createResponse("setDictionary", true, oInfo, true)); } -function setDictionaryOnOff (sDictionary, bActivate, dInfo) { +function setDictionaryOnOff (sDictionary, bActivate, oInfo) { if (!oSpellChecker) { - postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", dInfo, true)); + postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", oInfo, true)); return; } //console.log("setDictionaryOnOff", sDictionary, bActivate); switch (sDictionary) { case "community": @@ -391,38 +391,38 @@ } break; default: console.log("[worker] setDictionaryOnOff: Unknown dictionary <"+sDictionary+">"); } - postMessage(createResponse("setDictionaryOnOff", true, dInfo, true)); + postMessage(createResponse("setDictionaryOnOff", true, oInfo, true)); } -function getSpellSuggestions (sWord, dInfo) { +function getSpellSuggestions (sWord, oInfo) { if (!oSpellChecker) { - postMessage(createResponse("getSpellSuggestions", "# Error. SpellChecker not loaded.", dInfo, true)); + postMessage(createResponse("getSpellSuggestions", "# Error. SpellChecker not loaded.", oInfo, true)); return; } let i = 0; for (let aSugg of oSpellChecker.suggest(sWord)) { - postMessage(createResponse("getSpellSuggestions", {sWord: sWord, aSugg: aSugg, iSuggBlock: i}, dInfo, true)); + postMessage(createResponse("getSpellSuggestions", {sWord: sWord, aSugg: aSugg, iSuggBlock: i}, oInfo, true)); i += 1; } } // Conjugueur -function getVerb (sWord, bPro, bNeg, bTpsCo, bInt, bFem, dInfo) { +function getVerb (sWord, bPro, bNeg, bTpsCo, bInt, bFem, oInfo) { try { let oVerb = null; let oConjTable = null; if (conj.isVerb(sWord)) { oVerb = new Verb(sWord); oConjTable = oVerb.createConjTable(bPro, bNeg, bTpsCo, bInt, bFem); } - postMessage(createResponse("getVerb", { oVerb: oVerb, oConjTable: oConjTable }, dInfo, true)); + postMessage(createResponse("getVerb", { oVerb: oVerb, oConjTable: oConjTable }, oInfo, true)); } catch (e) { console.error(e); - postMessage(createResponse("getVerb", createErrorResult(e, "no verb"), dInfo, true, true)); + postMessage(createResponse("getVerb", createErrorResult(e, "no verb"), oInfo, true, true)); } } Index: gc_lang/fr/webext/panel/dictionaries.js ================================================================== --- gc_lang/fr/webext/panel/dictionaries.js +++ gc_lang/fr/webext/panel/dictionaries.js @@ -425,11 +425,11 @@ } let oDict = dic_merger.merge(lDict, "S", "fr", "Français", "fr.community", "Dictionnaire communautaire (personnalisé)", this.xProgressBar); console.log(oDict); browser.storage.local.set({ "community_dictionary": oDict }); browser.storage.local.set({ "selected_dictionaries_list": Array.from(this.dSelectedDictionaries.keys()) }); - browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "community", oDict: oDict}, dInfo: {} }); + browser.runtime.sendMessage({ sCommand: "setDictionary", oParam: {sDictionary: "community", oDict: oDict}, oInfo: {} }); } } const oDicTable = new Table("dictionaries_table", ["Nom", "Entrées", "Description", "Date"], "wait_progress", "num_dic", false, true); Index: gc_lang/fr/webext/panel/lex_editor.js ================================================================== --- gc_lang/fr/webext/panel/lex_editor.js +++ gc_lang/fr/webext/panel/lex_editor.js @@ -591,11 +591,11 @@ if (!sName) { console.log("Error: name of dictionary to save is empty.") return; } if (sName == "__personal__") { - browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} }); + browser.runtime.sendMessage({ sCommand: "setDictionary", oParam: {sDictionary: "personal", oDict: oJSON}, oInfo: {} }); browser.storage.local.set({ "personal_dictionary": oJSON }); } else { this.oDictionaries[sName] = oJSON; if (oJSON === null) { Index: gc_lang/fr/webext/panel/main.js ================================================================== --- gc_lang/fr/webext/panel/main.js +++ gc_lang/fr/webext/panel/main.js @@ -26,65 +26,65 @@ 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: {} + oParam: {sText: document.getElementById("text_to_test").value, sCountry: "FR", bDebug: true, bContext: false}, + oInfo: {} }); } else if (xElem.id === "fulltests_button") { document.getElementById("tests_result").textContent = "Veuillez patienter…"; browser.runtime.sendMessage({ sCommand: "fullTests", - dParam: {}, - dInfo: {} + oParam: {}, + oInfo: {} }); } else if (xElem.id == "restart_worker") { browser.runtime.sendMessage({ sCommand: "restartWorker", - dParam: { "nDelayLimit": 3 }, - dInfo: {} + oParam: { "nDelayLimit": 3 }, + oInfo: {} }); } // grammar options else if (xElem.id === "default_options_button") { browser.runtime.sendMessage({ sCommand: "resetOptions", - dParam: {}, - dInfo: {} + oParam: {}, + oInfo: {} }); } else if (xElem.id.startsWith("option_")) { if (xElem.dataset.option) { browser.runtime.sendMessage({ sCommand: "setOption", - dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked}, - dInfo: {} + oParam: {sOptName: xElem.dataset.option, bValue: xElem.checked}, + oInfo: {} }); } } // 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: {} + oParam: {sDictionary: xElem.dataset.dictionary, bActivate: xElem.checked}, + oInfo: {} }); } } 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("") } + oParam: { sDictionary: "main", oDict: sMainDicName }, + oInfo: { sExtPath: browser.extension.getURL("") } }); } // UI options else if (xElem.id.startsWith("ui_option_")) { storeUIOptions(); @@ -94,33 +94,33 @@ browser.tabs.create({url: xElem.dataset.url}); } else if (xElem.id == "conj_button") { browser.runtime.sendMessage({ sCommand: "openConjugueurTab", - dParam: {}, - dInfo: {} + oParam: {}, + oInfo: {} }); } else if (xElem.id == "dictionaries_button") { browser.runtime.sendMessage({ sCommand: "openDictionaries", - dParam: {}, - dInfo: {} + oParam: {}, + oInfo: {} }); } else if (xElem.id == "dic_community_button") { browser.runtime.sendMessage({ sCommand: "openLexiconEditor", - dParam: { "dictionary": "__community__"}, - dInfo: {} + oParam: { "dictionary": "__community__"}, + oInfo: {} }); } else if (xElem.id == "dic_personal_button") { browser.runtime.sendMessage({ sCommand: "openLexiconEditor", - dParam: { "dictionary": "__personal__"}, - dInfo: {} + oParam: { "dictionary": "__personal__"}, + oInfo: {} }); } // change UI page } else if (xElem.className.startsWith("select")) { showPage(xElem.dataset.page); @@ -154,11 +154,11 @@ /* Messages received */ function handleMessage (oMessage, xSender, sendResponse) { - let {sActionDone, result, dInfo, bEnd, bError} = oMessage; + let {sActionDone, result, oInfo, bEnd, bError} = oMessage; switch(sActionDone) { case "textToTest": case "fullTests": showTestResult(result); break;