This repository was archived by the owner on Mar 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
77 lines (68 loc) · 2.57 KB
/
Copy pathbackground.js
File metadata and controls
77 lines (68 loc) · 2.57 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const defaultSettings = {
enableIconClick: true,
enableHotkey: true,
sciHubDomain: "https://www.sci-hub.ru/",
arxivDomain: "https://arxiv.org/pdf/"
};
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.set(defaultSettings);
chrome.contextMenus.create({
id: "open-in-scihub",
title: "Open in Sci-Hub",
contexts: ["all"]
});
});
// arxiv automation implementation
function arxividentifier(urlToOpen) {
const arxivMatch = urlToOpen.split("arxiv.org/abs/")[1];
if (arxivMatch) {
return "https://arxiv.org/pdf/" + arxivMatch;
}
return null;
}
function isArxivUrl(url) {
return url.includes("arxiv.org");
}
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "open-in-scihub") {
chrome.tabs.create({ url: "https://git.new/open-in-sci-hub" });
}
});
chrome.commands.onCommand.addListener((command) => {
if (command === "open-in-scihub") {
chrome.storage.sync.get(["enableHotkey", "sciHubDomain", "arxivDomain"], (settings) => {
if (settings.enableHotkey) {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const currentUrl = tabs[0].url;
if (isArxivUrl(currentUrl)) {
const arxivUrl = arxividentifier(currentUrl);
if (arxivUrl) {
const arxivResearchUrl = settings.arxivDomain + arxivUrl.split("https://arxiv.org/pdf/")[1];
chrome.tabs.create({ url: arxivResearchUrl });
}
} else {
const sciHubUrl = settings.sciHubDomain + currentUrl;
chrome.tabs.create({ url: sciHubUrl });
}
});
}
});
}
});
chrome.action.onClicked.addListener((tab) => {
chrome.storage.sync.get(["enableIconClick", "sciHubDomain", "arxivDomain"], (settings) => {
if (settings.enableIconClick) {
const currentUrl = tab.url;
if (isArxivUrl(currentUrl)) {
const arxivUrl = arxividentifier(currentUrl);
if (arxivUrl) {
const arxivResearchUrl = settings.arxivDomain + arxivUrl.split("https://arxiv.org/pdf/")[1];
chrome.tabs.create({ url: arxivResearchUrl });
}
} else {
const sciHubUrl = settings.sciHubDomain + currentUrl;
chrome.tabs.create({ url: sciHubUrl });
}
}
});
});