-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
29 lines (26 loc) · 1.24 KB
/
main.js
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
searchWebArchive = function (word) {
// Use the URL from the input field as needed.
const searchBySelection = word.selectionText;
const searchByHover = word.linkUrl;
// TODO - make the decision which mode to use based on the content word; e.g. pattern based
// if hovering over a link - search for that link on webarchive and exit
if (searchByHover) {
const newURL = `https://web.archive.org/cdx/search/cdx?url=${searchByHover}&matchType=domain&fl=original&collapse=urlkey&output=text&filter=statuscode:200`;
// Open the modified URL in a new tab.
chrome.tabs.create({ url: newURL });
return;
}
// if text is selected - search for that text as a domain name on webarchive
if (searchBySelection) {
const newURL = `https://web.archive.org/cdx/search/cdx?url=${searchBySelection}&matchType=domain&fl=original&collapse=urlkey&output=text&filter=statuscode:200`;
// Open the modified URL in a new tab.
chrome.tabs.create({ url: newURL });
}
};
chrome.contextMenus.removeAll(function() {
chrome.contextMenus.create({
id: "1",
title: "Search WebArchive",
contexts:["selection","link"], // ContextType
}); })
chrome.contextMenus.onClicked.addListener(searchWebArchive);