arxiv titleAsPDFName

when download paper from arxiv.org, automate set the file name as the paper's title

  1. // ==UserScript==
  2. // @name arxiv titleAsPDFName
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description when download paper from arxiv.org, automate set the file name as the paper's title
  6. // @author EvanL00
  7. // @match https://arxiv.org*
  8. // @include https://arxiv.org*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. var dow = function() {
  13. 'use strict';
  14. // find the title
  15. var title = document.getElementsByClassName("title mathjax")[0].innerText;
  16. //find where to put the tag
  17. var loc = document.getElementsByClassName("full-text")[0].getElementsByTagName('ul');
  18. var obj = document.createElement("li");
  19. //get the pdf url
  20. var urls = document.getElementsByClassName("full-text")[0].getElementsByTagName('a');
  21. for (const url of urls) {
  22. if (url.className.includes('download-pdf')) {
  23. let pdfurl = url.href;
  24. if (!pdfurl.endsWith(".pdf")) {
  25. pdfurl = url + '.pdf';
  26. }
  27. var fileName = title.toString().replace(':', '--') + '.pdf';
  28. obj.innerHTML = '<a download='+ '"'+ fileName + '"' + ' href=' + pdfurl +'>Save as pdf</a>';
  29. //loc.insertBefore(obj, loc.childNodes[0]);
  30. loc[0].insertBefore(obj, loc[0].childNodes[0]);
  31. }
  32.  
  33. }
  34. //var getUrlHttp = new XMLHttpRequest();
  35. //getUrlHttp.open('GET', url, true);
  36. //getUrlHttp.send(null);
  37. //var res = getUrlHttp.responseText;
  38. //var myRex = /(http:\/\/ieee[^"]+)/;
  39. //var pdfurl = res.match(myRex)[0];
  40.  
  41. };
  42. dow();