summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/bg/js/search-frontend.js2
-rw-r--r--ext/bg/js/search.js2
-rw-r--r--ext/bg/js/settings-popup-preview.js3
-rw-r--r--ext/bg/lang/deinflect.json6
-rw-r--r--ext/fg/js/document.js10
-rw-r--r--ext/fg/js/float.js19
-rw-r--r--ext/fg/js/frontend.js34
-rw-r--r--ext/fg/js/popup-nested.js2
-rw-r--r--ext/fg/js/popup-proxy-host.js37
-rw-r--r--ext/fg/js/popup-proxy.js21
-rw-r--r--ext/fg/js/popup.js29
-rw-r--r--ext/fg/js/source.js2
-rw-r--r--ext/mixed/js/display.js38
13 files changed, 104 insertions, 101 deletions
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js
index f55f06e6..b21dac17 100644
--- a/ext/bg/js/search-frontend.js
+++ b/ext/bg/js/search-frontend.js
@@ -25,6 +25,8 @@ async function searchFrontendSetup() {
const options = await apiOptionsGet(optionsContext);
if (!options.scanning.enableOnSearchPage) { return; }
+ window.frontendInitializationData = {depth: 1, proxy: false};
+
const scriptSrcs = [
'/fg/js/frontend-api-receiver.js',
'/fg/js/popup.js',
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 68afe47e..a5a815cf 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -101,7 +101,7 @@ class DisplaySearch extends Display {
this.updateSearchButton();
if (valid) {
const {definitions} = await apiTermsFind(query, this.optionsContext);
- this.termsShow(definitions, {
+ this.setContentTerms(definitions, {
focus: false,
sentence: null,
url: window.location.href
diff --git a/ext/bg/js/settings-popup-preview.js b/ext/bg/js/settings-popup-preview.js
index 7ccdc7f3..b12fb726 100644
--- a/ext/bg/js/settings-popup-preview.js
+++ b/ext/bg/js/settings-popup-preview.js
@@ -100,8 +100,7 @@ class SettingsPopupPreview {
const elementRect = textSource.getRect();
const writingMode = textSource.getWritingMode();
- const options = this.frontend.options;
- this.frontend.popup.show(elementRect, writingMode, options);
+ this.frontend.popup.showContent(elementRect, writingMode);
}
onMessage(e) {
diff --git a/ext/bg/lang/deinflect.json b/ext/bg/lang/deinflect.json
index 682093e1..a0b6baa1 100644
--- a/ext/bg/lang/deinflect.json
+++ b/ext/bg/lang/deinflect.json
@@ -3671,7 +3671,7 @@
"kanaIn": "ておる",
"kanaOut": "て",
"rulesIn": [
- "v1"
+ "v5"
],
"rulesOut": [
"iru"
@@ -3701,7 +3701,7 @@
"kanaIn": "でおる",
"kanaOut": "で",
"rulesIn": [
- "v1"
+ "v5"
],
"rulesOut": [
"iru"
@@ -3711,7 +3711,7 @@
"kanaIn": "とる",
"kanaOut": "て",
"rulesIn": [
- "v1"
+ "v5"
],
"rulesOut": [
"iru"
diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js
index 94a68e6c..a168705e 100644
--- a/ext/fg/js/document.js
+++ b/ext/fg/js/document.js
@@ -27,8 +27,8 @@ function docImposterCreate(element, isTextarea) {
const elementStyle = window.getComputedStyle(element);
const elementRect = element.getBoundingClientRect();
const documentRect = document.documentElement.getBoundingClientRect();
- const left = elementRect.left - documentRect.left;
- const top = elementRect.top - documentRect.top;
+ let left = elementRect.left - documentRect.left;
+ let top = elementRect.top - documentRect.top;
// Container
const container = document.createElement('div');
@@ -82,6 +82,12 @@ function docImposterCreate(element, isTextarea) {
docSetImposterStyle(imposterStyle, 'width', `${width}px`);
docSetImposterStyle(imposterStyle, 'height', `${height}px`);
}
+ if (imposterRect.x !== elementRect.x || imposterRect.y !== elementRect.y) {
+ left += (elementRect.left - imposterRect.left);
+ top += (elementRect.top - imposterRect.top);
+ docSetImposterStyle(imposterStyle, 'left', `${left}px`);
+ docSetImposterStyle(imposterStyle, 'top', `${top}px`);
+ }
imposter.scrollTop = element.scrollTop;
imposter.scrollLeft = element.scrollLeft;
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 4b3cd848..089c9422 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -32,25 +32,12 @@ class DisplayFloat extends Display {
onError(error) {
if (window.yomichan_orphaned) {
- this.onOrphaned();
+ this.setContentOrphaned();
} else {
logError(error, true);
}
}
- onOrphaned() {
- const definitions = document.querySelector('#definitions');
- const errorOrphaned = document.querySelector('#error-orphaned');
-
- if (definitions !== null) {
- definitions.style.setProperty('display', 'none', 'important');
- }
-
- if (errorOrphaned !== null) {
- errorOrphaned.style.setProperty('display', 'block', 'important');
- }
- }
-
onSearchClear() {
window.parent.postMessage('popupClose', '*');
}
@@ -121,10 +108,8 @@ DisplayFloat.onKeyDownHandlers = {
};
DisplayFloat.messageHandlers = {
- termsShow: (self, {definitions, context}) => self.termsShow(definitions, context),
- kanjiShow: (self, {definitions, context}) => self.kanjiShow(definitions, context),
+ setContent: (self, {type, details}) => self.setContent(type, details),
clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),
- orphaned: (self) => self.onOrphaned(),
setCustomCss: (self, {css}) => self.setCustomCss(css),
initialize: (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported)
};
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 3ddeae78..45d24329 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -49,11 +49,10 @@ class Frontend {
}
static create() {
- const initializationData = window.frontendInitializationData;
- const isNested = (initializationData !== null && typeof initializationData === 'object');
- const {id, depth, parentFrameId, ignoreNodes, url} = isNested ? initializationData : {};
+ const data = window.frontendInitializationData || {};
+ const {id, depth=0, parentFrameId, ignoreNodes, url, proxy=false} = data;
- const popup = isNested ? new PopupProxy(depth + 1, id, parentFrameId, url) : PopupProxyHost.instance.createPopup(null);
+ const popup = proxy ? new PopupProxy(depth + 1, id, parentFrameId, url) : PopupProxyHost.instance.createPopup(null, depth);
const frontend = new Frontend(popup, ignoreNodes);
frontend.prepare();
return frontend;
@@ -140,8 +139,14 @@ class Frontend {
}
}
- onResize() {
- this.searchClear(false);
+ async onResize() {
+ if (this.textSourceLast !== null && await this.popup.isVisibleAsync()) {
+ const textSource = this.textSourceLast;
+ this.lastShowPromise = this.popup.showContent(
+ textSource.getRect(),
+ textSource.getWritingMode()
+ );
+ }
}
onClick(e) {
@@ -333,9 +338,10 @@ class Frontend {
} catch (e) {
if (window.yomichan_orphaned) {
if (textSource && this.options.scanning.modifier !== 'none') {
- this.lastShowPromise = this.popup.showOrphaned(
+ this.lastShowPromise = this.popup.showContent(
textSource.getRect(),
- textSource.getWritingMode()
+ textSource.getWritingMode(),
+ 'orphaned'
);
}
} else {
@@ -371,11 +377,11 @@ class Frontend {
const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
const url = window.location.href;
- this.lastShowPromise = this.popup.termsShow(
+ this.lastShowPromise = this.popup.showContent(
textSource.getRect(),
textSource.getWritingMode(),
- definitions,
- {sentence, url, focus}
+ 'terms',
+ {definitions, context: {sentence, url, focus}}
);
this.textSourceLast = textSource;
@@ -401,11 +407,11 @@ class Frontend {
const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
const url = window.location.href;
- this.lastShowPromise = this.popup.kanjiShow(
+ this.lastShowPromise = this.popup.showContent(
textSource.getRect(),
textSource.getWritingMode(),
- definitions,
- {sentence, url, focus}
+ 'kanji',
+ {definitions, context: {sentence, url, focus}}
);
this.textSourceLast = textSource;
diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js
index f7309466..cec95aea 100644
--- a/ext/fg/js/popup-nested.js
+++ b/ext/fg/js/popup-nested.js
@@ -35,7 +35,7 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) {
const ignoreNodes = options.scanning.enableOnPopupExpressions ? [] : [ '.expression', '.expression *' ];
- window.frontendInitializationData = {id, depth, parentFrameId, ignoreNodes, url};
+ window.frontendInitializationData = {id, depth, parentFrameId, ignoreNodes, url, proxy: true};
const scriptSrcs = [
'/fg/js/frontend-api-sender.js',
diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js
index bb323f64..d8dec4df 100644
--- a/ext/fg/js/popup-proxy-host.js
+++ b/ext/fg/js/popup-proxy-host.js
@@ -39,21 +39,22 @@ class PopupProxyHost {
this.apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${frameId}`, {
createNestedPopup: ({parentId}) => this.createNestedPopup(parentId),
setOptions: ({id, options}) => this.setOptions(id, options),
- showOrphaned: ({id, elementRect}) => this.showOrphaned(id, elementRect),
hide: ({id, changeFocus}) => this.hide(id, changeFocus),
+ isVisibleAsync: ({id}) => this.isVisibleAsync(id),
setVisibleOverride: ({id, visible}) => this.setVisibleOverride(id, visible),
containsPoint: ({id, x, y}) => this.containsPoint(id, x, y),
- termsShow: ({id, elementRect, writingMode, definitions, context}) => this.termsShow(id, elementRect, writingMode, definitions, context),
- kanjiShow: ({id, elementRect, writingMode, definitions, context}) => this.kanjiShow(id, elementRect, writingMode, definitions, context),
+ showContent: ({id, elementRect, writingMode, type, details}) => this.showContent(id, elementRect, writingMode, type, details),
setCustomCss: ({id, css}) => this.setCustomCss(id, css),
clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id)
});
}
- createPopup(parentId) {
+ createPopup(parentId, depth) {
const parent = (typeof parentId === 'string' && this.popups.hasOwnProperty(parentId) ? this.popups[parentId] : null);
- const depth = (parent !== null ? parent.depth + 1 : 0);
const id = `${this.nextId}`;
+ if (parent !== null) {
+ depth = parent.depth + 1;
+ }
++this.nextId;
const popup = new Popup(id, depth, this.frameIdPromise);
if (parent !== null) {
@@ -65,7 +66,7 @@ class PopupProxyHost {
}
async createNestedPopup(parentId) {
- return this.createPopup(parentId).id;
+ return this.createPopup(parentId, 0).id;
}
getPopup(id) {
@@ -92,20 +93,19 @@ class PopupProxyHost {
return await popup.setOptions(options);
}
- async showOrphaned(id, elementRect) {
+ async hide(id, changeFocus) {
const popup = this.getPopup(id);
- elementRect = this.jsonRectToDOMRect(popup, elementRect);
- return await popup.showOrphaned(elementRect);
+ return popup.hide(changeFocus);
}
- async hide(id, changeFocus) {
+ async isVisibleAsync(id) {
const popup = this.getPopup(id);
- return popup.hide(changeFocus);
+ return await popup.isVisibleAsync();
}
async setVisibleOverride(id, visible) {
const popup = this.getPopup(id);
- return popup.setVisibleOverride(visible);
+ return await popup.setVisibleOverride(visible);
}
async containsPoint(id, x, y) {
@@ -113,18 +113,11 @@ class PopupProxyHost {
return await popup.containsPoint(x, y);
}
- async termsShow(id, elementRect, writingMode, definitions, context) {
- const popup = this.getPopup(id);
- elementRect = this.jsonRectToDOMRect(popup, elementRect);
- if (!PopupProxyHost.popupCanShow(popup)) { return false; }
- return await popup.termsShow(elementRect, writingMode, definitions, context);
- }
-
- async kanjiShow(id, elementRect, writingMode, definitions, context) {
+ async showContent(id, elementRect, writingMode, type, details) {
const popup = this.getPopup(id);
elementRect = this.jsonRectToDOMRect(popup, elementRect);
- if (!PopupProxyHost.popupCanShow(popup)) { return false; }
- return await popup.kanjiShow(elementRect, writingMode, definitions, context);
+ if (!PopupProxyHost.popupCanShow(popup)) { return Promise.resolve(false); }
+ return await popup.showContent(elementRect, writingMode, type, details);
}
async setCustomCss(id, css) {
diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js
index 6ea94b6a..e62a4868 100644
--- a/ext/fg/js/popup-proxy.js
+++ b/ext/fg/js/popup-proxy.js
@@ -51,12 +51,6 @@ class PopupProxy {
return await this.invokeHostApi('setOptions', {id, options});
}
- async showOrphaned(elementRect) {
- const id = await this.getPopupId();
- elementRect = PopupProxy.DOMRectToJson(elementRect);
- return await this.invokeHostApi('showOrphaned', {id, elementRect});
- }
-
async hide(changeFocus) {
if (this.id === null) {
return;
@@ -64,6 +58,11 @@ class PopupProxy {
return await this.invokeHostApi('hide', {id: this.id, changeFocus});
}
+ async isVisibleAsync() {
+ const id = await this.getPopupId();
+ return await this.invokeHostApi('isVisibleAsync', {id});
+ }
+
async setVisibleOverride(visible) {
const id = await this.getPopupId();
return await this.invokeHostApi('setVisibleOverride', {id, visible});
@@ -76,16 +75,10 @@ class PopupProxy {
return await this.invokeHostApi('containsPoint', {id: this.id, x, y});
}
- async termsShow(elementRect, writingMode, definitions, context) {
- const id = await this.getPopupId();
- elementRect = PopupProxy.DOMRectToJson(elementRect);
- return await this.invokeHostApi('termsShow', {id, elementRect, writingMode, definitions, context});
- }
-
- async kanjiShow(elementRect, writingMode, definitions, context) {
+ async showContent(elementRect, writingMode, type=null, details=null) {
const id = await this.getPopupId();
elementRect = PopupProxy.DOMRectToJson(elementRect);
- return await this.invokeHostApi('kanjiShow', {id, elementRect, writingMode, definitions, context});
+ return await this.invokeHostApi('showContent', {id, elementRect, writingMode, type, details});
}
async setCustomCss(css) {
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 2a9670fc..b5eb9fe2 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -90,6 +90,13 @@ class Popup {
this.updateTheme();
}
+ async showContent(elementRect, writingMode, type=null, details=null) {
+ if (!this.isInitialized()) { return; }
+ await this.show(elementRect, writingMode);
+ if (type === null) { return; }
+ this.invokeApi('setContent', {type, details});
+ }
+
async show(elementRect, writingMode) {
await this.inject();
@@ -218,12 +225,6 @@ class Popup {
return [position, size, after];
}
- async showOrphaned(elementRect, writingMode) {
- if (!this.isInitialized()) { return; }
- await this.show(elementRect, writingMode);
- this.invokeApi('orphaned');
- }
-
hide(changeFocus) {
if (!this.isVisible()) {
return;
@@ -238,6 +239,10 @@ class Popup {
}
}
+ async isVisibleAsync() {
+ return this.isVisible();
+ }
+
isVisible() {
return this.isInjected && (this.visibleOverride !== null ? this.visibleOverride : this.visible);
}
@@ -320,18 +325,6 @@ class Popup {
return false;
}
- async termsShow(elementRect, writingMode, definitions, context) {
- if (!this.isInitialized()) { return; }
- await this.show(elementRect, writingMode);
- this.invokeApi('termsShow', {definitions, context});
- }
-
- async kanjiShow(elementRect, writingMode, definitions, context) {
- if (!this.isInitialized()) { return; }
- await this.show(elementRect, writingMode);
- this.invokeApi('kanjiShow', {definitions, context});
- }
-
async setCustomCss(css) {
this.invokeApi('setCustomCss', {css});
}
diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js
index a483952e..c3da9f46 100644
--- a/ext/fg/js/source.js
+++ b/ext/fg/js/source.js
@@ -233,7 +233,7 @@ class TextSourceRange {
const style = window.getComputedStyle(element);
const writingMode = style.writingMode;
if (typeof writingMode === 'string') {
- TextSourceRange.normalizeWritingMode(writingMode);
+ return TextSourceRange.normalizeWritingMode(writingMode);
}
}
return 'horizontal-tb';
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index e0994f8a..bab82015 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -74,8 +74,8 @@ class Display {
context.source.source = this.context.source;
}
- const kanjiDefs = await apiKanjiFind(link.textContent, this.getOptionsContext());
- this.kanjiShow(kanjiDefs, context);
+ const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext());
+ this.setContentKanji(definitions, context);
} catch (e) {
this.onError(e);
}
@@ -122,7 +122,7 @@ class Display {
context.source.source = this.context.source;
}
- this.termsShow(definitions, context);
+ this.setContentTerms(definitions, context);
} catch (e) {
this.onError(e);
}
@@ -263,7 +263,20 @@ class Display {
});
}
- async termsShow(definitions, context) {
+ setContent(type, details) {
+ switch (type) {
+ case 'terms':
+ return this.setContentTerms(details.definitions, details.context);
+ case 'kanji':
+ return this.setContentKanji(details.definitions, details.context);
+ case 'orphaned':
+ return this.setContentOrphaned();
+ default:
+ return Promise.resolve();
+ }
+ }
+
+ async setContentTerms(definitions, context) {
if (!this.isInitialized()) { return; }
try {
@@ -317,7 +330,7 @@ class Display {
}
}
- async kanjiShow(definitions, context) {
+ async setContentKanji(definitions, context) {
if (!this.isInitialized()) { return; }
try {
@@ -363,6 +376,19 @@ class Display {
}
}
+ async setContentOrphaned() {
+ const definitions = document.querySelector('#definitions');
+ const errorOrphaned = document.querySelector('#error-orphaned');
+
+ if (definitions !== null) {
+ definitions.style.setProperty('display', 'none', 'important');
+ }
+
+ if (errorOrphaned !== null) {
+ errorOrphaned.style.setProperty('display', 'block', 'important');
+ }
+ }
+
autoPlayAudio() {
this.audioPlay(this.definitions[0], this.firstExpressionIndex, 0);
}
@@ -441,7 +467,7 @@ class Display {
source: this.context.source.source
};
- this.termsShow(this.context.source.definitions, context);
+ this.setContentTerms(this.context.source.definitions, context);
}
}