fix permissions problem preventing mining from working
This commit is contained in:
1 parent
7860b009b5
commit
7267e1bcaa
5 files changed
+18
-19
No files matched your search
@@ -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', () =>
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
</p>
|
||||
|
||||
<h2>Advanced</h2>
|
||||
<input type="text" value="http://localhost:8765/" id="host"><br>
|
||||
<label for="host">Ankiconnect host (default: http://localhost:8765/) (You probably don't want to change this!)</label><br>
|
||||
</body>
|
||||
</html>
|
||||
+4
-5
@@ -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();
|
||||
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@
|
||||
"storage",
|
||||
"tabs",
|
||||
"clipboardRead",
|
||||
"https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?*",
|
||||
"http://assets.languagepod101.com/dictionary/japanese/audiomp3.php?*"
|
||||
"unlimitedStorage",
|
||||
"<all_urls>"
|
||||
],
|
||||
|
||||
"background": {
|
||||
|
||||
+5
-5
@@ -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"]);
|
||||
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);});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user