aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/float.js22
-rw-r--r--ext/fg/js/popup.js13
2 files changed, 32 insertions, 3 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 1f08702d..1deb61a9 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -21,6 +21,7 @@ class DisplayFloat extends Display {
constructor() {
super($('#spinner'), $('#definitions'));
this.autoPlayAudioTimer = null;
+ this.styleNode = null;
$(window).on('message', utilAsync(this.onMessage.bind(this)));
}
@@ -62,6 +63,13 @@ class DisplayFloat extends Display {
orphaned: () => {
this.onOrphaned();
+ },
+
+ setOptions: (options) => {
+ const css = options.general.customPopupCss;
+ if (css) {
+ this.setStyle(css);
+ }
}
};
@@ -101,6 +109,20 @@ class DisplayFloat extends Display {
this.autoPlayAudioTimer = null;
}
}
+
+ setStyle(css) {
+ const parent = document.head;
+
+ if (this.styleNode === null) {
+ this.styleNode = document.createElement('style');
+ }
+
+ this.styleNode.textContent = css;
+
+ if (this.styleNode.parentNode !== parent) {
+ parent.appendChild(this.styleNode);
+ }
+ }
}
window.yomichan_display = new DisplayFloat();
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index ad81cf03..f5ccaf8b 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -29,10 +29,17 @@ class Popup {
this.injected = null;
}
- inject() {
+ inject(options) {
if (!this.injected) {
this.injected = new Promise((resolve, reject) => {
- this.container.addEventListener('load', resolve);
+ this.container.addEventListener('load', () => {
+ this.invokeApi('setOptions', {
+ general: {
+ customPopupCss: options.general.customPopupCss
+ }
+ });
+ resolve();
+ });
this.observeFullscreen();
this.onFullscreenChanged();
});
@@ -42,7 +49,7 @@ class Popup {
}
async show(elementRect, options) {
- await this.inject();
+ await this.inject(options);
const containerStyle = window.getComputedStyle(this.container);
const containerHeight = parseInt(containerStyle.height);