add error to ankiconnect mining

This commit is contained in:
wareya committed 2019-04-10 13:55:53 -04:00
1 parent d4ce7bd968
commit f411429afb
3 files changed
+28 -4

No files matched your search

+18
View File
@@ -1418,6 +1418,14 @@ async function get_real_platform()
}
get_real_platform();
function send_error(tab, error)
{
try
{
browser.tabs.sendMessage(tab, {type:"error",error:error});
} catch (err) {}
}
browser.runtime.onMessage.addListener((req, sender) =>
{
if (req.type == "search")
@@ -1449,6 +1457,16 @@ browser.runtime.onMessage.addListener((req, sender) =>
xhr.addEventListener('load', () =>
{
let response = JSON.parse(xhr.responseText);
if(response.error)
send_error(sender.tab.id, "AnkiConnect mining failed: " + response.error);
});
xhr.addEventListener('error', () =>
{
send_error(sender.tab.id, "AnkiConnect mining failed: unspecified error (Anki is probably not open)");
});
xhr.addEventListener('timeout', () =>
{
send_error(sender.tab.id, "AnkiConnect mining failed: timed out");
});
xhr.send(req.command);
}
+2 -2
View File
@@ -590,6 +590,7 @@ function buildpage()
let reader = new FileReader();
reader.onload = async(e) =>
{
// FIXME: add asking for the unlimited storage permission
try
{
browser.storage.local.set({"epwing":JSON.stringify(JSON.parse(e.target.result))});
@@ -666,8 +667,6 @@ This format can be extended in the future if it becomes desirable to include mor
let a = document.createElement("a");
a.href = url;
a.download = "nazeka_data_backup.json";
console.log("trying to virtually click this a element:");
console.log(a);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
@@ -699,6 +698,7 @@ This format can be extended in the future if it becomes desirable to include mor
};
reader.readAsText(fname);
});
// FIXME: add asking for the unlimited storage permission
let backup_load_label = document.createElement("label");
backup_load_label.for = backup_save.id;
backup_load_label.id = "backup_load_label";
+8 -2
View File
@@ -1607,11 +1607,11 @@ function update_touch(event)
}
}
function message(text)
function errormessage(text)
{
if(!text) return;
let mydiv = document.createElement("div");
mydiv.style = "background-color: rgba(0, 0, 0, 0.5); color: white; width: 200px; position: fixed; right: 25px; bottom: 25px; z-index: 1000000000000000000000; padding: 5px; border-radius: 3px;"
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);
@@ -1623,6 +1623,12 @@ function message(text)
setTimeout(delete_later, 3000);
}
browser.runtime.onMessage.addListener((req, sender) =>
{
if (req.type == "error")
errormessage(req.error);
});
async function mine_to_storage(object)
{
let cards = (await browser.storage.local.get("cards")).cards;