aboutsummaryrefslogtreecommitdiff
path: root/src/content/Bootstrap.ts
blob: 62e1530b8d2ae1c59f0cc779887d2b31f051adf9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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,
    });
  }
}