From ebf000b0bcf8bcf919f2a7c3944ece219a03ad1e Mon Sep 17 00:00:00 2001
From: trickypr <23250792+trickypr@users.noreply.github.com>
Date: Tue, 14 Nov 2023 22:22:57 +1100
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Link=20context=20menus?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/actors/ContextMenu.types.ts | 1 +
src/actors/ContextMenuChild.ts | 12 +++++++++
.../contextMenus/BrowserContextMenu.svelte | 26 ++++++++++++++++++-
src/content/browser/lib/globalApi.ts | 26 ++++++++++++-------
src/prefs.js | 3 +++
5 files changed, 58 insertions(+), 10 deletions(-)
diff --git a/src/actors/ContextMenu.types.ts b/src/actors/ContextMenu.types.ts
index b4ce07b..ef9a516 100644
--- a/src/actors/ContextMenu.types.ts
+++ b/src/actors/ContextMenu.types.ts
@@ -13,4 +13,5 @@ export interface ContextMenuInfo {
}
textSelection?: string
+ href?: string
}
diff --git a/src/actors/ContextMenuChild.ts b/src/actors/ContextMenuChild.ts
index a5616f7..269498c 100644
--- a/src/actors/ContextMenuChild.ts
+++ b/src/actors/ContextMenuChild.ts
@@ -11,6 +11,16 @@ const lazy = lazyESModuleGetters({
})
export class ContextMenuChild extends JSWindowActorChild {
+ getHrefIfExists(target: Node): string | undefined {
+ if ((target as HTMLAnchorElement).href) {
+ return (target as HTMLAnchorElement).href
+ }
+
+ if (target.parentElement) {
+ return this.getHrefIfExists(target.parentElement)
+ }
+ }
+
handleEvent(event: MouseEvent & { inputSource: number }) {
const data: {
position: ContextMenuInfo['position']
@@ -29,6 +39,8 @@ export class ContextMenuChild extends JSWindowActorChild {
data.textSelection = selectionInfo.fullText
}
+ if (event.target) data.href = this.getHrefIfExists(event.target as Node)
+
this.sendAsyncMessage('contextmenu', data satisfies ContextMenuInfo)
}
}
diff --git a/src/content/browser/components/contextMenus/BrowserContextMenu.svelte b/src/content/browser/components/contextMenus/BrowserContextMenu.svelte
index 385bb3a..7bac34c 100644
--- a/src/content/browser/components/contextMenus/BrowserContextMenu.svelte
+++ b/src/content/browser/components/contextMenus/BrowserContextMenu.svelte
@@ -3,14 +3,38 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->