From ec922e80319999373fdfc6971e0b4d9cc6534aab Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 29 Mar 2022 13:03:19 +0200 Subject: [PATCH] added navigation buttons to frames Closes #8 --- main.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/main.ts b/main.ts index c43a4c2..7bc7aec 100644 --- a/main.ts +++ b/main.ts @@ -110,6 +110,8 @@ class CustomFrameView extends ItemView { this.addAction("refresh-cw", "Refresh", () => this.refresh()); this.addAction("home", "Return to original page", () => this.return()); + this.addAction("arrow-left", "Go back", () => this.goBack()); + this.addAction("arrow-right", "Go forward", () => this.goForward()); } onload(): void { @@ -155,6 +157,16 @@ class CustomFrameView extends ItemView { i.setIcon("home"); i.onClick(() => this.return()); }); + menu.addItem(i => { + i.setTitle("Go back"); + i.setIcon("arrow-left"); + i.onClick(() => this.goBack()); + }); + menu.addItem(i => { + i.setTitle("Go forward"); + i.setIcon("arrow-right"); + i.onClick(() => this.goForward()); + }); } getViewType(): string { @@ -184,6 +196,24 @@ class CustomFrameView extends ItemView { this.frame.loadURL(this.data.url); } } + + private goBack(): void { + if (this.frame instanceof HTMLIFrameElement) { + this.frame.contentWindow.history.back(); + } + else { + this.frame.goBack(); + } + } + + private goForward() { + if (this.frame instanceof HTMLIFrameElement) { + this.frame.contentWindow.history.forward(); + } + else { + this.frame.goForward(); + } + } } class CustomFramesSettingTab extends PluginSettingTab {