288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
object {
sCommand: the action to perform
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)
}
*/
checkConnection: function () {
if (!this.xConnect) {
this.xConnect = browser.runtime.connect({name: "content-script port"});
}
},
parseAndSpellcheck: function (sText, sDestination) {
this.xConnect.postMessage({
sCommand: "parseAndSpellcheck",
oParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false },
oInfo: { sDestination: sDestination }
});
},
parseAndSpellcheck1: function (sText, sDestination, sParagraphId) {
this.xConnect.postMessage({
sCommand: "parseAndSpellcheck1",
oParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false },
oInfo: { sDestination: sDestination, sParagraphId: sParagraphId }
});
},
getListOfTokens: function (sText) {
this.xConnect.postMessage({ sCommand: "getListOfTokens", oParam: { sText: sText }, oInfo: {} });
},
parseFull: function (sText) {
this.xConnect.postMessage({
sCommand: "parseFull",
oParam: { sText: sText, 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",
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", oParam: { sWord: sWord }, oInfo: { sDestination: sDestination, sErrorId: sErrorId } });
},
openURL: function (sURL) {
this.xConnect.postMessage({ sCommand: "openURL", oParam: { "sURL": sURL }, oInfo: null });
},
openLexiconEditor: function () {
this.xConnect.postMessage({ sCommand: "openLexiconEditor", oParam: null, oInfo: null });
},
restartWorker: function (nTimeDelay=10) {
this.xConnect.postMessage({ sCommand: "restartWorker", oParam: { "nTimeDelay": nTimeDelay }, oInfo: {} });
},
/*
Messages from the background
*/
listen: function () {
this.xConnect.onMessage.addListener(function (oMessage) {
let { sActionDone, result, oInfo, bEnd, bError } = oMessage;
switch (sActionDone) {
case "init":
oGrammalecte.sExtensionUrl = oMessage.sUrl;
oGrammalecte.listen();
oGrammalecte.createButton();
|
|
|
|
>
>
<
<
|
<
<
<
<
|
<
<
|
<
<
|
<
<
<
<
|
<
<
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
object {
sCommand: the action to perform
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)
}
*/
send: function (sCommand, oParam={}, oInfo={}) {
if (this.xConnect) {
this.xConnect.postMessage({ sCommand: sCommand, oParam: oParam, oInfo: oInfo });
} else {
oGrammalecte.showMessage("Erreur. La connexion vers le correcteur grammatical est perdue.");
}
},
parseAndSpellcheck: function (sText, sDestination) {
this.send("parseAndSpellcheck", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination });
},
parseAndSpellcheck1: function (sText, sDestination, sParagraphId) {
this.send("parseAndSpellcheck1", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination, sParagraphId: sParagraphId });
},
getListOfTokens: function (sText) {
this.send("getListOfTokens", { sText: sText }, {});
},
parseFull: function (sText) {
this.send("parseFull", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, {});
},
getVerb: function (sVerb, bStart=true, bPro=false, bNeg=false, bTpsCo=false, bInt=false, bFem=false) {
this.send("getVerb", { sVerb: sVerb, bPro: bPro, bNeg: bNeg, bTpsCo: bTpsCo, bInt: bInt, bFem: bFem }, { bStart: bStart });
},
getSpellSuggestions: function (sWord, sDestination, sErrorId) {
this.send("getSpellSuggestions", { sWord: sWord }, { sDestination: sDestination, sErrorId: sErrorId });
},
openURL: function (sURL) {
this.send("openURL", { "sURL": sURL });
},
openLexiconEditor: function () {
this.send("openLexiconEditor");
},
restartWorker: function (nTimeDelay=10) {
this.send("restartWorker", { "nTimeDelay": nTimeDelay });
},
/*
Messages from the background
*/
listen: function () {
this.xConnect.onDisconnect.addListener(function (xPort) {
let sError = "";
if (xPort.error) {
sError = xPort.error.message;
}
else if (browser.runtime.lastError) {
sError = browser.runtime.lastError.message;
}
console.log("[Grammalecte] Connection to the background script has been lost. Error :", sError);
this.xConnect = browser.runtime.connect({name: "content-script port"});
this.listen();
}.bind(this));
this.xConnect.onMessage.addListener(function (oMessage) {
let { sActionDone, result, oInfo, bEnd, bError } = oMessage;
switch (sActionDone) {
case "init":
oGrammalecte.sExtensionUrl = oMessage.sUrl;
oGrammalecte.listen();
oGrammalecte.createButton();
|