GotoArXivCN

Open arXiv sites with arXivCN

  1. // ==UserScript==
  2. // @name GotoArXivCN
  3. // @namespace https://github.com/zzilch/GotoArXivMirrors
  4. // @homepage https://github.com/zzilch/GotoArXivMirrors
  5. // @version 1.1
  6. // @author zzilch
  7. // @description Open arXiv sites with arXivCN
  8. // @include /^https?://(.*\.)?arxiv\.org/.*/
  9. // @include http://xxx.itp.ac.cn/*
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. // useful funcitons
  16. function incompletePDF(url){ return url.includes('/pdf') && !url.endsWith('pdf') }
  17. function abstractURL(url){ return url.includes('/abs') }
  18.  
  19. // available mirrors
  20. let mirrors = {
  21. 'Main':'arxiv.org',
  22. 'China':'xxx.itp.ac.cn',
  23. 'Germany':'de.arxiv.org',
  24. 'India':'in.arxiv.org',
  25. }
  26.  
  27. // auto redirect to ArxivCN
  28. if(!location.href.includes(mirrors.China)){
  29. let url = location.href.replace(location.hostname,mirrors.China).replace('https','http')
  30. url = incompletePDF(url) ? url+'.pdf' : url
  31. location.replace(url)
  32. }
  33.  
  34. // append the filename extension for downloading
  35. if(incompletePDF(location.href)) { history.pushState(null,"",location.href+'.pdf') }
  36.  
  37. // complete pdf url with filename extension after the document is loaded
  38. onload = function(){
  39. if(abstractURL(location.href))
  40. { document.querySelector("#abs > div.extra-services > div.full-text > ul > li:nth-child(1) > a").href += '.pdf' }
  41. }
  42. })();

QingJ © 2025

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