Overview
Comment: | [fx] attempt for the lexicographer (can’t work that way, it seems) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | fx | webext2 |
Files: | files | file ages | folders |
SHA3-256: |
fd7a9b5ca39b9c90309c170dc9d5bb77 |
User & Date: | olr on 2017-08-08 13:08:16 |
Other Links: | branch diff | manifest | tags |
Context
2017-08-08
| ||
17:25 | [fx] conjugueur: panneau et onglet check-in: 1f91810c3d user: olr tags: fx, webext2 | |
16:39 | [fx] merge webext2 check-in: 1eac03608e user: IllusionPerdu tags: fx, webext2_fix | |
13:08 | [fx] attempt for the lexicographer (can’t work that way, it seems) check-in: fd7a9b5ca3 user: olr tags: fx, webext2 | |
2017-08-07
| ||
15:09 | [fx] tests with context menus check-in: f7b29b571c user: olr tags: fx, webext2 | |
Changes
Modified gc_lang/fr/webext/background.js from [fa74ac872d] to [f23ea27e23].
1 2 3 4 5 6 7 8 9 10 11 12 | // Background "use strict"; /* Worker (separate thread to avoid freezing Firefox) */ let xGCEWorker = new Worker("gce_worker.js"); xGCEWorker.onmessage = function (e) { // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent | > > > > | | | | | | | | | | | | | | | | | | | | | | | | | > > | | | | | | | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 61 | // Background "use strict"; function showError (e) { console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message); } /* Worker (separate thread to avoid freezing Firefox) */ let xGCEWorker = new Worker("gce_worker.js"); xGCEWorker.onmessage = function (e) { // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent try { switch (e.data[0]) { case "grammar_errors": console.log("GRAMMAR ERRORS"); console.log(e.data[1].aGrammErr); browser.runtime.sendMessage({sCommand: "grammar_errors", aGrammErr: e.data[1].aGrammErr}); break; case "spelling_and_grammar_errors": console.log("SPELLING AND GRAMMAR ERRORS"); console.log(e.data[1].aSpellErr); console.log(e.data[1].aGrammErr); break; case "text_to_test_result": browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: e.data[1]}); break; case "fulltests_result": console.log("TESTS RESULTS"); browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: e.data[1]}); break; case "options": console.log("OPTIONS"); console.log(e.data[1]); break; case "tokens": console.log("TOKENS"); console.log(e.data[1]); browser.browserAction.setPopup({popup: "panel/main.html"}); browser.runtime.sendMessage({sCommand: "show_tokens", oResult: e.data[1]}); break; case "error": console.log("ERROR"); console.log(e.data[1]); break; default: console.log("Unknown command: " + e.data[0]); } } catch (e) { showError(e); } }; xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]); /* |
︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 | 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; } }); | > > > | 109 110 111 112 113 114 115 116 117 118 119 120 121 | 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": if (xInfo.selectionText) { xGCEWorker.postMessage(["getListOfTokens", {sText: xInfo.selectionText}]); } break; } }); |
Modified gc_lang/fr/webext/panel/main.js from [9125bf11f9] to [def169afbc].
1 2 3 4 | // Main panel "use strict"; | | > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Main panel "use strict"; /* Common functions */ function showError (e) { console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message); } function showPage (sPageName) { try { // hide them all |
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | //document.getElementById("movewindow").style.display = "block"; } } catch (e) { showError(e); } } /* Events */ window.addEventListener( "click", | > > > > > > > > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | //document.getElementById("movewindow").style.display = "block"; } } catch (e) { showError(e); } } function startWaitIcon () { document.getElementById("waiticon").hidden = false; } function stopWaitIcon () { document.getElementById("waiticon").hidden = true; } /* Events */ window.addEventListener( "click", |
︙ | ︙ | |||
79 80 81 82 83 84 85 | } /* Messages received */ function handleMessage (oMessage, xSender, sendResponse) { | | > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 89 90 91 92 93 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | } /* Messages received */ function handleMessage (oMessage, xSender, sendResponse) { console.log(xSender); switch(oMessage.sCommand) { case "show_tokens": console.log("show tokens"); addParagraphOfTokens(oMessage.oResult); break; case "text_to_test_result": showTestResult(oMessage.sResult); break; case "fulltests_result": showTestResult(oMessage.sResult); break; } sendResponse({sCommand: "none", sResult: "done"}); } browser.runtime.onMessage.addListener(handleMessage); /* DEDICATED FUNCTIONS */ /* Test page */ function showTestResult (sText) { document.getElementById("tests_result").textContent = sText; } /* Lexicographer page */ function addSeparator (sText) { if (document.getElementById("tokens_list").textContent !== "") { let xElem = document.createElement("p"); xElem.className = "separator"; xElem.textContent = sText; document.getElementById("tokens_list").appendChild(xElem); } } function addMessage (sClass, sText) { let xNode = document.createElement("p"); xNode.className = sClass; xNode.textContent = sText; document.getElementById("tokens_list").appendChild(xNode); } function addParagraphOfTokens (lElem) { try { let xNodeDiv = document.createElement("div"); xNodeDiv.className = "paragraph"; for (let oToken of lElem) { xNodeDiv.appendChild(createTokenNode(oToken)); } document.getElementById("tokens_list").appendChild(xNodeDiv); } catch (e) { showError(e); } } function createTokenNode (oToken) { let xTokenNode = document.createElement("div"); xTokenNode.className = "token " + oToken.sType; let xTokenValue = document.createElement("b"); xTokenValue.className = oToken.sType; xTokenValue.textContent = oToken.sValue; xTokenNode.appendChild(xTokenValue); let xSep = document.createElement("s"); xSep.textContent = " : "; xTokenNode.appendChild(xSep); if (oToken.aLabel.length === 1) { xTokenNode.appendChild(document.createTextNode(oToken.aLabel[0])); } else { let xTokenList = document.createElement("ul"); for (let sLabel of oToken.aLabel) { let xTokenLine = document.createElement("li"); xTokenLine.textContent = sLabel; xTokenList.appendChild(xTokenLine); } xTokenNode.appendChild(xTokenList); } return xTokenNode; } |