aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-08-22 19:44:31 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-08-26 21:58:03 -0400
commita39a1fa9e4700d1189dfc5073b5fcb2557965671 (patch)
treea803e03e64285d3c2b1c6d4c0e4ee87eee2cb266 /ext/bg
parent8ebac935e8c0ee167514d5726b1e2e16921e4957 (diff)
Add support for Edge browser
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/background.html2
-rw-r--r--ext/bg/context.html2
-rw-r--r--ext/bg/js/search.js2
-rw-r--r--ext/bg/js/settings.js31
-rw-r--r--ext/bg/js/util.js16
-rw-r--r--ext/bg/search.html2
-rw-r--r--ext/bg/settings.html2
7 files changed, 39 insertions, 18 deletions
diff --git a/ext/bg/background.html b/ext/bg/background.html
index 3262f2a1..5978f10f 100644
--- a/ext/bg/background.html
+++ b/ext/bg/background.html
@@ -10,6 +10,8 @@
<script src="/mixed/lib/jszip.min.js"></script>
<script src="/mixed/lib/wanakana.min.js"></script>
+ <script src="/mixed/js/extension.js"></script>
+
<script src="/bg/js/anki.js"></script>
<script src="/bg/js/api.js"></script>
<script src="/bg/js/audio.js"></script>
diff --git a/ext/bg/context.html b/ext/bg/context.html
index 01b4fb30..198ccd42 100644
--- a/ext/bg/context.html
+++ b/ext/bg/context.html
@@ -32,6 +32,8 @@
<script src="/mixed/lib/jquery.min.js"></script>
<script src="/mixed/lib/bootstrap-toggle/bootstrap-toggle.min.js"></script>
+ <script src="/mixed/js/extension.js"></script>
+
<script src="/bg/js/api.js"></script>
<script src="/bg/js/options.js"></script>
<script src="/bg/js/util.js"></script>
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index f08f22da..a3382398 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -25,7 +25,7 @@ class DisplaySearch extends Display {
this.query = $('#query').on('input', this.onSearchInput.bind(this));
this.intro = $('#intro');
- this.dependencies = {...this.dependencies, ...{docRangeFromPoint, docSentenceExtract}};
+ this.dependencies = Object.assign({}, this.dependencies, {docRangeFromPoint, docSentenceExtract});
window.wanakana.bind(this.query.get(0));
}
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index 75082f3e..e542118c 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -116,7 +116,7 @@ async function formMainDictionaryOptionsPopulate(options) {
select.append($('<option class="text-muted" value="">Not selected</option>'));
let mainDictionary = '';
- for (const dictRow of await utilDatabaseSummarize()) {
+ for (const dictRow of toIterable(await utilDatabaseSummarize())) {
if (dictRow.sequenced) {
select.append($(`<option value="${dictRow.title}">${dictRow.title}</option>`));
if (dictRow.title === options.general.mainDictionary) {
@@ -314,12 +314,12 @@ async function dictionaryGroupsPopulate(options) {
const dictGroups = $('#dict-groups').empty();
const dictWarning = $('#dict-warning').hide();
- const dictRows = await utilDatabaseSummarize();
+ const dictRows = toIterable(await utilDatabaseSummarize());
if (dictRows.length === 0) {
dictWarning.show();
}
- for (const dictRow of dictRowsSort(dictRows, options)) {
+ for (const dictRow of toIterable(dictRowsSort(dictRows, options))) {
const dictOptions = options.dictionaries[dictRow.title] || {
enabled: false,
priority: 0,
@@ -581,20 +581,19 @@ async function onAnkiFieldTemplatesReset(e) {
*/
async function getBrowser() {
- if (typeof chrome !== "undefined") {
- if (typeof browser !== "undefined") {
- try {
- const info = await browser.runtime.getBrowserInfo();
- if (info.name === "Fennec") {
- return "firefox-mobile";
- }
- } catch (e) { }
- return "firefox";
- } else {
- return "chrome";
- }
+ if (EXTENSION_IS_BROWSER_EDGE) {
+ return 'edge';
+ }
+ if (typeof browser !== 'undefined') {
+ try {
+ const info = await browser.runtime.getBrowserInfo();
+ if (info.name === 'Fennec') {
+ return 'firefox-mobile';
+ }
+ } catch (e) { }
+ return 'firefox';
} else {
- return "edge";
+ return 'chrome';
}
}
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 34b06ddb..3dc7c900 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -87,6 +87,20 @@ function utilDatabasePurge() {
return utilBackend().translator.database.purge();
}
-function utilDatabaseImport(data, progress, exceptions) {
+async function utilDatabaseImport(data, progress, exceptions) {
+ // Edge cannot read data on the background page due to the File object
+ // being created from a different window. Read on the same page instead.
+ if (EXTENSION_IS_BROWSER_EDGE) {
+ data = await utilReadFile(data);
+ }
return utilBackend().translator.database.importDictionary(data, progress, exceptions);
}
+
+function utilReadFile(file) {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = () => resolve(reader.result);
+ reader.onerror = () => reject(reader.error);
+ reader.readAsBinaryString(file);
+ });
+}
diff --git a/ext/bg/search.html b/ext/bg/search.html
index ce156578..05c0daab 100644
--- a/ext/bg/search.html
+++ b/ext/bg/search.html
@@ -37,6 +37,8 @@
<script src="/mixed/lib/jquery.min.js"></script>
<script src="/mixed/lib/wanakana.min.js"></script>
+ <script src="/mixed/js/extension.js"></script>
+
<script src="/bg/js/api.js"></script>
<script src="/bg/js/audio.js"></script>
<script src="/bg/js/dictionary.js"></script>
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index c6677018..0704140e 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -399,6 +399,8 @@
<script src="/mixed/lib/bootstrap/js/bootstrap.min.js"></script>
<script src="/mixed/lib/handlebars.min.js"></script>
+ <script src="/mixed/js/extension.js"></script>
+
<script src="/bg/js/anki.js"></script>
<script src="/bg/js/api.js"></script>
<script src="/bg/js/dictionary.js"></script>