Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Refactor isExtensionUrl #2015

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions ext/js/yomichan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down