Refactor isExtensionUrl (#2015)
* Update isExtensionUrl to work even if the extension is unloaded * Simplify
This commit is contained in:
parent
70ac6c51f9
commit
3c798ae36d
@ -49,12 +49,17 @@ class Yomichan extends EventDispatcher {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._extensionName = 'Yomichan';
|
|
||||||
try {
|
try {
|
||||||
const manifest = chrome.runtime.getManifest();
|
const manifest = chrome.runtime.getManifest();
|
||||||
this._extensionName = `${manifest.name} v${manifest.version}`;
|
this._extensionName = `${manifest.name} v${manifest.version}`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// NOP
|
this._extensionName = 'Yomichan';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this._extensionUrlBase = chrome.runtime.getURL('/');
|
||||||
|
} catch (e) {
|
||||||
|
this._extensionUrlBase = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._isBackground = null;
|
this._isBackground = null;
|
||||||
@ -148,11 +153,7 @@ class Yomichan extends EventDispatcher {
|
|||||||
* @returns true if the URL is an extension URL, false otherwise.
|
* @returns true if the URL is an extension URL, false otherwise.
|
||||||
*/
|
*/
|
||||||
isExtensionUrl(url) {
|
isExtensionUrl(url) {
|
||||||
try {
|
return this._extensionUrlBase !== null && url.startsWith(this._extensionUrlBase);
|
||||||
return url.startsWith(chrome.runtime.getURL('/'));
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user