Enhanced arXiv

Add some functions for arXiv

  1. // ==UserScript==
  2. // @name Enhanced arXiv
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Add some functions for arXiv
  6. // @author You
  7. // @match https://arxiv.org/abs/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function createButton(prompt, callback) {
  15. return `<button style="margin:0 8px;" class="button is-small" onclick='window.${callback}()'>${prompt}</button>`
  16. }
  17.  
  18. function main() {
  19. init();
  20. let targetElement = document.getElementsByClassName("authors")[0];
  21. let copyTitleButton = createButton("Copy Title", "copyTitle");
  22. let copyPDFLinkButton = createButton("Copy PDF Link", "copyPDFLink");
  23. let searchGoogleButton = createButton("Search With Google", "searchGoogle");
  24. targetElement.insertAdjacentHTML('beforeend', copyTitleButton);
  25. targetElement.insertAdjacentHTML('beforeend', copyPDFLinkButton);
  26. targetElement.insertAdjacentHTML('beforeend', searchGoogleButton);
  27. }
  28.  
  29. function init() {
  30. let hiddenTextArea = document.createElement('textarea');
  31. hiddenTextArea.setAttribute("id", "hiddenTextArea");
  32. hiddenTextArea.style.cssText = "display:hidden;";
  33. document.body.appendChild(hiddenTextArea);
  34. window.copyText = copyText;
  35. window.copyTitle = copyTitle;
  36. window.getPaperTitle = getPaperTitle;
  37. window.copyPDFLink = copyPDFLink;
  38. window.searchGoogle = searchGoogle;
  39. }
  40.  
  41. function copyText(text) {
  42. const textArea = document.getElementById('hiddenTextArea');
  43. textArea.textContent = text;
  44. document.body.append(textArea);
  45. textArea.select();
  46. document.execCommand("copy");
  47. }
  48.  
  49. function getPaperTitle() {
  50. let title = document.getElementsByTagName("h1")[2].textContent;
  51. title = title.replace("Title:", "");
  52. return title;
  53. }
  54.  
  55. function copyTitle() {
  56. let title = window.getPaperTitle();
  57. window.copyText(title)
  58. }
  59.  
  60. function copyPDFLink() {
  61. let link = document.getElementsByClassName("download-pdf")[0].href;
  62. window.copyText(link)
  63. }
  64.  
  65. function searchGoogle() {
  66. let title = window.getPaperTitle();
  67. window.open(`https://www.google.com/search?q=${title}`);
  68. }
  69. main();
  70. })();