Frontend updates

This commit is contained in:
toasted-nutbread 2019-10-11 22:35:59 -04:00
parent a6903d68a4
commit cc72514ce6
7 changed files with 47 additions and 10 deletions

View File

@ -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');

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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');

View File

@ -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();
});

View File

@ -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