aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-02-19 22:49:25 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-05-04 13:02:56 -0400
commit769dc205fb56fa8f9442f68907eb9598caea52bd (patch)
treee710f06e91d913cd5531bfd0807a8326a7e88363 /ext/bg/js/backend.js
parentd49cbf12eae40e1a898c619ed092af560aa91bc6 (diff)
Make extension badge and onCommand optional
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();