aboutsummaryrefslogtreecommitdiff
path: root/src/content/presenters
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/presenters')
-rw-r--r--src/content/presenters/ConsoleFramePresenter.ts31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/content/presenters/ConsoleFramePresenter.ts b/src/content/presenters/ConsoleFramePresenter.ts
index ccc196b..0db58f0 100644
--- a/src/content/presenters/ConsoleFramePresenter.ts
+++ b/src/content/presenters/ConsoleFramePresenter.ts
@@ -1,24 +1,43 @@
export default interface ConsoleFramePresenter {
- initialize(): void;
+ attach(): void;
+
+ detach(): void;
blur(): void;
resize(width: number, height: number): void;
+
+ isTopWindow(): boolean;
}
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();
}
@@ -30,4 +49,8 @@ export class ConsoleFramePresenterImpl implements ConsoleFramePresenter {
}
ele.style.height = `${height}px`;
}
+
+ isTopWindow(): boolean {
+ return window.top === window;
+ }
}