aboutsummaryrefslogtreecommitdiff
path: root/src/content/presenters/ConsoleFramePresenter.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-03-17 23:20:41 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2021-03-21 12:24:36 +0900
commit3ffb4b066cdcc60a49ce4ecd0bbc498da6256534 (patch)
treed118d1c1251fd93b9d36df79da80056ff13938b3 /src/content/presenters/ConsoleFramePresenter.ts
parent5382f2353e693bc8e2682eb045e8bb9930829adc (diff)
Attach/detach console iframe on addon enabled/disabled
Diffstat (limited to 'src/content/presenters/ConsoleFramePresenter.ts')
-rw-r--r--src/content/presenters/ConsoleFramePresenter.ts25
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();
}