aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-12-29 09:36:54 -0800
committerAlex Yatskov <alex@foosoft.net>2016-12-29 09:36:54 -0800
commitc185125e9f558faa765a8b185bfe6d6e6ec8148b (patch)
tree263cc776551a875dec4c8ce3cb681a0be7497a41 /ext
parent1e6feff20720685ba7ec4d8e295b0103a78209c6 (diff)
fixing ankiweb breakage (resolves #26)
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/ankiweb.js17
-rw-r--r--ext/manifest.json9
2 files changed, 22 insertions, 4 deletions
diff --git a/ext/bg/js/ankiweb.js b/ext/bg/js/ankiweb.js
index 41bf74bd..dc6a5d49 100644
--- a/ext/bg/js/ankiweb.js
+++ b/ext/bg/js/ankiweb.js
@@ -21,6 +21,15 @@ class AnkiWeb {
this.username = username;
this.password = password;
this.noteInfo = null;
+
+ chrome.webRequest.onBeforeSendHeaders.addListener(
+ details => {
+ details.requestHeaders.push({name: 'Origin', value: 'https://ankiweb.net'});
+ return {requestHeaders: details.requestHeaders};
+ },
+ {urls: ['https://ankiweb.net/*']},
+ ['blocking', 'requestHeaders']
+ );
}
addNote(note) {
@@ -133,20 +142,22 @@ class AnkiWeb {
static loadPage(url, data) {
return new Promise((resolve, reject) => {
+ let dataEnc = null;
if (data) {
const params = [];
for (const key in data) {
params.push(`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`);
}
- url += '?' + params.join('&');
+ dataEnc = params.join('&');
}
const xhr = new XMLHttpRequest();
xhr.addEventListener('error', () => reject('failed to execute network request'));
xhr.addEventListener('load', () => resolve(xhr.responseText));
- xhr.open('GET', url);
- xhr.send();
+ xhr.open('POST', url);
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+ xhr.send(dataEnc);
});
}
}
diff --git a/ext/manifest.json b/ext/manifest.json
index 1b407bcb..6320e072 100644
--- a/ext/manifest.json
+++ b/ext/manifest.json
@@ -24,7 +24,14 @@
"options_ui": {
"page": "bg/options.html"
},
- "permissions": ["file://*/*", "http://127.0.0.1/*", "storage"],
+ "permissions": [
+ "webRequest",
+ "webRequestBlocking",
+ "file://*",
+ "http://127.0.0.1/*",
+ "https://ankiweb.net/*",
+ "storage"
+ ],
"web_accessible_resources": [
"fg/css/frame.css",
"fg/img/add_kanji.png",