-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenhanced-arxiv.user.js
More file actions
92 lines (79 loc) · 3.26 KB
/
enhanced-arxiv.user.js
File metadata and controls
92 lines (79 loc) · 3.26 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// ==UserScript==
// @name Enhanced arXiv
// @namespace http://tampermonkey.net/
// @version 0.5
// @description Add some functions for arXiv
// @author JustSong
// @match https://arxiv.org/abs/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function createButton(prompt, callback) {
return `<button style="margin:0 8px;" class="button is-small" onclick='window.${callback}()'>${prompt}</button>`
}
function createLinkButton(prompt, link, filename) {
return `<a href="${link}" download="${filename}" class="button is-small">${prompt}</a>`
}
function main() {
init();
let targetElement = document.getElementsByClassName("authors")[0];
let copyTitleButton = createButton("Copy Title", "copyTitle");
let copyPDFLinkButton = createButton("Copy PDF Link", "copyPDFLink");
let searchGoogleButton = createButton("Search With Google", "searchGoogle");
let searchGoogleScholarButton = createButton("Search With Google Scholar", "searchGoogleScholar");
let downloadOriginButton = createLinkButton("Download", `https://arxiv.org/pdf/${window.location.href.split('/')[4]}.pdf`, getPaperTitle(true));
targetElement.insertAdjacentHTML('beforeend', copyTitleButton);
targetElement.insertAdjacentHTML('beforeend', copyPDFLinkButton);
targetElement.insertAdjacentHTML('beforeend', searchGoogleButton);
targetElement.insertAdjacentHTML('beforeend', searchGoogleScholarButton);
targetElement.insertAdjacentHTML('beforeend', downloadOriginButton);
}
function init() {
let hiddenTextArea = document.createElement('textarea');
hiddenTextArea.setAttribute("id", "hiddenTextArea");
hiddenTextArea.style.cssText = "display:hidden;";
document.body.appendChild(hiddenTextArea);
window.copyText = copyText;
window.copyTitle = copyTitle;
window.getPaperTitle = getPaperTitle;
window.copyPDFLink = copyPDFLink;
window.searchGoogle = searchGoogle;
window.searchGoogleScholar = searchGoogleScholar;
window.savePDF = savePDF;
}
function copyText(text) {
const textArea = document.getElementById('hiddenTextArea');
textArea.textContent = text;
document.body.append(textArea);
textArea.select();
document.execCommand("copy");
}
function getPaperTitle(safeFilename=false) {
let title = document.getElementsByClassName("title")[0].textContent;
title = title.replace("Title:", "");
if (safeFilename) {
title = title.replace(/[/\\?%*:|"<>]/g, '');
}
return title;
}
function copyTitle() {
let title = window.getPaperTitle();
window.copyText(title)
}
function copyPDFLink() {
let link = document.getElementsByClassName("download-pdf")[0].href;
window.copyText(link)
}
function searchGoogle() {
let title = window.getPaperTitle();
window.open(`https://www.google.com/search?q=${title}`);
}
function searchGoogleScholar() {
let title = window.getPaperTitle();
window.open(`https://scholar.google.com/scholar?q=${title}`);
}
function savePDF() {
}
main();
})();