GotoArXivMirrors

Open arXiv sites with arXiv mirrors

  1. // ==UserScript==
  2. // @name GotoArXivMirrors
  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 arXiv mirrors
  8. // @include /^https?://(.*\.)?arxiv\.org/.*/
  9. // @include http://xxx.itp.ac.cn/*
  10. // @run-at document-start
  11. // @grant GM_registerMenuCommand
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. // useful funcitons
  17. function incompletePDF(url){ return url.includes('/pdf') && !url.endsWith('pdf') }
  18. function abstractURL(url){ return url.includes('/abs') }
  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. // Tampermonkey menu items
  27. for(let mirror in mirrors){
  28. let url = location.href.replace(location.hostname,mirrors[mirror]).replace('https','http')
  29. url = incompletePDF(url) ? url+'.pdf' : url
  30. console.log(mirror+':'+url)
  31. GM_registerMenuCommand(mirror,()=>location.replace(url));
  32. }
  33. // append the filename extension for downloading
  34. if(incompletePDF(location.href)) { history.pushState(null,"",location.href+'.pdf') }
  35. // complete pdf url with filename extension after the document is loaded
  36. onload = function(){
  37. if(abstractURL(location.href))
  38. { document.querySelector("#abs > div.extra-services > div.full-text > ul > li:nth-child(1) > a").href += '.pdf' }
  39. }
  40. })();