Add isExtensionUrl utility function to yomichan object
This commit is contained in:
parent
82f8397000
commit
3c48290cd8
@ -539,19 +539,10 @@ class Popup {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static _isOnExtensionPage() {
|
|
||||||
try {
|
|
||||||
const url = chrome.runtime.getURL('/');
|
|
||||||
return window.location.href.substring(0, url.length) === url;
|
|
||||||
} catch (e) {
|
|
||||||
// NOP
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async _injectStylesheet(id, type, value, useWebExtensionApi) {
|
static async _injectStylesheet(id, type, value, useWebExtensionApi) {
|
||||||
const injectedStylesheets = Popup._injectedStylesheets;
|
const injectedStylesheets = Popup._injectedStylesheets;
|
||||||
|
|
||||||
if (Popup._isOnExtensionPage()) {
|
if (yomichan.isExtensionUrl(window.location.href)) {
|
||||||
// Permissions error will occur if trying to use the WebExtension API to inject
|
// Permissions error will occur if trying to use the WebExtension API to inject
|
||||||
// into an extension page.
|
// into an extension page.
|
||||||
useWebExtensionApi = false;
|
useWebExtensionApi = false;
|
||||||
|
@ -316,6 +316,15 @@ const yomichan = (() => {
|
|||||||
this.trigger('orphaned', {error});
|
this.trigger('orphaned', {error});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isExtensionUrl(url) {
|
||||||
|
try {
|
||||||
|
const urlBase = chrome.runtime.getURL('/');
|
||||||
|
return url.substring(0, urlBase.length) === urlBase;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getTemporaryListenerResult(eventHandler, userCallback, timeout=null) {
|
getTemporaryListenerResult(eventHandler, userCallback, timeout=null) {
|
||||||
if (!(
|
if (!(
|
||||||
typeof eventHandler.addListener === 'function' &&
|
typeof eventHandler.addListener === 'function' &&
|
||||||
|
Loading…
Reference in New Issue
Block a user