Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -72,5 +72,37 @@ } //sendResponse({response: "response from background script"}); } browser.runtime.onMessage.addListener(handleMessage); + + +/* + Context Menu +*/ +browser.contextMenus.create({ + id: "grammar_checking", + title: "Correction grammaticale", + contexts: ["selection", "editable", "page"] +}); + +browser.contextMenus.create({ + id: "lexicographer", + title: "Lexicographe", + contexts: ["selection", "editable", "page"] +}); + +browser.contextMenus.onClicked.addListener(function (xInfo, xTab) { + // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData + // xTab = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab + console.log(xInfo); + console.log(xTab); + console.log("Item " + xInfo.menuItemId + " clicked in tab " + xTab.id); + console.log("editable: " + xInfo.editable + " · selected: " + xInfo.selectionText); + // confusing: no way to get the node where we click?! + switch (xInfo.menuItemId) { + case "grammar_checking": + break; + case "lexicographer": + break; + } +}); Index: gc_lang/fr/webext/manifest.json ================================================================== --- gc_lang/fr/webext/manifest.json +++ gc_lang/fr/webext/manifest.json @@ -39,8 +39,9 @@ "grammalecte/fr/mfsp_data.json", "grammalecte/fr/phonet_data.json", "grammalecte/fr/tests_data.json" ], "permissions": [ - "activeTab" + "activeTab", + "contextMenus" ] }