From 7267e1bcaa0d50bd8fbb252e833d77ce8a92f773 Mon Sep 17 00:00:00 2001 From: wareya Date: Thu, 2 Jan 2020 19:19:25 -0500 Subject: [PATCH] fix permissions problem preventing mining from working --- background-script.js | 10 +++++++--- livemining.html | 4 ---- livemining.js | 9 ++++----- manifest.json | 4 ++-- texthook.js | 12 ++++++------ 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/background-script.js b/background-script.js index 922bb0f..981eb17 100644 --- a/background-script.js +++ b/background-script.js @@ -1967,7 +1967,7 @@ function send_error(tab, error) try { browser.tabs.sendMessage(tab, {type:"error",error:error}); - } catch (err) {} + } catch (err) {console.log("failed to send error to origin tab")} } browser.runtime.onMessage.addListener((req, sender) => @@ -2011,6 +2011,7 @@ browser.runtime.onMessage.addListener((req, sender) => console.log("got request"); let xhr = new XMLHttpRequest(); xhr.open("POST", req.host, true); + xhr.overrideMimeType('application/json'); //xhr.setRequestHeader('Content-type','application/json; charset=utf-8'); console.log(req.command); xhr.addEventListener('load', () => @@ -2030,11 +2031,14 @@ browser.runtime.onMessage.addListener((req, sender) => newxhr.send('{"action": "sync","version": 6}'); } } - } catch (e) { } + } catch (e) { + console.log(e); + } }); - xhr.addEventListener('error', () => + xhr.addEventListener('error', (e) => { send_error(sender.tab.id, "AnkiConnect mining failed: unspecified error (Anki is probably not open)"); + console.log(e); }); xhr.addEventListener('timeout', () => { diff --git a/livemining.html b/livemining.html index 7b0580b..138c233 100644 --- a/livemining.html +++ b/livemining.html @@ -87,9 +87,5 @@ time_local - Time when card was mined (localized date, depends on browser and OS readings_raw - The unfiltered list of readings associated with the given word. Tags and restriction information, like さくや not being a reading of 夕べ, are stripped. spellings_raw - The unfiltered list of spellings associated with the given word. Tags and restriction information are stripped.

- -

Advanced

-
-
diff --git a/livemining.js b/livemining.js index 71085a5..0bf4695 100644 --- a/livemining.js +++ b/livemining.js @@ -89,7 +89,7 @@ function saveConfig() "livemining_deckname": document.querySelector("#deckname").value, "livemining_modelname": document.querySelector("#modelname").value, "livemining_fields": mappings, - "livemining_host": document.querySelector("#host").value + "livemining_host2": "http://127.0.0.1:8765" }; console.log(setstuff); browser.storage.local.set(setstuff); @@ -97,15 +97,13 @@ function saveConfig() function loadConfig() { - let promise = browser.storage.local.get(["livemining_deckname", "livemining_modelname", "livemining_fields", "livemining_host"]); + let promise = browser.storage.local.get(["livemining_deckname", "livemining_modelname", "livemining_fields", "livemining_host2"]); promise.then((storage) => { if(storage["livemining_deckname"] !== undefined) document.querySelector("#deckname").value = storage["livemining_deckname"]; if(storage["livemining_modelname"] !== undefined) document.querySelector("#modelname").value = storage["livemining_modelname"]; - if(storage["livemining_host"] !== undefined) - document.querySelector("#host").value = storage["livemining_host"]; reset_fields(); for(let pair of storage["livemining_fields"]) add_field(pair[0], pair[1]); @@ -117,7 +115,7 @@ function buildpage() { document.getElementById("autofields").onclick = (e) => { - let host = document.getElementById("host").value; + let host = "http://127.0.0.1:8765"; let request = JSON.parse(` {"action":"modelFieldNames", @@ -167,6 +165,7 @@ function buildpage() }; document.getElementById("applyfields").onclick = saveConfig; + document.getElementById("host").onclick = saveConfig; loadConfig(); diff --git a/manifest.json b/manifest.json index ec29888..5db3c5c 100644 --- a/manifest.json +++ b/manifest.json @@ -18,8 +18,8 @@ "storage", "tabs", "clipboardRead", - "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?*", - "http://assets.languagepod101.com/dictionary/japanese/audiomp3.php?*" + "unlimitedStorage", + "" ], "background": { diff --git a/texthook.js b/texthook.js index 30e1594..8d2194e 100644 --- a/texthook.js +++ b/texthook.js @@ -2198,11 +2198,11 @@ function send_ankiconnect_command(host, command) 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_host"]); - promise.then((storage) => + let promise = browser.storage.local.get(["livemining_deckname", "livemining_modelname", "livemining_fields", "livemining_host2"]); + promise.then((storage) => { - if(storage["livemining_host"] === undefined) - storage["livemining_host"] = "http://localhost:8765/"; + 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) @@ -2246,7 +2246,7 @@ async function mine_to_ankiconnect_with_base64_audio(object, audiofname, audioda "data": audiodata } }; - send_ankiconnect_command(storage["livemining_host"], mediafilecommand); + send_ankiconnect_command(storage["livemining_host2"], mediafilecommand); audioadded = true; } // for some reason not even anki 2.0 supports this @@ -2260,7 +2260,7 @@ async function mine_to_ankiconnect_with_base64_audio(object, audiofname, audioda } } note["params"]["note"]["fields"] = fields; - send_ankiconnect_command(storage["livemining_host"], note); + send_ankiconnect_command(storage["livemining_host2"], note); }, (e) => {console.log(e);}); }