Better Luogu Problem Searcher

洛谷题目跳转器优化

目前为 2019-05-06 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Better Luogu Problem Searcher
  3. // @namespace n/a
  4. // @version 0
  5. // @description 洛谷题目跳转器优化
  6. // @author iotang
  7. // @match https://www.luogu.org
  8. // @match https://www.luogu.org/
  9. // @match https://www.luogu.org/#feed
  10. // @match https://www.luogu.org/#feed/
  11. // @match http://www.luogu.org
  12. // @match http://www.luogu.org/
  13. // @match http://www.luogu.org/#feed
  14. // @match http://www.luogu.org/#feed/
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. (function()
  19. {
  20. 'use strict';
  21.  
  22. function searchfn()
  23. {
  24. var target = document.getElementsByClassName("am-form-field")[0].value;
  25. if(target === "")return;
  26.  
  27. var targetu = target.toUpperCase();
  28. var go = "";
  29.  
  30. if(target.match(/^[0-9]+$/) == target)
  31. {
  32. go = "https://www.luogu.org/fe/problem/P" + target;
  33. }
  34. else if(targetu.match(/^[0-9]+[A-Z]?[0-9]?$/) == targetu)
  35. {
  36. go = "https://www.luogu.org/fe/problem/CF" + targetu;
  37. }
  38. else if(targetu.match(/^(?:P|CF|SP|AT|UVA)[0-9]+[A-Z]?[0-9]?$/) == targetu)
  39. {
  40. go = "https://www.luogu.org/fe/problem/" + targetu;
  41. }
  42. else
  43. {
  44. go = "https://www.luogu.org/fe/problem/list?keyword=" + target;
  45. }
  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(){searchfn();}
  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. })();