minor ankiconnect fixes and other minor fixes

This commit is contained in:
wareya committed 2019-05-02 07:49:03 -04:00
1 parent 16827e8b57
commit 5d092dbc3a
5 files changed
+54 -11

No files matched your search

+8 -2
View File
@@ -1523,14 +1523,20 @@ browser.runtime.onMessage.addListener((req, sender) =>
} }
else if (req.type == "ankiconnect_mine") else if (req.type == "ankiconnect_mine")
{ {
console.log("got request");
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.open("POST", req.host, true); xhr.open("POST", req.host, true);
//xhr.setRequestHeader('Content-type','application/json; charset=utf-8'); //xhr.setRequestHeader('Content-type','application/json; charset=utf-8');
console.log(req.command);
xhr.addEventListener('load', () => xhr.addEventListener('load', () =>
{ {
console.log(xhr.responseText);
let response = JSON.parse(xhr.responseText); let response = JSON.parse(xhr.responseText);
if(response.error) try
send_error(sender.tab.id, "AnkiConnect mining failed: " + response.error); {
if(response.error)
send_error(sender.tab.id, "AnkiConnect mining failed: " + response.error);
} catch (e) { }
}); });
xhr.addEventListener('error', () => xhr.addEventListener('error', () =>
{ {
+8 -3
View File
@@ -6,6 +6,9 @@
<title>Nazeka: Configuration for Live Mining</title> <title>Nazeka: Configuration for Live Mining</title>
<script src="include/browser-polyfill.min.js" charset="UTF-8"></script> <script src="include/browser-polyfill.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="livemining.js"></script> <script type="text/javascript" src="livemining.js"></script>
<style>
body { max-width: 800px; margin-left: auto; margin-right: auto; padding-left: 8px; padding-right: 8px; }
</style>
</head> </head>
<body> <body>
<h2>Configuration for Live Mining</h2> <h2>Configuration for Live Mining</h2>
@@ -13,9 +16,11 @@
<p>Live Mining requires <a href="https://apps.ankiweb.net/">Anki</a> and the <a href="https://ankiweb.net/shared/info/2055492159">Ankiconnect</a> plugin.</p> <p>Live Mining requires <a href="https://apps.ankiweb.net/">Anki</a> and the <a href="https://ankiweb.net/shared/info/2055492159">Ankiconnect</a> plugin.</p>
<p>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.</p> <p>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.</p>
<p>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.</p> <p>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.</p>
<input type="button" id="upgrade" value="Update Ankiconnect">
<h2>Deck and Model</h2> <h2>Deck and Model</h2>
<input type="text" value="Default" id="deckname"><br> <input type="text" value="Default" id="deckname"><br>
@@ -25,7 +30,7 @@
<h2>Fields</h2> <h2>Fields</h2>
<input type="button" id="autofields" value="Populate"><br> <input type="button" id="autofields" value="Populate"><br>
<label for="autofields">Button will connect to Ankiconnect and automatically populate a list of field inputs based on card model/template name, overwriting EVERYTHING that is currently here.</label><br> <label for="autofields">Populate button will connect to Ankiconnect and automatically populate a list of field inputs based on card model/template name, overwriting EVERYTHING that is currently here.</label><br>
<div id="containfields"> <div id="containfields">
(Unpopulated) (Unpopulated)
+34 -2
View File
@@ -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="") function add_field(fieldname, preselect="")
{ {
let div = document.createElement("div"); let div = document.createElement("div");
@@ -103,7 +114,7 @@ function loadConfig()
function buildpage() function buildpage()
{ {
document.getElementById("autofields").onclick = function(e) document.getElementById("autofields").onclick = (e) =>
{ {
let host = document.getElementById("host").value; let host = document.getElementById("host").value;
@@ -125,9 +136,16 @@ function buildpage()
let response = JSON.parse(xhr.responseText); let response = JSON.parse(xhr.responseText);
if (response["result"]) if (response["result"])
{ {
let old_fields = get_fields();
reset_fields(); reset_fields();
for(let fieldname of response["result"]) 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); xhr.send(json);
@@ -140,6 +158,20 @@ function buildpage()
loadConfig(); loadConfig();
document.getElementById("loadfields").onclick = 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") if (document.readyState == "complete")
{ {
+1 -1
View File
@@ -63,7 +63,7 @@ function defaults()
settings.push({ settings.push({
id: "alternatives_mode", id: "alternatives_mode",
kind: "combobox", 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, default: 3,
label: "Matching mode" label: "Matching mode"
}); });
+3 -3
View File
@@ -25,7 +25,7 @@ superborder: false,
showoriginal: true, showoriginal: true,
definitions_mode: 0, definitions_mode: 0,
normal_definitions_in_mining: false, 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_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, strict_epwing: true,
scale: 1, scale: 1,
@@ -1207,11 +1207,11 @@ async function settings_init()
getvar("bgcolor", "#111111"); getvar("bgcolor", "#111111");
getvar("fgcolor", "#CCCCCC"); getvar("fgcolor", "#CCCCCC");
getvar("hlcolor", "#99DDFF"); getvar("hlcolor", "#99DDFF");
getvar("hlcolor2", "#66DD44"); getvar("hlcolor2", "#99FF99");
getvar("font", ""); getvar("font", "");
getvar("hlfont", ""); getvar("hlfont", "");
getvar("alternatives_mode", 0); getvar("alternatives_mode", 3);
getvar("strict_alternatives", true); getvar("strict_alternatives", true);
getvar("definitions_mode", 0); getvar("definitions_mode", 0);
getvar("normal_definitions_in_mining", false); getvar("normal_definitions_in_mining", false);