From 6586851348c6e45c86a6b6b3fe4cef80725729cc Mon Sep 17 00:00:00 2001 From: wareya Date: Wed, 22 Jan 2020 10:37:34 -0500 Subject: [PATCH] fix live mining page --- livemining.js | 19 ++++++++----------- manifest.json | 2 +- texthook.js | 10 +++++----- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/livemining.js b/livemining.js index 0bf4695..29e810f 100644 --- a/livemining.js +++ b/livemining.js @@ -75,6 +75,8 @@ function add_field(fieldname, preselect="") document.getElementById("containfields").appendChild(div); } +var __host = "http://127.0.0.1:8765"; + function saveConfig() { let mappings = new Array(); @@ -89,7 +91,6 @@ function saveConfig() "livemining_deckname": document.querySelector("#deckname").value, "livemining_modelname": document.querySelector("#modelname").value, "livemining_fields": mappings, - "livemining_host2": "http://127.0.0.1:8765" }; console.log(setstuff); browser.storage.local.set(setstuff); @@ -97,7 +98,7 @@ function saveConfig() function loadConfig() { - let promise = browser.storage.local.get(["livemining_deckname", "livemining_modelname", "livemining_fields", "livemining_host2"]); + let promise = browser.storage.local.get(["livemining_deckname", "livemining_modelname", "livemining_fields"]); promise.then((storage) => { if(storage["livemining_deckname"] !== undefined) @@ -105,8 +106,9 @@ function loadConfig() if(storage["livemining_modelname"] !== undefined) document.querySelector("#modelname").value = storage["livemining_modelname"]; reset_fields(); - for(let pair of storage["livemining_fields"]) - add_field(pair[0], pair[1]); + if(storage["livemining_fields"] !== undefined) + for(let pair of storage["livemining_fields"]) + add_field(pair[0], pair[1]); }, (e) => {console.log(e);}); } @@ -115,8 +117,6 @@ function buildpage() { document.getElementById("autofields").onclick = (e) => { - let host = "http://127.0.0.1:8765"; - let request = JSON.parse(` {"action":"modelFieldNames", "version":6, @@ -128,7 +128,7 @@ function buildpage() console.log(json); let xhr = new XMLHttpRequest(); - xhr.open("POST", host, true); + xhr.open("POST", __host, true); //xhr.setRequestHeader('Content-type','application/json; charset=utf-8'); xhr.addEventListener('load', () => { @@ -165,7 +165,6 @@ function buildpage() }; document.getElementById("applyfields").onclick = saveConfig; - document.getElementById("host").onclick = saveConfig; loadConfig(); @@ -173,14 +172,12 @@ function buildpage() document.getElementById("upgrade").onclick = (e) => { - let host = document.getElementById("host").value; - let json = ` {"action":"upgrade", "version":6 }`; let xhr = new XMLHttpRequest(); - xhr.open("POST", host, true); + xhr.open("POST", __host, true); xhr.send(json); xhr.addEventListener('load', () => { diff --git a/manifest.json b/manifest.json index de92280..6c9f53d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "nazeka", - "version": "0.4.4", + "version": "0.4.5", "author": "Wareya", "homepage_url": "https://github.com/wareya/nazeka", "description": "A rikai replacement.", diff --git a/texthook.js b/texthook.js index af30208..eb83a3c 100644 --- a/texthook.js +++ b/texthook.js @@ -2199,14 +2199,14 @@ function send_ankiconnect_command(host, command) browser.runtime.sendMessage({type:"ankiconnect_mine", host:host, command:json}); } +var __host = "http://127.0.0.1:8765" + async function mine_to_ankiconnect_with_base64_audio(object, audiofname, audiodata) { let object_keys = Object.keys(object); - let promise = browser.storage.local.get(["livemining_deckname", "livemining_modelname", "livemining_fields", "livemining_host2"]); + let promise = browser.storage.local.get(["livemining_deckname", "livemining_modelname", "livemining_fields"]); promise.then((storage) => { - if(storage["livemining_host2"] === undefined) - storage["livemining_host2"] = "http://127.0.0.1:8765"; if(storage["livemining_deckname"] === undefined) storage["livemining_deckname"] = "Default"; if(storage["livemining_modelname"] === undefined) @@ -2250,7 +2250,7 @@ async function mine_to_ankiconnect_with_base64_audio(object, audiofname, audioda "data": audiodata } }; - send_ankiconnect_command(storage["livemining_host2"], mediafilecommand); + send_ankiconnect_command(__host, mediafilecommand); audioadded = true; } // for some reason not even anki 2.0 supports this @@ -2264,7 +2264,7 @@ async function mine_to_ankiconnect_with_base64_audio(object, audiofname, audioda } } note["params"]["note"]["fields"] = fields; - send_ankiconnect_command(storage["livemining_host2"], note); + send_ankiconnect_command(__host, note); }, (e) => {console.log(e);}); }