-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
53 lines (48 loc) · 1.47 KB
/
background.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
title: "Open with Scholarr",
contexts: ["selection", "link"],
id: "openwithscholarr",
});
// chrome.contextMenus.create({
// title: "Copy APA citation",
// contexts: ["selection", "link"],
// id: "copycitation",
// });
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId == "openwithscholarr") {
let constructedUrl = `https://sci-hub.ru/${
info.linkUrl ? info.linkUrl : info.selectionText
}`;
console.log(info);
console.log(constructedUrl);
chrome.tabs.create({
url: constructedUrl,
});
}
});
// chrome.contextMenus.onClicked.addListener((info, tab) => {
// if (info.menuItemId == "copycitation") {
// console.log(document.execCommand("paste"));
// // let doiLink = info.linkUrl;
// // fetch(
// // `https://citation.crosscite.org/format?doi=${doiLink}&style=apa&lang=en-US`
// // )
// // .then((response) => response.text())
// // .then((response) => {
// // console.log(response);
// // navigator.clipboard.writeText("hi");
// // })
// // .catch((err) => console.error(err));
// } else {
// let constructedUrl = `https://sci-hub.se/${
// info.linkUrl ? info.linkUrl : info.selectionText
// }`;
// console.log(info);
// console.log(constructedUrl);
// chrome.tabs.create({
// url: constructedUrl,
// });
// }
// });