2020-12-03 01:35:22 +01:00
|
|
|
if (process.env.CHANNEL !== 'stable'){
|
|
|
|
console.info("Loading: UI");
|
|
|
|
}
|
|
|
|
|
2020-12-03 00:34:50 +01:00
|
|
|
class UI {
|
|
|
|
constructor(
|
|
|
|
interfaceId,
|
|
|
|
uiConfig, // {component, parentElement?}
|
|
|
|
) {
|
|
|
|
this.interfaceId = interfaceId;
|
2020-12-03 01:35:22 +01:00
|
|
|
this.uiConfig = uiConfig;
|
|
|
|
|
|
|
|
this.init();
|
2020-12-03 00:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
const random = Math.round(Math.random() * 69420);
|
2022-01-07 00:50:58 +01:00
|
|
|
const uwid = `uw-ultrawidify-${this.interfaceId}-root-${random}`
|
2020-12-03 00:34:50 +01:00
|
|
|
|
|
|
|
const rootDiv = document.createElement('div');
|
|
|
|
|
2020-12-15 00:26:19 +01:00
|
|
|
if (this.uiConfig.additionalStyle) {
|
|
|
|
rootDiv.setAttribute('style', this.uiConfig.additionalStyle);
|
|
|
|
}
|
2020-12-05 03:30:43 +01:00
|
|
|
rootDiv.setAttribute('id', uwid);
|
2020-12-12 00:38:51 +01:00
|
|
|
rootDiv.classList.add('uw-ultrawidify-container-root');
|
2020-12-04 02:02:25 +01:00
|
|
|
|
|
|
|
if (this.uiConfig?.parentElement) {
|
2020-12-03 00:34:50 +01:00
|
|
|
this.uiConfig.parentElement.appendChild(rootDiv);
|
|
|
|
} else {
|
|
|
|
document.body.appendChild(rootDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.element = rootDiv;
|
|
|
|
|
2022-01-07 00:50:58 +01:00
|
|
|
try {
|
|
|
|
const iframe = document.createElement('iframe');
|
|
|
|
iframe.setAttribute('src', browser.runtime.getURL('/csui/csui.html'));
|
|
|
|
iframe.style.width = "100%";
|
|
|
|
iframe.style.height = "100%";
|
|
|
|
iframe.style.position = "absolute";
|
|
|
|
iframe.style.zIndex = "1000";
|
|
|
|
|
|
|
|
rootDiv.appendChild(iframe);
|
|
|
|
} catch(e) {
|
|
|
|
|
2020-12-04 02:02:25 +01:00
|
|
|
}
|
2021-10-26 23:13:11 +02:00
|
|
|
|
2022-01-07 00:50:58 +01:00
|
|
|
console.log('——————————————————————————————————————— UI IS BEING CREATED ', rootDiv);
|
2020-12-03 00:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces ui config and re-inits the UI
|
2021-10-22 00:30:36 +02:00
|
|
|
* @param {*} newUiConfig
|
2020-12-03 00:34:50 +01:00
|
|
|
*/
|
|
|
|
replace(newUiConfig) {
|
|
|
|
this.element?.remove();
|
|
|
|
this.uiConfig = newUiConfig;
|
2022-01-07 00:50:58 +01:00
|
|
|
this.init();
|
2020-12-03 00:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
2020-12-04 02:02:25 +01:00
|
|
|
// this.comms?.destroy();
|
2020-12-03 00:34:50 +01:00
|
|
|
this.element?.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 01:35:22 +01:00
|
|
|
if (process.env.CHANNEL !== 'stable'){
|
|
|
|
console.info("UI.js loaded");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-03 01:16:57 +01:00
|
|
|
export default UI;
|