summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authorAlex Yatskov <FooSoft@users.noreply.github.com>2019-05-05 18:26:02 -0700
committerGitHub <noreply@github.com>2019-05-05 18:26:02 -0700
commit61d1168d94a7467be6e98afc375d7583c0f23cb5 (patch)
tree383b42f3b616c033d24f62b8d883121f6687558f /ext/bg/js/backend.js
parent43c5ef87c03307e8281366725f1196307effa9c7 (diff)
parentf2a5d5095931a78dc388d4cba66953560a336e7f (diff)
Merge pull request #160 from toasted-nutbread/mobile
Add support for mobile Firefox
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 01340419..c191a150 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -28,7 +28,9 @@ class Backend {
await this.translator.prepare();
await apiOptionsSet(await optionsLoad());
- chrome.commands.onCommand.addListener(this.onCommand.bind(this));
+ if (chrome.commands !== null && typeof chrome.commands === 'object') {
+ chrome.commands.onCommand.addListener(this.onCommand.bind(this));
+ }
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
if (this.options.general.showGuide) {
@@ -40,13 +42,13 @@ class Backend {
this.options = utilIsolate(options);
if (!options.general.enable) {
- chrome.browserAction.setBadgeBackgroundColor({color: '#555555'});
- chrome.browserAction.setBadgeText({text: 'off'});
+ this.setExtensionBadgeBackgroundColor('#555555');
+ this.setExtensionBadgeText('off');
} else if (!dictConfigured(options)) {
- chrome.browserAction.setBadgeBackgroundColor({color: '#f0ad4e'});
- chrome.browserAction.setBadgeText({text: '!'});
+ this.setExtensionBadgeBackgroundColor('#f0ad4e');
+ this.setExtensionBadgeText('!');
} else {
- chrome.browserAction.setBadgeText({text: ''});
+ this.setExtensionBadgeText('');
}
if (options.anki.enable) {
@@ -125,6 +127,18 @@ class Backend {
return true;
}
+
+ setExtensionBadgeBackgroundColor(color) {
+ if (typeof chrome.browserAction.setBadgeBackgroundColor === 'function') {
+ chrome.browserAction.setBadgeBackgroundColor({color});
+ }
+ }
+
+ setExtensionBadgeText(text) {
+ if (typeof chrome.browserAction.setBadgeText === 'function') {
+ chrome.browserAction.setBadgeText({text});
+ }
+ }
}
window.yomichan_backend = new Backend();