aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-10-15 19:51:41 -0700
committerAlex Yatskov <alex@foosoft.net>2016-10-15 19:51:41 -0700
commit5057d6b6cff3bb9a176f3d96e64c878843dd443e (patch)
treee7c2d0567f85f17a981619e4acde9cf82f7b5da8 /ext/bg
parent49f98a8c53c396cc0fe69a62c7e2a2ce004f32ce (diff)
WIP
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/background.html1
-rw-r--r--ext/bg/js/ankiweb.js47
-rw-r--r--ext/bg/js/util.js2
3 files changed, 27 insertions, 23 deletions
diff --git a/ext/bg/background.html b/ext/bg/background.html
index 65707416..a849fadb 100644
--- a/ext/bg/background.html
+++ b/ext/bg/background.html
@@ -2,7 +2,6 @@
<html lang="en">
<body>
<script src="../lib/handlebars.min.js"></script>
- <script src="../lib/jquery-2.2.2.min.js"></script>
<script src="../lib/dexie.min.js"></script>
<script src="js/ankiweb.js"></script>
<script src="js/ankiconnect.js"></script>
diff --git a/ext/bg/js/ankiweb.js b/ext/bg/js/ankiweb.js
index 6cfc50be..9abd9b86 100644
--- a/ext/bg/js/ankiweb.js
+++ b/ext/bg/js/ankiweb.js
@@ -75,12 +75,9 @@ class AnkiWeb {
static scrape() {
return new Promise((resolve, reject) => {
- $.get('https://ankiweb.net/edit/', (data, status) => {
- if (status !== 'success') {
- reject('failed to execute scrape request');
- return;
- }
-
+ const xhr = new XMLHttpRequest();
+ xhr.addEventListener('error', () => reject('failed to execute scrape request'));
+ xhr.addEventListener('load', () => {
const modelsJson = JSON.parse(/editor\.models = (.*}]);/.exec(data)[1]);
if (!modelsJson) {
reject('failed to scrape model data');
@@ -105,34 +102,42 @@ class AnkiWeb {
resolve({deckNames, models});
});
+
+ xhr.open('GET', 'https://ankiweb.net/edit/');
+ xhr.send();
});
}
static login(username, password) {
return new Promise((resolve, reject) => {
- $.post('https://ankiweb.net/account/login', {username, password, submitted: 1}, (data, status) => {
- if (status === 'success') {
- if (data.includes('class="mitem"')) {
- resolve();
- } else {
- reject('failed to authenticate');
- }
+ const xhr = new XMLHttpRequest();
+ xhr.addEventListener('error', () => reject('failed to execute login request'));
+ xhr.addEventListener('success', () => {
+ if (xhr.responseText.includes('class="mitem"')) {
+ resolve();
} else {
- reject('failed to execute login request');
+ reject('failed to authenticate');
}
});
+
+ const form = new FormData();
+ form.append('username', username);
+ form.append('password', password);
+ form.append('submitted', 1);
+
+ xhr.open('POST', 'https://ankiweb.net/account/login');
+ xhr.send(form);
});
}
static logout() {
return new Promise((resolve, reject) => {
- $.get('https://ankiweb.net/account/logout', (data, status) => {
- if (status === 'success') {
- resolve();
- } else {
- reject('failed to execute logout request');
- }
- });
+ const xhr = new XMLHttpRequest();
+ xhr.addEventListener('error', () => reject('failed to execute logout request'));
+ xhr.addEventListener('load', () => resolve());
+
+ xhr.open('GET', 'https://ankiweb.net/account/logout');
+ xhr.send();
});
}
}
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 95d1b43e..1e033eef 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -34,7 +34,7 @@ function loadJson(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', () => resolve(JSON.parse(xhr.responseText)));
- xhr.open('GET', chrome.extension.getURL(url), true);
+ xhr.open('GET', chrome.extension.getURL(url));
xhr.send();
});
}