diff --git a/background-script.js b/background-script.js index c2d00b3..349d978 100644 --- a/background-script.js +++ b/background-script.js @@ -1523,14 +1523,20 @@ browser.runtime.onMessage.addListener((req, sender) => } else if (req.type == "ankiconnect_mine") { + console.log("got request"); let xhr = new XMLHttpRequest(); xhr.open("POST", req.host, true); //xhr.setRequestHeader('Content-type','application/json; charset=utf-8'); + console.log(req.command); xhr.addEventListener('load', () => { + console.log(xhr.responseText); let response = JSON.parse(xhr.responseText); - if(response.error) - send_error(sender.tab.id, "AnkiConnect mining failed: " + response.error); + try + { + if(response.error) + send_error(sender.tab.id, "AnkiConnect mining failed: " + response.error); + } catch (e) { } }); xhr.addEventListener('error', () => { diff --git a/livemining.html b/livemining.html index 60e30f6..60c01f4 100644 --- a/livemining.html +++ b/livemining.html @@ -6,6 +6,9 @@ Nazeka: Configuration for Live Mining +

Configuration for Live Mining

@@ -13,9 +16,11 @@

Live Mining requires Anki and the Ankiconnect plugin.

-

If Live Mining is enabled, then when you mine notes to the mining storage, Nazeka will also attempt to connect to Ankiconnect and tell it to insert a new note.

+

If Live Mining is enabled, then when you mine words to the mining storage (the list you see when you select "View Mined Cards"), Nazeka will also attempt to connect to Ankiconnect and tell it to insert a new note.

-

This is still experimental. Nazeka might not show any error messages if Ankiconnect fails to insert the new note. I only tested errors shown when Anki isn't running.

+

If this is your first time using live mining, please press the button below. This will make Ankiconnect ask you if it's okay to update to the latest version, then update if you say yes. Doing so fixes several bugs present in old versions of Ankiconnect, and this is important, because the version on Ankiweb sometimes falls behind the latest version. This requires Anki to be running with Ankiconnect already enabled.

+ +

Deck and Model


@@ -25,7 +30,7 @@

Fields


-
+
(Unpopulated) diff --git a/livemining.js b/livemining.js index d693afb..51fbf50 100644 --- a/livemining.js +++ b/livemining.js @@ -49,6 +49,17 @@ function add_options(input, preselect="") } } +function get_fields() +{ + let mappings = new Map(); + for(let element of document.querySelectorAll("#containfields > div")) + { + console.log(element); + mappings.set(element.querySelector("label").innerText, element.querySelector("select").value); + } + return mappings; +} + function add_field(fieldname, preselect="") { let div = document.createElement("div"); @@ -103,7 +114,7 @@ function loadConfig() function buildpage() { - document.getElementById("autofields").onclick = function(e) + document.getElementById("autofields").onclick = (e) => { let host = document.getElementById("host").value; @@ -125,9 +136,16 @@ function buildpage() let response = JSON.parse(xhr.responseText); if (response["result"]) { + let old_fields = get_fields(); reset_fields(); for(let fieldname of response["result"]) - add_field(fieldname); + { + let old = old_fields.get(fieldname); + if(old !== undefined) + add_field(fieldname, old); + else + add_field(fieldname); + } } }); xhr.send(json); @@ -140,6 +158,20 @@ function buildpage() loadConfig(); document.getElementById("loadfields").onclick = loadConfig; + + 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.send(json); + e.preventDefault(); + }; } if (document.readyState == "complete") { diff --git a/options.js b/options.js index c009e06..67bbf30 100644 --- a/options.js +++ b/options.js @@ -63,7 +63,7 @@ function defaults() settings.push({ id: "alternatives_mode", kind: "combobox", - options: ["Longest match only", "Longest and shortest match", "Longest and second longest match", "All matches"], + options: ["Longest match only", "Longest and second longest match", "Longest and shortest match", "All matches"], default: 3, label: "Matching mode" }); diff --git a/texthook.js b/texthook.js index d16a379..95c6cdd 100644 --- a/texthook.js +++ b/texthook.js @@ -25,7 +25,7 @@ superborder: false, showoriginal: true, definitions_mode: 0, normal_definitions_in_mining: false, -alternatives_mode: 0, // 0: longest only; 1: longest and shortest; 2: longest and second longest; 3: all matches +alternatives_mode: 3, // 0: longest only; 1: longest and shortest; 2: longest and second longest; 3: all matches strict_alternatives: true, // if true, alternatives looked up in all kana can not return results with kanji glosses that don't have any usually/exclusively kana info strict_epwing: true, scale: 1, @@ -1207,11 +1207,11 @@ async function settings_init() getvar("bgcolor", "#111111"); getvar("fgcolor", "#CCCCCC"); getvar("hlcolor", "#99DDFF"); - getvar("hlcolor2", "#66DD44"); + getvar("hlcolor2", "#99FF99"); getvar("font", ""); getvar("hlfont", ""); - getvar("alternatives_mode", 0); + getvar("alternatives_mode", 3); getvar("strict_alternatives", true); getvar("definitions_mode", 0); getvar("normal_definitions_in_mining", false);