-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathancestryLibrary.js
More file actions
53 lines (46 loc) · 1.34 KB
/
ancestryLibrary.js
File metadata and controls
53 lines (46 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Remain platform independent
if (typeof browser === "undefined") {
browser = chrome;
}
const cmId = "open-link-in-ancestry-library";
// Create context menu item
browser.contextMenus.create(
{
id: cmId,
title: "Open link in AncestryLibrary",
contexts: ["link"],
// visible: false, // Initially hidden
},
// onCreated,
() => void browser.runtime.lastError,
);
// Show/hide based on whether the right-clicked link is *.ancestry.com
// browser.contextMenus.onShown.addListener((info, tab) => {
// const linkUrl = info.linkUrl;
// const isAncestrySubdomain = new URL(linkUrl).hostname.endsWith(
// ".ancestry.com",
// );
// browser.contextMenus.update(cmId, {
// visible: isAncestrySubdomain,
// });
// // Refresh menu and apply visibility settings
// browser.contextMenus.refresh();
// });
// Click event listener/handler
browser.contextMenus.onClicked.addListener(function (info, tab) {
console.log(info);
switch (info.menuItemId) {
case "open-link-in-ancestry-library":
console.log(info.selectionText);
console.info("Open in AL: " + info.linkUrl);
if (info.linkUrl) {
let newTab = browser.tabs.create({
active: false,
url: info.linkUrl.replace("ancestry.com", "ancestrylibrary.com"),
index: tab.index + 1,
});
}
break;
// ...
}
});