arxiv论文下载重命名工具

当您从arxiv.org下载论文时,它可以将pdf重命名为【日期+论文标题】的形式

  1. // ==UserScript==
  2. // @name arxiv-download-rename-tool
  3. // @name:zh-CN arxiv论文下载重命名工具
  4. // @name:zh-TW arxiv論文下載重命名工具
  5. // @name:en arxiv-download-rename-tool
  6. // @namespace https://www.tampermonkey.net/
  7. // @version 0.8
  8. // @description When you download a paper from arxiv.org, it can rename the pdf to the form [date + paper title]
  9. // @description:zh-CN 当您从arxiv.org下载论文时,它可以将pdf重命名为【日期+论文标题】的形式
  10. // @description:zh-tw 當您從arxiv.org下載論文時,它可以將pdf重命名為【日期+論文標題】的形式
  11. // @description:en When you download a paper from arxiv.org, it can rename the pdf to the form [date + paper title]
  12. // @author Sean
  13. // @match *://arxiv.org/abs/*
  14. // @match *://arxiv.org/search/*
  15. // @match *://arxiv.org/list/*
  16. // @icon https://static.arxiv.org/static/browse/0.3.4/images/icons/favicon-32x32.png
  17. // @grant none
  18. // @homepage https://github.com/seanxuu/arxiv-download-rename-tool
  19. // @license AGPL License
  20. // ==/UserScript==
  21.  
  22. (function () {
  23. "use strict";
  24. const url = location.pathname,
  25. webTitle = document.title;
  26. var downloadName = "",
  27. downloadPath = "";
  28. var papertitle = "",
  29. papertime = "";
  30. // add expanding all abs
  31. var more = $("a:contains(More)");
  32. for(var i = 0; i < more.length; i++) {
  33. more[i].click();
  34. }
  35. if (url.search("/abs/") != -1) {
  36. papertitle = document.querySelector("#abs > h1").innerText;
  37. downloadPath = window.location.href.replace("abs", "pdf") + ".pdf"; //document.querySelector("#abs-outer > div.extra-services > div.full-text > ul > li:nth-child(1) > a")+'.pdf'
  38. papertime = window.location.pathname.slice(5, 9); //document.querySelector("#abs > div.metatable > table > tbody > tr:nth-child(3) > td.tablecell.arxivid > span > a").innerText.slice(6,10)
  39. downloadName = renamePaperFile(papertitle, papertime);
  40. addDownloadButton(
  41. downloadPath,
  42. downloadName,
  43. document.querySelector("#abs-outer > div.extra-services > div.full-text")
  44. );
  45. }
  46. if (url.search("/search/") != -1) {
  47. var paperlist = document.querySelectorAll(
  48. "#main-container > div.content > ol > li"
  49. );
  50. for (let i = 0; i < paperlist.length; i++) {
  51. let listItem = paperlist[i];
  52. try {
  53. papertitle = listItem.children[1].textContent.trim();
  54. papertime = listItem.children[0].innerText.slice(6, 10);
  55. } catch (error) {
  56. console.log(papertitle, i);
  57. console.log(listItem.children[0]);
  58. }
  59. papertime = listItem.children[0].innerText.slice(6, 10);
  60. downloadName = renamePaperFile(papertitle, papertime);
  61. try {
  62. downloadPath =
  63. listItem.children[0].children[0].children[1].children[0].getAttribute(
  64. "href"
  65. );
  66. } catch (error) {
  67. downloadPath = listItem.children[0].children[0].children[0].href;
  68. downloadPath = downloadPath.replace("abs", "pdf");
  69. }
  70. addDownloadButton(downloadPath, downloadName, listItem.children[0]);
  71. }
  72. }
  73. if (url.search("/list/") != -1) {
  74. let paperlist = document.querySelectorAll(".list-identifier");
  75. for (let i = 0, len = paperlist.length; i < len; i++) {
  76. try {
  77. let paper = paperlist[i];
  78. papertitle =
  79. paper.parentNode.nextElementSibling.querySelector(
  80. ".list-title"
  81. ).innerText;
  82. downloadPath =
  83. paper.querySelector('a[title="Download PDF"]').href + ".pdf";
  84. papertime = downloadPath.split("/").pop().split(".")[0];
  85. downloadName = renamePaperFile(papertitle, papertime);
  86. addDownloadButton(downloadPath, downloadName, paper);
  87. } catch (error) {
  88. console.warn("AUTO download rename raise warning at : " + papertitle);
  89. }
  90. }
  91. }
  92.  
  93. function addDownloadButton(downloadPath, downloadName, element) {
  94. var button = document.createElement("a");
  95. button.id = "downloadPaper";
  96. button.textContent = "⏬Download paper with a new name⏬";
  97. button.setAttribute("href", downloadPath);
  98. button.setAttribute("download", downloadName);
  99. element.append(button);
  100. }
  101. function renamePaperFile(name, time) {
  102. var downloadName = name.replace(": ", ":");
  103. downloadName = downloadName.replace(":", ":");
  104. downloadName = downloadName.replace("?", "?");
  105. downloadName = downloadName.replace("/", " OR ");
  106. downloadName = downloadName.replace('"', "“") + ".pdf";
  107. return "[" + time + "]" + downloadName;
  108. }
  109. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址