Greasy Fork is available in English.

GitCode 重定向智能匹配版

GitCode 重定向智能匹配版1

  1. // ==UserScript==
  2. // @name GitCode 重定向智能匹配版
  3. // @description GitCode 重定向智能匹配版1
  4. // @namespace https://github.com/CandyTek/
  5. // @author CandyTek
  6. // @match *://gitcode.com/gh_mirrors/*
  7. // @version 1.0
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11. (() => {
  12. searchGitcodeMirror(0);
  13.  
  14. function searchGitcodeMirror(searchTimes) {
  15. searchTimes++;
  16. // 超过次数了,就不再尝试
  17. if(searchTimes > 30){
  18. return
  19. }
  20. const el = document.querySelector("div.repo-warning-msg > div.msg-content > a");
  21. if(el!=null && el.textContent.includes("github.com")){
  22. console.warn("正在重定向");
  23. // 去除尾部 .git 字符串
  24. window.location.href = el.textContent.replace(/\.git$/, '');
  25. }else{
  26. console.warn("未找到Github库,再次重试");
  27. setTimeout(function() {
  28. searchGitcodeMirror(searchTimes);
  29. }, 80);
  30. }
  31. }
  32. })();