summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-11-21 12:27:29 -0500
committerGitHub <noreply@github.com>2021-11-21 12:27:29 -0500
commit3c798ae36d1181a57de59f03bcf10d3bf7fc9577 (patch)
treebd185bcad6d3376f7f62a7bc008dfe35020a2f7d /ext
parent70ac6c51f99ba055ebced0dc3ab2be1b00d95992 (diff)
Refactor isExtensionUrl (#2015)
* Update isExtensionUrl to work even if the extension is unloaded * Simplify
Diffstat (limited to 'ext')
-rw-r--r--ext/js/yomichan.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/ext/js/yomichan.js b/ext/js/yomichan.js
index c65e2f7d..33e84df1 100644
--- a/ext/js/yomichan.js
+++ b/ext/js/yomichan.js
@@ -49,12 +49,17 @@ class Yomichan extends EventDispatcher {
constructor() {
super();
- this._extensionName = 'Yomichan';
try {
const manifest = chrome.runtime.getManifest();
this._extensionName = `${manifest.name} v${manifest.version}`;
} catch (e) {
- // NOP
+ this._extensionName = 'Yomichan';
+ }
+
+ try {
+ this._extensionUrlBase = chrome.runtime.getURL('/');
+ } catch (e) {
+ this._extensionUrlBase = null;
}
this._isBackground = null;
@@ -148,11 +153,7 @@ class Yomichan extends EventDispatcher {
* @returns true if the URL is an extension URL, false otherwise.
*/
isExtensionUrl(url) {
- try {
- return url.startsWith(chrome.runtime.getURL('/'));
- } catch (e) {
- return false;
- }
+ return this._extensionUrlBase !== null && url.startsWith(this._extensionUrlBase);
}
/**