summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-07-19 21:28:09 -0700
committerAlex Yatskov <alex@foosoft.net>2017-07-19 21:28:09 -0700
commitfe137e94c92cf0366735936b6ac82dc147b1ad33 (patch)
tree76382040a15ef4fb32d6a8dfb5a7ecc023ab2fde /ext/bg
parent62db3d74b8042dd3185a7a552920a2ce7a4bd4ab (diff)
cleanup
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/background.html1
-rw-r--r--ext/bg/js/anki-connect.js2
-rw-r--r--ext/bg/js/translator.js2
-rw-r--r--ext/bg/js/util.js40
-rw-r--r--ext/bg/js/yomichan.js8
-rw-r--r--ext/bg/popup.html1
-rw-r--r--ext/bg/search.html1
-rw-r--r--ext/bg/settings.html1
8 files changed, 14 insertions, 42 deletions
diff --git a/ext/bg/background.html b/ext/bg/background.html
index 61bc17a0..7d352561 100644
--- a/ext/bg/background.html
+++ b/ext/bg/background.html
@@ -14,6 +14,7 @@
<script src="/bg/js/handlebars.js"></script>
<script src="/bg/js/dictionary.js"></script>
<script src="/mixed/js/japanese.js"></script>
+ <script src="/mixed/js/request.js"></script>
<script src="/bg/js/options.js"></script>
<script src="/bg/js/anki-connect.js"></script>
<script src="/bg/js/anki-null.js"></script>
diff --git a/ext/bg/js/anki-connect.js b/ext/bg/js/anki-connect.js
index a4d8ba3f..567e8d3f 100644
--- a/ext/bg/js/anki-connect.js
+++ b/ext/bg/js/anki-connect.js
@@ -64,6 +64,6 @@ class AnkiConnect {
}
ankiInvoke(action, params) {
- return jsonRequest(this.server, 'POST', {action, params, version: this.localVersion});
+ return requestJson(this.server, 'POST', {action, params, version: this.localVersion});
}
}
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 9232e529..1be485c7 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -31,7 +31,7 @@ class Translator {
if (!this.deinflector) {
const url = chrome.extension.getURL('/bg/lang/deinflect.json');
- const reasons = await jsonRequest(url, 'GET');
+ const reasons = await requestJson(url, 'GET');
this.deinflector = new Deinflector(reasons);
}
}
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 6e86c2a6..c7ebbb0e 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -18,19 +18,6 @@
/*
- * Promise
- */
-
-function promiseCallback(promise, callback) {
- return promise.then(result => {
- callback({result});
- }).catch(error => {
- callback({error});
- });
-}
-
-
-/*
* Commands
*/
@@ -71,30 +58,3 @@ function fgBroadcast(action, params) {
function fgOptionsSet(options) {
fgBroadcast('optionsSet', options);
}
-
-
-/*
- * JSON
- */
-
-function jsonRequest(url, action, params) {
- return new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.overrideMimeType('application/json');
- xhr.addEventListener('load', () => resolve(xhr.responseText));
- xhr.addEventListener('error', () => reject('failed to execute network request'));
- xhr.open(action, url);
- if (params) {
- xhr.send(JSON.stringify(params));
- } else {
- xhr.send();
- }
- }).then(responseText => {
- try {
- return JSON.parse(responseText);
- }
- catch (e) {
- return Promise.reject('invalid JSON response');
- }
- });
-}
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index acc560ce..eb083396 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -195,6 +195,14 @@ window.yomichan = new class {
}
onMessage({action, params}, sender, callback) {
+ const promiseCallback = (promise, callback) => {
+ return promise.then(result => {
+ callback({result});
+ }).catch(error => {
+ callback({error});
+ });
+ };
+
const handlers = {
optionsGet: ({callback}) => {
promiseCallback(optionsLoad(), callback);
diff --git a/ext/bg/popup.html b/ext/bg/popup.html
index db9097bd..b3d38533 100644
--- a/ext/bg/popup.html
+++ b/ext/bg/popup.html
@@ -32,6 +32,7 @@
<script src="/mixed/lib/handlebars.min.js"></script>
<script src="/bg/js/util.js"></script>
<script src="/bg/js/dictionary.js"></script>
+ <script src="/mixed/js/request.js"></script>
<script src="/mixed/js/japanese.js"></script>
<script src="/bg/js/options.js"></script>
<script src="/bg/js/popup.js"></script>
diff --git a/ext/bg/search.html b/ext/bg/search.html
index b30b8910..45603f17 100644
--- a/ext/bg/search.html
+++ b/ext/bg/search.html
@@ -35,6 +35,7 @@
<script src="/mixed/lib/jquery.min.js"></script>
<script src="/bg/js/util.js"></script>
<script src="/bg/js/dictionary.js"></script>
+ <script src="/mixed/js/request.js"></script>
<script src="/mixed/js/japanese.js"></script>
<script src="/mixed/js/audio.js"></script>
<script src="/mixed/js/display.js"></script>
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index 9b21b4d8..4c7198c3 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -280,6 +280,7 @@
<script src="/bg/js/handlebars.js"></script>
<script src="/bg/js/dictionary.js"></script>
<script src="/mixed/js/japanese.js"></script>
+ <script src="/mixed/js/request.js"></script>
<script src="/bg/js/options.js"></script>
<script src="/bg/js/settings.js"></script>
</body>