arXiv Redirect and Rename

Slove the "Access Denied" problem in arXiv

  1. // ==UserScript==
  2. // @name arXiv Redirect and Rename
  3. // @include https://arxiv.org/*
  4. // @version 1.0
  5. // @description Slove the "Access Denied" problem in arXiv
  6. // And rename the download pdf
  7. // @author Daqing Liu
  8. // @date 2020.01.07
  9. // @namespace http://home.ustc.edu.cn/~liudq/
  10. // ==/UserScript==
  11.  
  12. // fork from EvanL00
  13. var dow = function() {
  14. 'use strict';
  15. // find the title
  16. var title = document.getElementsByClassName("title mathjax")[0].innerText;
  17. //find where to put the tag
  18. var loc = document.getElementsByClassName("full-text")[0].getElementsByTagName('ul');
  19. var obj = document.createElement("li");
  20. //get the pdf url
  21. var pdfurl = document.getElementsByClassName("full-text")[0].getElementsByTagName('ul')[0].getElementsByTagName('a')[0].href;
  22. //check name
  23. if (!pdfurl.endsWith(".pdf")) {
  24. pdfurl = pdfurl + '.pdf';
  25. }
  26. //change name
  27. var fileName = document.title.replace(/\.\d*/, '') + '.pdf';
  28. obj.innerHTML = '<a download='+ '"'+ fileName + '"' + ' href=' + pdfurl +'>Save as PDF</a>';
  29. loc[0].insertBefore(obj, loc[0].childNodes[0]);
  30. };
  31. dow();
  32.  
  33. var rename = function() {
  34. var content;
  35. var CheckStr = 'Access Denied';
  36. var IsRedirect = false;
  37.  
  38. var stre = document.getElementsByTagName('h1');
  39.  
  40. var i;
  41. for (i = 0; i < stre.length; i++) {
  42. content = stre[i].innerText;
  43. if(content.indexOf(CheckStr) != -1){
  44. IsRedirect = true;
  45. }
  46. }
  47.  
  48. if(IsRedirect){
  49. var url = window.location.toString();
  50. window.location = url.replace('https://arxiv.org/', 'http://cn.arxiv.org/');
  51. }
  52. };
  53. rename();

QingJ © 2025

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