summaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r--ext/fg/js/popup.js32
1 files changed, 19 insertions, 13 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 4f2de4f2..35e66044 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -83,6 +83,7 @@ class Popup {
this._frame.addEventListener('mousedown', (e) => e.stopPropagation());
this._frame.addEventListener('scroll', (e) => e.stopPropagation());
this._frame.addEventListener('load', this._onFrameLoad.bind(this));
+ yomichan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this));
}
isProxy() {
@@ -149,8 +150,12 @@ class Popup {
this._invokeApi('setCustomCss', {css});
}
- clearAutoPlayTimer() {
- this._invokeApi('clearAutoPlayTimer');
+ async clearAutoPlayTimer() {
+ try {
+ await this._invokeApi('clearAutoPlayTimer');
+ } catch (e) {
+ // NOP
+ }
}
setContentScale(scale) {
@@ -447,6 +452,18 @@ class Popup {
return await api.crossFrame.invoke(this._frameClient.frameId, 'popupMessage', message);
}
+ _invokeWindowApi(action, params={}) {
+ const contentWindow = this._frame.contentWindow;
+ if (this._frameClient === null || !this._frameClient.isConnected() || contentWindow === null) { return; }
+
+ const message = this._frameClient.createMessage({action, params});
+ contentWindow.postMessage(message, this._targetOrigin);
+ }
+
+ _onExtensionUnloaded() {
+ this._invokeWindowApi('extensionUnloaded');
+ }
+
_getFrameParentElement() {
const defaultParent = document.body;
const fullscreenElement = DOM.getFullscreenElement();
@@ -636,15 +653,4 @@ class Popup {
bottom: window.innerHeight
};
}
-
- static isFrameAboutBlank(frame) {
- try {
- const contentDocument = frame.contentDocument;
- if (contentDocument === null) { return false; }
- const url = contentDocument.location.href;
- return /^about:blank(?:[#?]|$)/.test(url);
- } catch (e) {
- return false;
- }
- }
}