Index: gc_lang/fr/webext/content_scripts/api.js ================================================================== --- gc_lang/fr/webext/content_scripts/api.js +++ gc_lang/fr/webext/content_scripts/api.js @@ -9,34 +9,34 @@ sVersion: "1.0", openPanelForNode: function (vNode) { // Parameter: a HTML node or the identifier of a HTML node - if (vNode instanceof HTMLElement) { - let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "openPanelForNode", xNode: vNode} }); + if (vNode instanceof HTMLElement && vNode.id) { + let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForNode", sNodeId: vNode.id}) }); document.dispatchEvent(xEvent); } else if (typeof(vNode) === "string" && document.getElementById(vNode)) { - let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "openPanelForNode", xNode: document.getElementById(vNode)} }); + let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForNode", sNodeId: vNode}) }); document.dispatchEvent(xEvent); } else { - console.log("[Grammalecte API] Error: parameter is not a HTML node."); + console.log("[Grammalecte API] Error: parameter is not a HTML node with an identifier."); } }, openPanelForText: function (sText, vNode=null) { // Parameter: text to analyze, and optionaly a node to send results to. if (typeof(sText) === "string") { - let xNode = null; - if (vNode instanceof HTMLElement) { - xNode = vNode; + let sNodeId = ""; + if (vNode instanceof HTMLElement && vNode.id) { + sNodeId = vNode.id; } else if (typeof(vNode) === "string" && document.getElementById(vNode)) { - xNode = document.getElementById(vNode); + sNodeId = vNode; } - let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "openPanelForText", sText: sText, xNode: xNode} }); + let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForText", sText: sText, sNodeId: sNodeId}) }); document.dispatchEvent(xEvent); } else { console.log("[Grammalecte API] Error: parameter is not a text."); } }, @@ -44,35 +44,35 @@ parseNode: function (vNode) { /* Parameter: a HTML node (with a identifier) or the identifier of a HTML node. The result will be sent as an event “GrammalecteResult” to the node. */ if (vNode instanceof HTMLElement && vNode.id) { - let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "parseNode", xNode: vNode} }); + let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseNode", sNodeId: vNode.id}) }); document.dispatchEvent(xEvent); } else if (typeof(vNode) === "string" && document.getElementById(vNode)) { - let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "parseNode", xNode: document.getElementById(vNode)} }); + let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseNode", sNodeId: vNode}) }); document.dispatchEvent(xEvent); } else { - console.log("[Grammalecte API] Error: parameter is not a HTML node or doesn’t have an identifier."); + console.log("[Grammalecte API] Error: parameter is not a HTML node with an identifier."); } }, parseText: function (sText, vNode) { // Parameter: text to analyze, and a node to send results to. if (typeof(sText) === "string") { if (vNode instanceof HTMLElement && vNode.id) { - let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "parseText", sText: sText, xNode: vNode} }); + let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseText", sText: sText, sNodeId: vNode.id}) }); document.dispatchEvent(xEvent); } else if (typeof(vNode) === "string" && document.getElementById(vNode)) { - let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "parseText", sText: sText, xNode: document.getElementById(vNode)} }); + let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseText", sText: sText, sNodeId: vNode}) }); document.dispatchEvent(xEvent); } else { - console.log("[Grammalecte API] Error: parameter is not a HTML node or doesn’t have an identifier."); + console.log("[Grammalecte API] Error: parameter is not a HTML node with an identifier."); } } else { console.log("[Grammalecte API] Error: parameter is not a text."); } }, @@ -82,11 +82,11 @@ - sWord (string) - sDestination: HTML identifier (string) -> the result will be sent as an event “GrammalecteResult” to destination node - sRequestId: custom identifier for the request (string) [default = ""] */ if (typeof(sWord) === "string" && typeof(sDestination) === "string" && typeof(sRequestId) === "string") { - let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "getSpellSuggestions", sWord: sWord, sDestination: sDestination, sRequestId: sRequestId} }); + let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "getSpellSuggestions", sWord: sWord, sDestination: sDestination, sRequestId: sRequestId}) }); document.dispatchEvent(xEvent); } else { console.log("[Grammalecte API] Error: one or several parameters aren’t string."); } } 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 @@ -462,42 +462,43 @@ */ document.addEventListener("GrammalecteCall", function (xEvent) { // GrammalecteCall events are dispatched by functions in the API script // The script is loaded below. try { - let oCommand = xEvent.detail; + let oCommand = JSON.parse(xEvent.detail); switch (oCommand.sCommand) { case "openPanelForNode": - if (oCommand.xNode) { - oGrammalecte.startGCPanel(oCommand.xNode); + if (oCommand.sNodeId && document.getElementById(oCommand.sNodeId)) { + oGrammalecte.startGCPanel(document.getElementById(oCommand.sNodeId)); } break; case "openPanelForText": - if (oCommand.sText) { - oGrammalecte.startGCPanel(oCommand.sText, oCommand.xNode); + if (oCommand.sText && oCommand.sNodeId && document.getElementById(oCommand.sNodeId)) { + oGrammalecte.startGCPanel(oCommand.sText, document.getElementById(oCommand.sNodeId)); } break; case "parseNode": - if (oCommand.xNode && oCommand.xNode.id) { - if (oCommand.xNode.tagName == "TEXTAREA" || oCommand.xNode.tagName == "INPUT") { - oGrammalecteBackgroundPort.parseAndSpellcheck(oCommand.xNode.value, oCommand.xNode.id); + if (oCommand.sNodeId && document.getElementById(oCommand.sNodeId)) { + let xNode = document.getElementById(oCommand.sNodeId); + if (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT") { + oGrammalecteBackgroundPort.parseAndSpellcheck(xNode.value, oCommand.sNodeId); } - else if (oCommand.xNode.tagName == "IFRAME") { - oGrammalecteBackgroundPort.parseAndSpellcheck(oCommand.xNode.contentWindow.document.body.innerText, oCommand.xNode.id); + else if (xNode.tagName == "IFRAME") { + oGrammalecteBackgroundPort.parseAndSpellcheck(xNode.contentWindow.document.body.innerText, oCommand.sNodeId); } else { - oGrammalecteBackgroundPort.parseAndSpellcheck(oCommand.xNode.innerText, oCommand.xNode.id); + oGrammalecteBackgroundPort.parseAndSpellcheck(xNode.innerText, oCommand.sNodeId); } } break; case "parseText": - if (oCommand.sText && oCommand.xNode) { - oGrammalecteBackgroundPort.parseAndSpellcheck(oCommand.sText, oCommand.xNode.id); + if (oCommand.sText && oCommand.sNodeId) { + oGrammalecteBackgroundPort.parseAndSpellcheck(oCommand.sText, oCommand.sNodeId); } break; case "getSpellSuggestions": - if (oCommand.sWord) { + if (oCommand.sWord && oCommand.sDestination) { oGrammalecteBackgroundPort.getSpellSuggestions(oCommand.sWord, oCommand.sDestination, oCommand.sErrorId); } break; default: console.log("[Grammalecte] Event: Unknown command", oCommand.sCommand);