tiny improevment to context grabbing; error messages on live mining config page
This commit is contained in:
1 parent
8e7772ad5c
commit
9e84c36afb
2 files changed
+49
-2
No files matched your search
+47
-2
@@ -134,11 +134,11 @@ function buildpage()
|
||||
xhr.addEventListener('load', () =>
|
||||
{
|
||||
let response = JSON.parse(xhr.responseText);
|
||||
if (response["result"])
|
||||
if (response.result)
|
||||
{
|
||||
let old_fields = get_fields();
|
||||
reset_fields();
|
||||
for(let fieldname of response["result"])
|
||||
for(let fieldname of response.result)
|
||||
{
|
||||
let old = old_fields.get(fieldname);
|
||||
if(old !== undefined)
|
||||
@@ -147,6 +147,18 @@ function buildpage()
|
||||
add_field(fieldname);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errormessage(response.error);
|
||||
}
|
||||
});
|
||||
xhr.addEventListener('error', () =>
|
||||
{
|
||||
errormessage("AnkiConnect messaging failed: unspecified error (Anki is probably not open)");
|
||||
});
|
||||
xhr.addEventListener('timeout', () =>
|
||||
{
|
||||
errormessage("AnkiConnect messaging failed: timed out");
|
||||
});
|
||||
xhr.send(json);
|
||||
|
||||
@@ -170,6 +182,22 @@ function buildpage()
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", host, true);
|
||||
xhr.send(json);
|
||||
xhr.addEventListener('load', () =>
|
||||
{
|
||||
let response = JSON.parse(xhr.responseText);
|
||||
if (!response.result)
|
||||
{
|
||||
errormessage(response.error);
|
||||
}
|
||||
});
|
||||
xhr.addEventListener('error', () =>
|
||||
{
|
||||
errormessage("AnkiConnect messaging failed: unspecified error (Anki is probably not open)");
|
||||
});
|
||||
xhr.addEventListener('timeout', () =>
|
||||
{
|
||||
errormessage("AnkiConnect messaging failed: timed out");
|
||||
});
|
||||
e.preventDefault();
|
||||
};
|
||||
}
|
||||
@@ -181,3 +209,20 @@ else
|
||||
{
|
||||
document.addEventListener("DOMContentLoaded", buildpage);
|
||||
}
|
||||
|
||||
|
||||
function errormessage(text)
|
||||
{
|
||||
if(!text) return;
|
||||
let mydiv = document.createElement("div");
|
||||
mydiv.style = "background-color: #111; color: #CCC; font-family: Arial, sans-serif; font-size: 13px; width: 300px; border: 3px double red; position: fixed; right: 25px; top: 25px; z-index: 1000000000000000000000; padding: 5px; border-radius: 3px;"
|
||||
mydiv.textContent = text;
|
||||
document.body.appendChild(mydiv);
|
||||
|
||||
function delete_later()
|
||||
{
|
||||
mydiv.remove();
|
||||
}
|
||||
|
||||
setTimeout(delete_later, 3000);
|
||||
}
|
||||
@@ -1646,6 +1646,8 @@ function grab_text(textNode, offset, elemental)
|
||||
|
||||
while(!japaneseSeparators.includes(moreText[index + rightwards]) && moreText[index + rightwards] != "\n" && index + rightwards < moreText.length)
|
||||
rightwards++;
|
||||
while(japanesePunctuation.includes(moreText[index + rightwards]) && index + rightwards < moreText.length)
|
||||
rightwards++;
|
||||
|
||||
moreText = moreText.substring(index+leftwards, index+rightwards);
|
||||
text = text.substring(0, rightwards);
|
||||
|
||||
Reference in new issue
Block a user