Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -32,10 +32,13 @@ console.log(e.data); } break; case "textToTest": case "fullTests": + // send result to panel + browser.runtime.sendMessage(e.data); + break; case "getOptions": case "getDefaultOptions": case "resetOptions": // send result to panel browser.runtime.sendMessage(e.data); @@ -91,26 +94,26 @@ /* Messages from the extension (not the Worker) */ function handleMessage (oRequest, xSender, sendResponse) { //console.log(xSender); - switch (oRequest.sCommand) { - case "parse": - case "parseAndSpellcheck": - case "parseAndSpellcheck1": - case "getListOfTokens": - case "textToTest": + let {sCommand, dParam, dInfo} = oRequest; + switch (sCommand) { case "getOptions": case "getDefaultOptions": case "setOptions": case "setOption": case "resetOptions": + case "textToTest": case "fullTests": xGCEWorker.postMessage(oRequest); break; + case "openURL": + browser.tabs.create({url: dParam.sURL}); + break; default: - console.log("[background] Unknown command: " + oRequest.sCommand); + console.log("[background] Unknown command: " + sCommand); } //sendResponse({response: "response from background script"}); } browser.runtime.onMessage.addListener(handleMessage); @@ -118,20 +121,24 @@ function handleConnexion (xPort) { 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) { - switch (oRequest.sCommand) { + let {sCommand, dParam, dInfo} = oRequest; + switch (sCommand) { case "parse": case "parseAndSpellcheck": case "parseAndSpellcheck1": case "getListOfTokens": oRequest.dInfo.iReturnPort = iPortId; // we pass the id of the return port to receive answer xGCEWorker.postMessage(oRequest); break; + case "openURL": + browser.tabs.create({url: dParam.sURL}); + break; default: - console.log("[background] Unknown command: " + oRequest.sCommand); + console.log("[background] Unknown command: " + sCommand); console.log(oRequest); } }); xPort.postMessage({sActionDone: "newId", result: iPortId}); } Index: gc_lang/fr/webext/content_scripts/gc_content.css ================================================================== --- gc_lang/fr/webext/content_scripts/gc_content.css +++ gc_lang/fr/webext/content_scripts/gc_content.css @@ -160,32 +160,35 @@ } #grammalecte_tooltip_message { font-size: 15px; margin: 0 0 5px 0; } -a#grammalecte_tooltip_ignore { - padding: 0 2px; +#grammalecte_tooltip_ignore { + display: inline-block; + padding: 2px 5px; background-color: hsla(30, 30%, 40%, 1); color: hsla(30, 0%, 96%, 1); border-radius: 2px; cursor: pointer; text-decoration: none; } -a#grammalecte_tooltip_ignore:hover { +#grammalecte_tooltip_ignore:hover { background-color: hsla(30, 30%, 50%, 1); color: hsla(0, 0%, 100%, 1); text-shadow: 0 0 3px hsl(30, 30%, 60%); } -a#grammalecte_tooltip_url { - padding: 0 2px; +#grammalecte_tooltip_url { + display: inline-block; + margin: 0 0 0 10px; + padding: 2px 5px; background-color: hsla(210, 50%, 50%, 1); color: hsla(210, 0%, 96%, 1); border-radius: 2px; cursor: pointer; text-decoration: none; } -a#grammalecte_tooltip_url:hover { +#grammalecte_tooltip_url:hover { background-color: hsla(210, 50%, 60%, 1); color: hsla(0, 0%, 100%, 1); text-shadow: 0 0 3px hsl(210, 30%, 60%); } #grammalecte_tooltip_sugg_title { Index: gc_lang/fr/webext/content_scripts/gc_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/gc_content.js +++ gc_lang/fr/webext/content_scripts/gc_content.js @@ -16,16 +16,14 @@ xElem.parentNode.parentNode.style.display = "none"; } else if (xElem.tagName === "U" && xElem.id.startsWith("grammalecte_err") && xElem.className !== "corrected" && xElem.className !== "ignored") { oGrammalecte.oGCPanel.oTooltip.show(xElem.id); } else if (xElem.id === "grammalecte_tooltip_url") { - oGrammalecte.oGCPanel.openURL(xElem.getAttribute("href")); + oGrammalecte.oGCPanel.openURL(xElem.dataset.url); } else { oGrammalecte.oGCPanel.oTooltip.hide(); } - } else if (xElem.tagName === "A") { - oGrammalecte.oGCPanel.openURL(xElem.getAttribute("href")); } else { oGrammalecte.oGCPanel.oTooltip.hide(); } } catch (e) { @@ -252,11 +250,11 @@ xEvent.clipboardData.setData("text/plain", sText); }; document.addEventListener("copy", setClipboardData, true); document.execCommand("copy"); - }; + } copyTextToClipboard () { this.startWaitIcon(); try { let xClipboardButton = document.getElementById("grammalecte_clipboard_button"); @@ -263,19 +261,27 @@ xClipboardButton.textContent = "->>"; let sText = ""; for (let xNode of document.getElementsByClassName("grammalecte_paragraph")) { sText += xNode.textContent + "\n"; } - xClipboardButton.textContent = "OK"; this._copyToClipboard(sText); + xClipboardButton.textContent = "OK"; window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 2000); } catch (e) { showError(e); } this.stopWaitIcon(); } + + openURL (sURL) { + xPort.postMessage({ + sCommand: "openURL", + dParam: {"sURL": sURL}, + dInfo: {} + }); + } } class GrammalecteTooltip { @@ -288,12 +294,14 @@ }); this.xTooltipSuggBlock = createNode("div", {id: "grammalecte_tooltip_sugg_block"}); let xMessageBlock = createNode("div", {id: "grammalecte_tooltip_message_block"}); xMessageBlock.appendChild(createNode("p", {id: "grammalecte_tooltip_rule_id"})); xMessageBlock.appendChild(createNode("p", {id: "grammalecte_tooltip_message", textContent: "Erreur."})); - xMessageBlock.appendChild(createNode("a", {id: "grammalecte_tooltip_ignore", href: "#", onclick: "return false;", textContent: "Ignorer"})); - xMessageBlock.appendChild(createNode("a", {id: "grammalecte_tooltip_url", href: "#", onclick: "return false;", textContent: "Voulez-vous en savoir plus ?…"})); + let xActions = xMessageBlock.appendChild(createNode("div", {id: "grammalecte_tooltip_actions"})); + xActions.appendChild(createNode("div", {id: "grammalecte_tooltip_ignore", textContent: "Ignorer"})); + xActions.appendChild(createNode("div", {id: "grammalecte_tooltip_url", textContent: "Voulez-vous en savoir plus ?…"}, {url: ""})); + xMessageBlock.appendChild(xActions); this.xTooltip.appendChild(xMessageBlock); this.xTooltip.appendChild(createNode("div", {id: "grammalecte_tooltip_sugg_title", textContent: "SUGGESTIONS :"})); this.xTooltip.appendChild(this.xTooltipSuggBlock); xContentNode.appendChild(this.xTooltip); xContentNode.appendChild(this.xTooltipArrow); @@ -317,13 +325,14 @@ } else { document.getElementById("grammalecte_tooltip_message").textContent = xNodeErr.dataset.gc_message; document.getElementById("grammalecte_tooltip_rule_id").style.display = "none"; } if (xNodeErr.dataset.gc_url != "") { + document.getElementById("grammalecte_tooltip_url").dataset.url = xNodeErr.dataset.gc_url; document.getElementById("grammalecte_tooltip_url").style.display = "inline"; - document.getElementById("grammalecte_tooltip_url").setAttribute("href", xNodeErr.dataset.gc_url); } else { + document.getElementById("grammalecte_tooltip_url").dataset.url = ""; document.getElementById("grammalecte_tooltip_url").style.display = "none"; } document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id; let iSugg = 0; let xGCSugg = document.getElementById("grammalecte_tooltip_sugg_block");