aboutsummaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/Bootstrap.ts27
-rw-r--r--src/content/index.ts34
2 files changed, 49 insertions, 12 deletions
diff --git a/src/content/Bootstrap.ts b/src/content/Bootstrap.ts
new file mode 100644
index 0000000..62e1530
--- /dev/null
+++ b/src/content/Bootstrap.ts
@@ -0,0 +1,27 @@
+type Callback = () => void;
+
+export default class Bootstrap {
+ constructor() {}
+
+ isReady(): boolean {
+ return document.body !== null;
+ }
+
+ waitForReady(callback: Callback): void {
+ const observer = new MutationObserver(() => {
+ if (document.body != null) {
+ observer.disconnect();
+ callback();
+ }
+ });
+
+ observer.observe(document, {
+ attributes: false,
+ attributeOldValue: false,
+ characterData: false,
+ characterDataOldValue: false,
+ childList: true,
+ subtree: true,
+ });
+ }
+}
diff --git a/src/content/index.ts b/src/content/index.ts
index b575e0d..5252338 100644
--- a/src/content/index.ts
+++ b/src/content/index.ts
@@ -1,22 +1,32 @@
import "reflect-metadata";
import Application from "./Application";
+import Bootstrap from "./Bootstrap";
import consoleFrameStyle from "./site-style";
import { ConsoleFramePresenterImpl } from "./presenters/ConsoleFramePresenter";
import { container } from "tsyringe";
import "./di";
-if (window.self === window.top) {
- new ConsoleFramePresenterImpl().initialize();
-}
+const initDom = () => {
+ if (window.self === window.top) {
+ new ConsoleFramePresenterImpl().initialize();
+ }
-try {
- const app = container.resolve(Application);
- app.run();
-} catch (e) {
- console.error(e);
-}
+ try {
+ const app = container.resolve(Application);
+ app.run();
+ } catch (e) {
+ console.error(e);
+ }
-const style = window.document.createElement("style");
-style.textContent = consoleFrameStyle;
-window.document.head.appendChild(style);
+ const style = window.document.createElement("style");
+ style.textContent = consoleFrameStyle;
+ window.document.head.appendChild(style);
+};
+
+const bootstrap = new Bootstrap();
+if (bootstrap.isReady()) {
+ initDom();
+} else {
+ bootstrap.waitForReady(() => initDom());
+}