Index: gc_lang/fr/webext/panel/lex_editor.js ================================================================== --- gc_lang/fr/webext/panel/lex_editor.js +++ gc_lang/fr/webext/panel/lex_editor.js @@ -57,10 +57,14 @@ document.getElementById(sElemId).style.display = sDisplay; } } } +function showMessage (sMessage) { + console.log(sMessage); +} + const oTabulations = { lPage: ["lexicon_page", "add_page", "search_page", "info_page"], @@ -502,10 +506,11 @@ catch (e) { showError(e); } } } + const oDictHandler = { oDictionaries: {}, oPersonalDictionary: null, lCreatedDictionaries: [], @@ -591,13 +596,62 @@ this.oDictionaries[sName] = oJSON; if (oJSON === null) { delete this.oDictionaries[sName]; } browser.storage.local.set({ "shared_dictionaries": this.oDictionaries }); + this.sendDictionaryOnline(oJSON); + } + }, + + sendDictionaryOnline: function (oJSON) { + let sJSON = ""; + try { + sJSON = JSON.stringify(oJSON); + } + catch (e) { + showError(e); + return e.message; } + console.log("Send online dictionary: " + oJSON.sDicName); + fetch("http://localhost/receive/", { + method: "POST", // *GET, POST, PUT, DELETE, etc. + //mode: "cors", // no-cors, cors, *same-origin + //cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached + credentials: "include", // include, *same-origin, omit + headers: { + "Content-Type": "application/json", // text/plain, application/json + "Content-Length": sJSON.length + }, + redirect: "follow", // manual, *follow, error + referrer: "no-referrer", // no-referrer, *client + body: sJSON, // body data type must match "Content-Type" header + }) + .then((response) => { + if (response.ok) { + for (let param in response) { + console.log(param, response[param]); + } + console.log(response); + return response.json(); + } else { + console.log("Error: dictionary not sent: " + oJSON.sDicName); + return null; + } + }) + .then((response) => { + if (response) { + console.log(response); + } else { + // + } + }) + .catch((e) => { + showError(e); + }); } } + const oBinaryDict = { oIBDAWG: null, sName: "",