Update how custom CSS is applied
This commit is contained in:
parent
c90bc75eb8
commit
883226b045
@ -118,6 +118,10 @@ class DisplaySearch extends Display {
|
|||||||
return this.optionsContext;
|
return this.optionsContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCustomCss() {
|
||||||
|
// No custom CSS
|
||||||
|
}
|
||||||
|
|
||||||
setIntroVisible(visible, animate) {
|
setIntroVisible(visible, animate) {
|
||||||
if (this.introVisible === visible) {
|
if (this.introVisible === visible) {
|
||||||
return;
|
return;
|
||||||
|
@ -21,7 +21,6 @@ class DisplayFloat extends Display {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super(document.querySelector('#spinner'), document.querySelector('#definitions'));
|
super(document.querySelector('#spinner'), document.querySelector('#definitions'));
|
||||||
this.autoPlayAudioTimer = null;
|
this.autoPlayAudioTimer = null;
|
||||||
this.styleNode = null;
|
|
||||||
|
|
||||||
this.optionsContext = {
|
this.optionsContext = {
|
||||||
depth: 0,
|
depth: 0,
|
||||||
@ -101,11 +100,6 @@ class DisplayFloat extends Display {
|
|||||||
async initialize(options, popupInfo, url, childrenSupported) {
|
async initialize(options, popupInfo, url, childrenSupported) {
|
||||||
await super.initialize(options);
|
await super.initialize(options);
|
||||||
|
|
||||||
const css = options.general.customPopupCss;
|
|
||||||
if (css) {
|
|
||||||
this.setStyle(css);
|
|
||||||
}
|
|
||||||
|
|
||||||
const {id, depth, parentFrameId} = popupInfo;
|
const {id, depth, parentFrameId} = popupInfo;
|
||||||
this.optionsContext.depth = depth;
|
this.optionsContext.depth = depth;
|
||||||
this.optionsContext.url = url;
|
this.optionsContext.url = url;
|
||||||
@ -114,20 +108,6 @@ class DisplayFloat extends Display {
|
|||||||
popupNestedInitialize(id, depth, parentFrameId, url);
|
popupNestedInitialize(id, depth, parentFrameId, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayFloat.onKeyDownHandlers = {
|
DisplayFloat.onKeyDownHandlers = {
|
||||||
@ -145,6 +125,7 @@ DisplayFloat.messageHandlers = {
|
|||||||
kanjiShow: (self, {definitions, context}) => self.kanjiShow(definitions, context),
|
kanjiShow: (self, {definitions, context}) => self.kanjiShow(definitions, context),
|
||||||
clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),
|
clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),
|
||||||
orphaned: (self) => self.onOrphaned(),
|
orphaned: (self) => self.onOrphaned(),
|
||||||
|
setCustomCss: (self, {css}) => self.setCustomCss(css),
|
||||||
initialize: (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported)
|
initialize: (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ class PopupProxyHost {
|
|||||||
containsPoint: ({id, x, y}) => this.containsPoint(id, x, y),
|
containsPoint: ({id, x, y}) => this.containsPoint(id, x, y),
|
||||||
termsShow: ({id, elementRect, writingMode, definitions, context}) => this.termsShow(id, elementRect, writingMode, definitions, context),
|
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),
|
kanjiShow: ({id, elementRect, writingMode, definitions, context}) => this.kanjiShow(id, elementRect, writingMode, definitions, context),
|
||||||
|
setCustomCss: ({id, css}) => this.setCustomCss(id, css),
|
||||||
clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id)
|
clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -126,6 +127,11 @@ class PopupProxyHost {
|
|||||||
return await popup.kanjiShow(elementRect, writingMode, definitions, context);
|
return await popup.kanjiShow(elementRect, writingMode, definitions, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setCustomCss(id, css) {
|
||||||
|
const popup = this.getPopup(id);
|
||||||
|
return popup.setCustomCss(css);
|
||||||
|
}
|
||||||
|
|
||||||
async clearAutoPlayTimer(id) {
|
async clearAutoPlayTimer(id) {
|
||||||
const popup = this.getPopup(id);
|
const popup = this.getPopup(id);
|
||||||
return popup.clearAutoPlayTimer();
|
return popup.clearAutoPlayTimer();
|
||||||
|
@ -88,6 +88,11 @@ class PopupProxy {
|
|||||||
return await this.invokeHostApi('kanjiShow', {id, elementRect, writingMode, definitions, context});
|
return await this.invokeHostApi('kanjiShow', {id, elementRect, writingMode, definitions, context});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setCustomCss(css) {
|
||||||
|
const id = await this.getPopupId();
|
||||||
|
return await this.invokeHostApi('setCustomCss', {id, css});
|
||||||
|
}
|
||||||
|
|
||||||
async clearAutoPlayTimer() {
|
async clearAutoPlayTimer() {
|
||||||
if (this.id === null) {
|
if (this.id === null) {
|
||||||
return;
|
return;
|
||||||
|
@ -292,6 +292,10 @@ class Popup {
|
|||||||
this.invokeApi('kanjiShow', {definitions, context});
|
this.invokeApi('kanjiShow', {definitions, context});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setCustomCss(css) {
|
||||||
|
this.invokeApi('setCustomCss', {css});
|
||||||
|
}
|
||||||
|
|
||||||
clearAutoPlayTimer() {
|
clearAutoPlayTimer() {
|
||||||
if (this.isInjected) {
|
if (this.isInjected) {
|
||||||
this.invokeApi('clearAutoPlayTimer');
|
this.invokeApi('clearAutoPlayTimer');
|
||||||
|
@ -29,6 +29,7 @@ class Display {
|
|||||||
this.audioPlaying = null;
|
this.audioPlaying = null;
|
||||||
this.audioFallback = null;
|
this.audioFallback = null;
|
||||||
this.audioCache = {};
|
this.audioCache = {};
|
||||||
|
this.styleNode = null;
|
||||||
|
|
||||||
this.eventListeners = [];
|
this.eventListeners = [];
|
||||||
this.persistentEventListeners = [];
|
this.persistentEventListeners = [];
|
||||||
@ -195,6 +196,7 @@ class Display {
|
|||||||
async updateOptions(options) {
|
async updateOptions(options) {
|
||||||
this.options = options ? options : await apiOptionsGet(this.getOptionsContext());
|
this.options = options ? options : await apiOptionsGet(this.getOptionsContext());
|
||||||
this.updateTheme(this.options.general.popupTheme);
|
this.updateTheme(this.options.general.popupTheme);
|
||||||
|
this.setCustomCss(this.options.general.customPopupCss);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTheme(themeName) {
|
updateTheme(themeName) {
|
||||||
@ -207,6 +209,20 @@ class Display {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCustomCss(css) {
|
||||||
|
if (this.styleNode === null) {
|
||||||
|
if (css.length === 0) { return; }
|
||||||
|
this.styleNode = document.createElement('style');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.styleNode.textContent = css;
|
||||||
|
|
||||||
|
const parent = document.head;
|
||||||
|
if (this.styleNode.parentNode !== parent) {
|
||||||
|
parent.appendChild(this.styleNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setInteractive(interactive) {
|
setInteractive(interactive) {
|
||||||
interactive = !!interactive;
|
interactive = !!interactive;
|
||||||
if (this.interactive === interactive) { return; }
|
if (this.interactive === interactive) { return; }
|
||||||
|
Loading…
Reference in New Issue
Block a user