Override setCustomOuterCss instead of Popup.injectOuterStylesheet

This commit is contained in:
toasted-nutbread 2020-02-16 13:37:03 -05:00
parent b6a50e234c
commit d3aefdc4e3

View File

@ -22,7 +22,8 @@ class SettingsPopupPreview {
constructor() { constructor() {
this.frontend = null; this.frontend = null;
this.apiOptionsGetOld = apiOptionsGet; this.apiOptionsGetOld = apiOptionsGet;
this.popupInjectOuterStylesheetOld = Popup.injectOuterStylesheet; this.popup = null;
this.popupSetCustomOuterCssOld = null;
this.popupShown = false; this.popupShown = false;
this.themeChangeTimeout = null; this.themeChangeTimeout = null;
this.textSource = null; this.textSource = null;
@ -50,19 +51,19 @@ class SettingsPopupPreview {
const popupHost = new PopupProxyHost(); const popupHost = new PopupProxyHost();
await popupHost.prepare(); await popupHost.prepare();
const popup = popupHost.getOrCreatePopup(); this.popup = popupHost.getOrCreatePopup();
popup.setChildrenSupported(false); this.popup.setChildrenSupported(false);
this.frontend = new Frontend(popup); this.popupSetCustomOuterCssOld = this.popup.setCustomOuterCss;
this.popup.setCustomOuterCss = (...args) => this.popupSetCustomOuterCss(...args);
this.frontend = new Frontend(this.popup);
this.frontend.setEnabled = function () {}; this.frontend.setEnabled = function () {};
this.frontend.searchClear = function () {}; this.frontend.searchClear = function () {};
await this.frontend.prepare(); await this.frontend.prepare();
// Overwrite popup
Popup.injectOuterStylesheet = (...args) => this.popupInjectOuterStylesheet(...args);
// Update search // Update search
this.updateSearch(); this.updateSearch();
} }
@ -83,9 +84,9 @@ class SettingsPopupPreview {
return options; return options;
} }
popupInjectOuterStylesheet(...args) { async popupSetCustomOuterCss(...args) {
// This simulates the stylesheet priorities when injecting using the web extension API. // This simulates the stylesheet priorities when injecting using the web extension API.
const result = this.popupInjectOuterStylesheetOld(...args); const result = await this.popupSetCustomOuterCssOld.call(this.popup, ...args);
const outerStylesheet = Popup.outerStylesheet; const outerStylesheet = Popup.outerStylesheet;
const node = document.querySelector('#client-css'); const node = document.querySelector('#client-css');