From 8fb398aad8752f3307452f1a1d3459bace77a97c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 15 Mar 2017 20:13:58 -0700 Subject: inject yomichan frame on demand, fixes #34 --- ext/fg/js/popup.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 2b2bf5d3..7da75446 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -26,10 +26,19 @@ class Popup { this.container.setAttribute('src', chrome.extension.getURL('/fg/frame.html')); this.container.style.width='0px'; this.container.style.height='0px'; - document.body.appendChild(this.container); + this.injected = false; + } + + inject() { + if (!this.injected) { + document.body.appendChild(this.container); + this.injected = true; + } } showAt(rect) { + this.inject(); + this.container.style.left = `${rect.x}px`; this.container.style.top = `${rect.y}px`; this.container.style.height = `${rect.height}px`; @@ -38,6 +47,8 @@ class Popup { } showNextTo(elementRect, options) { + this.inject(); + const containerStyle = window.getComputedStyle(this.container); const containerHeight = parseInt(containerStyle.height); const containerWidth = parseInt(containerStyle.width); @@ -83,7 +94,7 @@ class Popup { } isVisible() { - return this.container.style.visibility !== 'hidden'; + return this.injected && this.container.style.visibility !== 'hidden'; } showTermDefs(definitions, options, context) { -- cgit v1.2.3