diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/guide.html | 2 | ||||
-rw-r--r-- | ext/bg/settings.html | 14 | ||||
-rw-r--r-- | ext/fg/js/frontend-api-sender.js | 14 | ||||
-rw-r--r-- | ext/fg/js/popup-proxy-host.js | 6 | ||||
-rw-r--r-- | ext/fg/js/popup.js | 7 |
5 files changed, 30 insertions, 13 deletions
diff --git a/ext/bg/guide.html b/ext/bg/guide.html index 6f98d264..7ec1d8d9 100644 --- a/ext/bg/guide.html +++ b/ext/bg/guide.html @@ -15,7 +15,7 @@ <p> Read the steps below to get up and running with Yomichan. For complete documentation, - visit the <a href="https://foosoft.net/projects/yomichan/" target="_blank">official homepage</a>. + visit the <a href="https://foosoft.net/projects/yomichan/" target="_blank" rel="noopener">official homepage</a>. </p> <ol> diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 577e1a1f..7df47980 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -307,7 +307,7 @@ <div id="dict-importer"> <p class="help-block"> Select a dictionary to import for use below. Please visit the Yomichan homepage to - <a href="https://foosoft.net/projects/yomichan" target="_blank">download free dictionaries</a> + <a href="https://foosoft.net/projects/yomichan" target="_blank" rel="noopener">download free dictionaries</a> for use with this extension and to learn about importing proprietary EPWING dictionaries. </p> <input type="file" id="dict-file"> @@ -333,7 +333,7 @@ <div data-show-for-browser="firefox firefox-mobile"><div class="alert alert-danger options-advanced"> On Firefox and Firefox for Android, the storage information feature may be hidden behind a browser flag. - If you would like to enable this flag, open <a href="about:config" target="_blank">about:config</a> and search for the + If you would like to enable this flag, open <a href="about:config" target="_blank" rel="noopener">about:config</a> and search for the <strong>dom.storageManager.enabled</strong> option. If this option has a value of <strong>false</strong>, toggling it to <strong>true</strong> may allow storage information to be calculated. </div></div> @@ -355,9 +355,9 @@ </div> <p class="help-block"> - Yomichan supports automatic flashcard creation for <a href="http://ankisrs.net/" target="_blank">Anki</a>, a free application + Yomichan supports automatic flashcard creation for <a href="https://apps.ankiweb.net/" target="_blank" rel="noopener">Anki</a>, a free application designed to help you remember. This feature requires installation of the - <a href="https://foosoft.net/projects/anki-connect/" target="_blank">AnkiConnect</a> plugin. + <a href="https://foosoft.net/projects/anki-connect/" target="_blank" rel="noopener">AnkiConnect</a> plugin. </p> <div class="alert alert-danger" id="anki-error"></div> @@ -450,7 +450,7 @@ <div class="options-advanced"> <p class="help-block"> - Fields are formatted using the <a href="http://handlebarsjs.com/">Handlebars.js</a> template rendering + Fields are formatted using the <a href="https://handlebarsjs.com/" target="_blank" rel="noopener">Handlebars.js</a> template rendering engine. Advanced users can modify these templates for ultimate control of what information gets included in their Anki cards. If you encounter problems with your changes you can always <a href="#" id="field-templates-reset">reset to default</a> template settings. @@ -473,14 +473,14 @@ countless hours that I have devoted to this extension. </p> <p> - <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4DBTN9A3CUAFN" target="_blank"><img src="/bg/img/paypal.gif" alt></a> + <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4DBTN9A3CUAFN" target="_blank" rel="noopener"><img src="/bg/img/paypal.gif" alt></a> </p> </div> <pre id="debug"></pre> <div class="pull-right bottom-links"> - <small><a href="search.html">Search</a> • <a href="https://foosoft.net/projects/yomichan/" target="_blank">Homepage</a> • <a href="legal.html">Legal</a></small> + <small><a href="search.html">Search</a> • <a href="https://foosoft.net/projects/yomichan/" target="_blank" rel="noopener">Homepage</a> • <a href="legal.html">Legal</a></small> </div> </div> diff --git a/ext/fg/js/frontend-api-sender.js b/ext/fg/js/frontend-api-sender.js index a1cb02c4..2e037e62 100644 --- a/ext/fg/js/frontend-api-sender.js +++ b/ext/fg/js/frontend-api-sender.js @@ -26,9 +26,7 @@ class FrontendApiSender { this.disconnected = false; this.nextId = 0; - this.port = chrome.runtime.connect(null, {name: 'backend-api-forwarder'}); - this.port.onDisconnect.addListener(this.onDisconnect.bind(this)); - this.port.onMessage.addListener(this.onMessage.bind(this)); + this.port = null; } invoke(action, params, target) { @@ -36,6 +34,10 @@ class FrontendApiSender { return Promise.reject('Disconnected'); } + if (this.port === null) { + this.createPort(); + } + const id = `${this.nextId}`; ++this.nextId; @@ -48,6 +50,12 @@ class FrontendApiSender { }); } + createPort() { + this.port = chrome.runtime.connect(null, {name: 'backend-api-forwarder'}); + this.port.onDisconnect.addListener(this.onDisconnect.bind(this)); + this.port.onMessage.addListener(this.onMessage.bind(this)); + } + onMessage({type, id, data, senderId}) { if (senderId !== this.senderId) { return; } switch (type) { diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index 47f49b8d..396f7556 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -116,12 +116,14 @@ class PopupProxyHost { async termsShow(id, elementRect, writingMode, definitions, options, context) { const popup = this.getPopup(id); elementRect = this.jsonRectToDOMRect(popup, elementRect); + if (!PopupProxyHost.popupCanShow(popup)) { return false; } return await popup.termsShow(elementRect, writingMode, definitions, options, context); } async kanjiShow(id, elementRect, writingMode, definitions, options, context) { const popup = this.getPopup(id); elementRect = this.jsonRectToDOMRect(popup, elementRect); + if (!PopupProxyHost.popupCanShow(popup)) { return false; } return await popup.kanjiShow(elementRect, writingMode, definitions, options, context); } @@ -129,6 +131,10 @@ class PopupProxyHost { const popup = this.getPopup(id); return popup.clearAutoPlayTimer(); } + + static popupCanShow(popup) { + return popup.parent === null || popup.parent.isVisible(); + } } PopupProxyHost.instance = PopupProxyHost.create(); diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 1d6fa5b3..8953cf30 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -239,9 +239,12 @@ class Popup { } focusParent() { - if (this.parent && this.parent.container) { + if (this.parent !== null) { // Chrome doesn't like focusing iframe without contentWindow. - this.parent.container.contentWindow.focus(); + const contentWindow = this.parent.container.contentWindow; + if (contentWindow !== null) { + contentWindow.focus(); + } } else { // Firefox doesn't like focusing window without first blurring the iframe. // this.container.contentWindow.blur() doesn't work on Firefox for some reason. |