diff options
Diffstat (limited to 'src/content/presenters/ConsoleFramePresenter.ts')
-rw-r--r-- | src/content/presenters/ConsoleFramePresenter.ts | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/content/presenters/ConsoleFramePresenter.ts b/src/content/presenters/ConsoleFramePresenter.ts index ccc196b..9c4b3f1 100644 --- a/src/content/presenters/ConsoleFramePresenter.ts +++ b/src/content/presenters/ConsoleFramePresenter.ts @@ -1,5 +1,7 @@ export default interface ConsoleFramePresenter { - initialize(): void; + attach(): void; + + detach(): void; blur(): void; @@ -7,18 +9,33 @@ export default interface ConsoleFramePresenter { } export class ConsoleFramePresenterImpl implements ConsoleFramePresenter { - initialize(): void { + 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 = "vimvixen-console-frame"; + 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) { - throw new Error("console frame not created"); + return; } ele.blur(); } |