aboutsummaryrefslogtreecommitdiff
path: root/src/content/presenters/ConsoleFramePresenter.ts
blob: 0db58f0b9367938c8f52d1b71834b755f62cdcbd (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
export default interface ConsoleFramePresenter {
  attach(): void;

  detach(): void;

  blur(): void;

  resize(width: number, height: number): void;

  isTopWindow(): boolean;
}

export class ConsoleFramePresenterImpl implements ConsoleFramePresenter {
  private static readonly IframeId = "vimvixen-console-frame" as const;

  attach(): void {
    const ele = document.getElementById("vimvixen-console-frame");
    if (ele) {
      return;
    }

    const iframe = document.createElement("iframe");
    iframe.src = browser.runtime.getURL("build/console.html");
    iframe.id = ConsoleFramePresenterImpl.IframeId;
    iframe.className = "vimvixen-console-frame";
    document.body.append(iframe);
  }

  detach(): void {
    const ele = document.getElementById(ConsoleFramePresenterImpl.IframeId);
    if (!ele) {
      return;
    }
    ele.remove();
  }

  blur(): void {
    const ele = document.getElementById("vimvixen-console-frame");
    if (!ele) {
      return;
    }
    ele.blur();
  }

  resize(_width: number, height: number): void {
    const ele = document.getElementById("vimvixen-console-frame");
    if (!ele) {
      return;
    }
    ele.style.height = `${height}px`;
  }

  isTopWindow(): boolean {
    return window.top === window;
  }
}