Better Luogu Problem Searcher

洛谷题目跳转器优化

当前为 2019-11-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Better Luogu Problem Searcher
  3. // @namespace n/a
  4. // @version 0.0.2.7
  5. // @description 洛谷题目跳转器优化
  6. // @author iotang
  7. // @match https://www.luogu.com.cn
  8. // @match https://www.luogu.com.cn/
  9. // @match https://www.luogu.com.cn/#feed
  10. // @match https://www.luogu.com.cn/#feed/
  11. // @match http://www.luogu.com.cn
  12. // @match http://www.luogu.com.cn/
  13. // @match http://www.luogu.com.cn/#feed
  14. // @match http://www.luogu.com.cn/#feed/
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. (function()
  19. {
  20. 'use strict';
  21.  
  22. var href = "https://www.luogu.org/problem";
  23.  
  24. function jumpfn()
  25. {
  26. var target = document.getElementsByClassName("am-form-field")[0].value;
  27. if(target === "")return;
  28.  
  29. var go = href + "/list?keyword=" + target + "&content=true";
  30.  
  31. location.href = go;
  32. }
  33.  
  34. function searchfn()
  35. {
  36. var target = document.getElementsByClassName("am-form-field")[0].value;
  37. if(target === "")return;
  38.  
  39. var targetu = target.toUpperCase();
  40. var go = href;
  41.  
  42. if(target.match(/^[1-9][0-9][0-9][0-9]+$/) == target)go = go + "/P" + target;
  43. else if(targetu.match(/^[0-9]+[A-Z][0-9]?$/) == targetu)go = go + "/CF" + targetu;
  44. else if(targetu.match(/^(?:U|P|CF|SP|AT|UVA)[0-9]+[A-Z]?[0-9]?$/) == targetu)go = go + "/" + targetu;
  45. else{go = href + "/list?keyword=" + target + "&content=true";}
  46.  
  47. location.href = go;
  48. }
  49.  
  50. var locations =
  51. document.getElementsByClassName("lg-index-content")[0]
  52. .getElementsByClassName("lg-article lg-index-stat")[0]
  53. .getElementsByClassName("am-btn am-btn-primary am-btn-sm")[0]
  54. .parentNode;
  55.  
  56. var button = document.createElement("button");
  57. button.className = "am-btn am-btn-success am-btn-sm";
  58. button.name = "gotosearch";
  59. button.id = "gotosearch";
  60. button.innerHTML = "搜索";
  61. button.onclick = function(){jumpfn();};
  62.  
  63. locations.appendChild(button);
  64.  
  65. document.getElementsByClassName("am-form-field")[0].placeholder = "输入题号或题目名,按回车确认";
  66. document.getElementsByClassName("am-form-field")[0].onkeyup = function(event){if(event.keyCode === 13){searchfn();}};
  67.  
  68. document.getElementsByClassName("lg-article lg-index-stat")[0].getElementsByTagName("h2")[0].innerHTML = "问题搜索";
  69.  
  70. document.getElementsByName("gotorandom")[0].innerHTML = "随机";
  71. })();

QingJ © 2025

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