From c185125e9f558faa765a8b185bfe6d6e6ec8148b Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 29 Dec 2016 09:36:54 -0800 Subject: fixing ankiweb breakage (resolves #26) --- ext/bg/js/ankiweb.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'ext/bg/js') 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); }); } } -- cgit v1.2.3