Overview
Comment: | [fx] WebExt: parse from context menu |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | fx | webext3 |
Files: | files | file ages | folders |
SHA3-256: |
13e3ccd8afa2064f1d8ed3d11c2e9cf5 |
User & Date: | olr on 2017-10-11 14:43:41 |
Other Links: | branch diff | manifest | tags |
Context
2017-10-11
| ||
18:07 | [fx] WebExt: tab id (bug) + parse full page check-in: 94ae41b9ee user: olr tags: fx, webext3 | |
14:43 | [fx] WebExt: parse from context menu check-in: 13e3ccd8af user: olr tags: fx, webext3 | |
09:33 | [fx] WebExt: new contextual menu check-in: c2aa4fe9b2 user: olr tags: fx, webext3 | |
Changes
Modified gc_lang/fr/webext/background.js from [b86410f356] to [d80a5da332].
︙ | ︙ | |||
175 176 177 178 179 180 181 | /* Context Menu */ // Editable content browser.contextMenus.create({ | | | | | | | | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | /* Context Menu */ // Editable content browser.contextMenus.create({ id: "rightClickLxgEditableNode", title: "Lexicographe (zone de texte)", contexts: ["editable"] }); browser.contextMenus.create({ id: "rightClickGCEditableNode", title: "Correction grammaticale (zone de texte)", contexts: ["editable"] }); browser.contextMenus.create({ id: "separator_editable", type: "separator", contexts: ["editable"] }); // Page browser.contextMenus.create({ id: "rightClickLxgPage", title: "Lexicographe (page)", contexts: ["all"] }); browser.contextMenus.create({ id: "rightClickGCPage", title: "Correction grammaticale (page)", contexts: ["all"] }); browser.contextMenus.create({ id: "separator_page", type: "separator", contexts: ["all"] }); // Selected text browser.contextMenus.create({ id: "getListOfTokensFromSelectedText", title: "Lexicographe (sélection)", contexts: ["selection"] }); browser.contextMenus.create({ id: "parseAndSpellcheckSelectedText", title: "Correction grammaticale (sélection)", contexts: ["selection"] }); browser.contextMenus.create({ id: "separator_selection", type: "separator", |
︙ | ︙ | |||
262 263 264 265 266 267 268 | 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 // confusing: no way to get the node where we click?! switch (xInfo.menuItemId) { | > > > > > > > > > > > > | | > > > > > | | > > > > | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | 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 // confusing: no way to get the node where we click?! switch (xInfo.menuItemId) { // editable node // page case "rightClickGCEditableNode": case "rightClickLxgEditableNode": case "rightClickGCPage": case "rightClickLxgPage": sendCommandToTab(xInfo.menuItemId, xTab.id); break; // selected text case "rightClickGCSelectedText": sendCommandToTab("rightClickGCSelectedText", xTab.id); xGCEWorker.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: xInfo.selectionText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {iReturnPort: iTab} }); break; case "rightClickLxgSelectedText": sendCommandToTab("rightClickLxgSelectedText", xTab.id); xGCEWorker.postMessage({ sCommand: "getListOfTokens", dParam: {sText: xInfo.selectionText}, dInfo: {iReturnPort: iTab} }); break; // conjugueur case "conjugueur_window": openConjugueurWindow(); break; case "conjugueur_tab": openConjugueurTab(); break; // rescan page case "rescanPage": let xPort = dConnx.get(xTab.id); xPort.postMessage({sActionDone: "rescanPage"}); break; default: console.log("[Background] Unknown menu id: " + xInfo.menuItemId); console.log(xInfo); |
︙ | ︙ | |||
313 314 315 316 317 318 319 | if (bChrome) { // JS crap again. Chrome can’t store Map object. dOptions = helpers.mapToObject(dOptions); } browser.storage.local.set({"gc_options": dOptions}); } | < < < < < < < < < < < | < < | < < < < < < | 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | if (bChrome) { // JS crap again. Chrome can’t store Map object. dOptions = helpers.mapToObject(dOptions); } browser.storage.local.set({"gc_options": dOptions}); } function sendCommandToTab (sCommand, iTab) { let xTabPort = dConnx.get(iTab); xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false}); } function openConjugueurTab () { if (bChrome) { browser.tabs.create({ url: browser.extension.getURL("panel/conjugueur.html") }); |
︙ | ︙ |
Modified gc_lang/fr/webext/content_scripts/init.js from [b57bfdbc72] to [a42a275d4a].
︙ | ︙ | |||
94 95 96 97 98 99 100 101 102 103 104 105 106 107 | createGCPanel: function () { if (this.oGCPanel === null) { this.oGCPanel = new GrammalecteGrammarChecker("grammalecte_gc_panel", "Grammalecte", 500, 700); this.oGCPanel.insertIntoPage(); } }, createNode: function (sType, oAttr, oDataset=null) { try { let xNode = document.createElement(sType); Object.assign(xNode, oAttr); if (oDataset) { Object.assign(xNode.dataset, oDataset); | > > > > > > > > > > > > > > > | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | createGCPanel: function () { if (this.oGCPanel === null) { this.oGCPanel = new GrammalecteGrammarChecker("grammalecte_gc_panel", "Grammalecte", 500, 700); this.oGCPanel.insertIntoPage(); } }, startGCPanel: function (xNode=null) { oGrammalecte.createGCPanel(); oGrammalecte.oGCPanel.clear(); oGrammalecte.oGCPanel.show(); oGrammalecte.oGCPanel.start(xNode); oGrammalecte.oGCPanel.startWaitIcon(); }, startLxgPanel: function () { oGrammalecte.createLxgPanel(); oGrammalecte.oLxgPanel.clear(); oGrammalecte.oLxgPanel.show(); oGrammalecte.oLxgPanel.startWaitIcon(); }, createNode: function (sType, oAttr, oDataset=null) { try { let xNode = document.createElement(sType); Object.assign(xNode, oAttr); if (oDataset) { Object.assign(xNode.dataset, oDataset); |
︙ | ︙ | |||
128 129 130 131 132 133 134 135 136 137 138 139 140 141 | /* Connexion to the background */ let xGrammalectePort = browser.runtime.connect({name: "content-script port"}); xGrammalectePort.onMessage.addListener(function (oMessage) { let {sActionDone, result, dInfo, bEnd, bError} = oMessage; switch (sActionDone) { case "parseAndSpellcheck": if (!bEnd) { oGrammalecte.oGCPanel.addParagraphResult(result); } else { oGrammalecte.oGCPanel.stopWaitIcon(); } | > | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | /* Connexion to the background */ let xGrammalectePort = browser.runtime.connect({name: "content-script port"}); xGrammalectePort.onMessage.addListener(function (oMessage) { let {sActionDone, result, dInfo, bEnd, bError} = oMessage; let sText = ""; switch (sActionDone) { case "parseAndSpellcheck": if (!bEnd) { oGrammalecte.oGCPanel.addParagraphResult(result); } else { oGrammalecte.oGCPanel.stopWaitIcon(); } |
︙ | ︙ | |||
149 150 151 152 153 154 155 | } else { oGrammalecte.oLxgPanel.stopWaitIcon(); } break; case "getSpellSuggestions": oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, dInfo.sErrorId); break; | > | | > > | | > | > > > > > > | | > > > > > > | > > > | > | > > > > > > | | > > > > > > | > > | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | } else { oGrammalecte.oLxgPanel.stopWaitIcon(); } break; case "getSpellSuggestions": oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, dInfo.sErrorId); break; /* Commands received from the context menu (Context menu are initialized in background) */ // Grammar checker commands case "rightClickGCEditableNode": oGrammalecte.startGCPanel(xRightClickedNode); sText = (xRightClickedNode.tagName == "TEXTAREA") ? xRightClickedNode.value : xRightClickedNode.textContent; xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {sTextAreaId: xRightClickedNode.id} }); break; case "rightClickGCPage": oGrammalecte.startGCPanel(); xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: "je test", sCountry: "FR", bDebug: false, bContext: false}, dInfo: {sTextAreaId: xRightClickedNode.id} }); break; case "rightClickGCSelectedText": oGrammalecte.startGCPanel(); // selected text is sent to the GC worker in the background script. break; // Lexicographer commands case "rightClickLxgEditableNode": oGrammalecte.startLxgPanel(); sText = (xRightClickedNode.tagName == "TEXTAREA") ? xRightClickedNode.value : xRightClickedNode.textContent; xGrammalectePort.postMessage({ sCommand: "getListOfTokens", dParam: {sText: sText}, dInfo: {sTextAreaId: xRightClickedNode.id} }); break; case "rightClickLxgPage": oGrammalecte.startLxgPanel(); xGrammalectePort.postMessage({ sCommand: "getListOfTokens", dParam: {sText: "Je teste."}, dInfo: {sTextAreaId: xRightClickedNode.id} }); break; case "rightClickLxgSelectedText": oGrammalecte.startLxgPanel(); // selected text is sent to the GC worker in the background script. break; // rescan page command case "rescanPage": oGrammalecte.rescanPage(); break; default: console.log("[Content script] Unknown command: " + sActionDone); } }); |
︙ | ︙ |
Modified gc_lang/fr/webext/content_scripts/menu.js from [296905930b] to [18891f63f4].
︙ | ︙ | |||
34 35 36 37 38 39 40 | }; xMenu.appendChild(xTFButton); } // lexicographe let xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Lexicographe"}); xLxgButton.onclick = () => { this.switchMenu(); | | < < < | < < < | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | }; xMenu.appendChild(xTFButton); } // lexicographe let xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Lexicographe"}); xLxgButton.onclick = () => { this.switchMenu(); oGrammalecte.startLxgPanel(); xGrammalectePort.postMessage({ sCommand: "getListOfTokens", dParam: {sText: sText}, dInfo: {sTextAreaId: xNode.id} }); }; xMenu.appendChild(xLxgButton); // Grammar checker let xGCButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Correction grammaticale"}); xGCButton.onclick = () => { this.switchMenu(); oGrammalecte.startGCPanel(xNode); xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {sTextAreaId: xNode.id} }); }; xMenu.appendChild(xGCButton); |
︙ | ︙ |