diff options
| author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-11 22:35:59 -0400 | 
|---|---|---|
| committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-11 23:24:51 -0400 | 
| commit | cc72514ce6260bc489b8dd9b51ea27b9fb6e3ce8 (patch) | |
| tree | 2c233ad490183780f9812994f5b1345dd1adff98 /ext | |
| parent | a6903d68a409544f0f26f4cefb2ad6c40f9994c9 (diff) | |
Frontend updates
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/bg/js/search-frontend.js | 3 | ||||
| -rw-r--r-- | ext/fg/js/float.js | 9 | ||||
| -rw-r--r-- | ext/fg/js/frontend-initialize.js | 20 | ||||
| -rw-r--r-- | ext/fg/js/frontend.js | 15 | ||||
| -rw-r--r-- | ext/fg/js/popup-nested.js | 3 | ||||
| -rw-r--r-- | ext/fg/js/popup.js | 4 | ||||
| -rw-r--r-- | ext/manifest.json | 3 | 
7 files changed, 47 insertions, 10 deletions
| diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js index 0c1a61ea..f55f06e6 100644 --- a/ext/bg/js/search-frontend.js +++ b/ext/bg/js/search-frontend.js @@ -29,7 +29,8 @@ async function searchFrontendSetup() {          '/fg/js/frontend-api-receiver.js',          '/fg/js/popup.js',          '/fg/js/popup-proxy-host.js', -        '/fg/js/frontend.js' +        '/fg/js/frontend.js', +        '/fg/js/frontend-initialize.js'      ];      for (const src of scriptSrcs) {          const script = document.createElement('script'); diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 8fdb6925..533d98e1 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -96,7 +96,7 @@ class DisplayFloat extends Display {          }      } -    initialize(options, popupInfo, url) { +    initialize(options, popupInfo, url, childrenSupported) {          const css = options.general.customPopupCss;          if (css) {              this.setStyle(css); @@ -105,7 +105,10 @@ class DisplayFloat extends Display {          const {id, depth, parentFrameId} = popupInfo;          this.optionsContext.depth = depth;          this.optionsContext.url = url; -        popupNestedInitialize(id, depth, parentFrameId, url); + +        if (childrenSupported) { +            popupNestedInitialize(id, depth, parentFrameId, url); +        }      }      setStyle(css) { @@ -138,7 +141,7 @@ DisplayFloat.messageHandlers = {      kanjiShow: (self, {definitions, options, context}) => self.kanjiShow(definitions, options, context),      clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),      orphaned: (self) => self.onOrphaned(), -    initialize: (self, {options, popupInfo, url}) => self.initialize(options, popupInfo, url) +    initialize: (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported)  };  window.yomichan_display = new DisplayFloat(); diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js new file mode 100644 index 00000000..37a82faa --- /dev/null +++ b/ext/fg/js/frontend-initialize.js @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2019  Alex Yatskov <alex@foosoft.net> + * Author: Alex Yatskov <alex@foosoft.net> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program.  If not, see <http://www.gnu.org/licenses/>. + */ + + +window.yomichan_frontend = Frontend.create(); diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 88cb93a9..1c41cad1 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -41,6 +41,9 @@ class Frontend {          this.enabled = false;          this.eventListeners = []; + +        this.isPreparedPromiseResolve = null; +        this.isPreparedPromise = new Promise((resolve) => { this.isPreparedPromiseResolve = resolve; });      }      static create() { @@ -59,11 +62,16 @@ class Frontend {              await this.updateOptions();              chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this)); +            this.isPreparedPromiseResolve();          } catch (e) {              this.onError(e);          }      } +    isPrepared() { +        return this.isPreparedPromise; +    } +      onMouseOver(e) {          if (e.target === this.popup.container && this.popupTimer !== null) {              this.popupTimerClear(); @@ -303,6 +311,10 @@ class Frontend {          }          const textSource = docRangeFromPoint(x, y, this.options); +        return await this.searchSource(textSource, cause); +    } + +    async searchSource(textSource, cause) {          let hideResults = textSource === null;          let searched = false;          let success = false; @@ -560,6 +572,3 @@ Frontend.runtimeMessageHandlers = {          self.popup.setVisibleOverride(visible);      }  }; - - -window.yomichan_frontend = Frontend.create(); diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js index b36de2ec..f7309466 100644 --- a/ext/fg/js/popup-nested.js +++ b/ext/fg/js/popup-nested.js @@ -41,7 +41,8 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) {          '/fg/js/frontend-api-sender.js',          '/fg/js/popup.js',          '/fg/js/popup-proxy.js', -        '/fg/js/frontend.js' +        '/fg/js/frontend.js', +        '/fg/js/frontend-initialize.js'      ];      for (const src of scriptSrcs) {          const script = document.createElement('script'); diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 9ca91afa..7f96fe97 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -25,6 +25,7 @@ class Popup {          this.frameId = null;          this.parent = null;          this.child = null; +        this.childrenSupported = true;          this.container = document.createElement('iframe');          this.container.id = 'yomichan-float';          this.container.addEventListener('mousedown', e => e.stopPropagation()); @@ -70,7 +71,8 @@ class Popup {                          depth: this.depth,                          parentFrameId                      }, -                    url: this.url +                    url: this.url, +                    childrenSupported: this.childrenSupported                  });                  resolve();              }); diff --git a/ext/manifest.json b/ext/manifest.json index 927861bd..25b86023 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -26,7 +26,8 @@              "fg/js/source.js",              "fg/js/util.js",              "fg/js/popup-proxy-host.js", -            "fg/js/frontend.js" +            "fg/js/frontend.js", +            "fg/js/frontend-initialize.js"          ],          "css": ["fg/css/client.css"],          "all_frames": true |