Redirect arxiv.org to cn.arxiv.org/pdf

将任何网页内指向arxov.org的pdf链接重写为arxiv中文镜像站cn.arxov.org的对应链接,加速pdf加载。 Redirect arxiv.org to cn.arxiv.org/pdf.

当前为 2018-07-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Redirect arxiv.org to cn.arxiv.org/pdf
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 将任何网页内指向arxov.org的pdf链接重写为arxiv中文镜像站cn.arxov.org的对应链接,加速pdf加载。 Redirect arxiv.org to cn.arxiv.org/pdf.
  6. // @author LTGuo
  7. // @include http://*.*
  8. // @include https://*.*
  9. // @require http://code.jquery.com/jquery-3.3.1.min.js
  10. // ==/UserScript==
  11.  
  12. window.onload = function() {
  13. 'use strict';
  14. $('a[href*="arxiv.org"]').each(function() {
  15. console.log('Contains arxiv href');
  16. // console.log(this.href);
  17. if ( this.href.match(/http[s]?:\/\/arxiv.org\/(pdf|abs)/) ) {
  18. console.log("match")
  19. this.href = this.href.replace(/http[s]?:\/\/arxiv.org\/(pdf|abs)/, 'http://cn.arxiv.org/pdf');
  20. }
  21. if (this.href.match(/http?:\/\/cn.arxiv.org\/pdf/) && !this.href.match(/\.pdf/) )
  22. {
  23. this.href = this.href + '.pdf';
  24. }
  25. });
  26.  
  27. //handle the pdf link in arxiv.org/abs page
  28. if (/arxiv\.org/i.test(window.location.href)){
  29. var ele = $(".full-text ul li a")[0];
  30. ele.href = ele.href.replace('https://arxiv.org/', 'http://cn.arxiv.org/')+'.pdf';
  31. }
  32. }