-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSci_Hub_Auto_Download.js
58 lines (50 loc) · 2.14 KB
/
Sci_Hub_Auto_Download.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
54
55
56
57
58
async function main()
{
let settings_storage = get_storage('settings')
let hide_sci_hub = settings_storage["hide_scihub_or_libgen"]
if (document.getElementById('pdf'))
{
if ('src' in document.getElementById('pdf'))
{
let pdf_link = document.getElementById('pdf')['src']
// console.log("Download link:", pdf_link)
let link_filename = pdf_link.split('/')
link_filename = link_filename[link_filename.length - 1].split('#')[0]
location.replace(pdf_link)
if (hide_sci_hub)
{
let text = "<b>PDF download started by LYH DOI Tools... </b></br></br>"
text += 'PDF file found: <b>[ ' + link_filename + ' ]</b><br><br>'
text += 'This page will self-destruct in 10 seconds...<br><br>'
text += 'Cancel this by unchecking the "Auto hide Sci-Hub or Lib-Gen page" option in the popup page<br><br>'
document.getElementById('article').innerHTML = '<center><br><br><br><br><br><br><br>' + text + '</center>'
// chrome.runtime.sendMessage({switch_to_previous_tab: window.location.href});
setTimeout(function ()
{
chrome.runtime.sendMessage({closeThis: true});
},
10000);
}
else
{
let text = "<b>PDF download auto-started by LYH DOI Tools... </b></br></br>"
text += 'PDF file found: <b>[ ' + link_filename + ' ]</b><br><br>'
text += 'You can close this tab now.<br><br>'
document.getElementById('article').innerHTML = '<center><br><br><br><br><br><br><br>' + text + '</center>'
}
}
else
{
console.log("PDF file not found.")
}
}
else
{
console.log("PDF file not found.")
}
}
let current_host_check_scihub = new URL(window.location.href).host
if (current_host_check_scihub.toLowerCase().search("sci-hub")!==-1)
{
main()
}