Luogu Problem Jumper

双击题号,自动跳转

目前为 2019-08-19 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Luogu Problem Jumper
  3. // @version 1.4.1
  4. // @description 双击题号,自动跳转
  5. // @author Anguei, ouuan, abc1763613206
  6. // @match https://www.luogu.org/*
  7. // @match https://*.blog.luogu.org/*
  8. // @grant none
  9. // @namespace Anguei
  10. // ==/UserScript==
  11.  
  12. function isProblemId(text) {
  13. if (text.match(/AT[0-9]{1,4}/) == text) return true;
  14. if (text.match(/CF[0-9]{1,4}[A-Z][0-9]{0,1}/) == text) return true;
  15. if (text.match(/SP[0-9]{1,5}/) == text) return true;
  16. if (text.match(/P[0-9]{4}/) == text) return true;
  17. if (text.match(/UVA[0-9]{1,5}/) == text) return true;
  18. if (text.match(/U[0-9]{1,6}/) == text) return true;
  19. if (text.match(/T[0-9]{1,6}/) == text) return true;
  20. return false;
  21. }
  22.  
  23. function jump() {
  24. var selection = window.getSelection();
  25. var selected = selection.toString().replace(' ', '').toUpperCase();
  26. var url;
  27.  
  28. if (event.ctrlKey) {
  29. var myBlog = document.querySelectorAll('.ops>a[href*=blog]')[0];
  30. url = myBlog.href + 'solution-';
  31. } else {
  32. url = 'https://www.luogu.org/problem/';
  33. }
  34.  
  35. if (isProblemId(selected)) {
  36. window.open(url + selected);
  37. }
  38. }
  39.  
  40. function jumpMobile() {
  41. var selection = window.getSelection();
  42. var selected = selection.toString().replace(' ', '').toUpperCase();
  43. var url = window.location.href;
  44.  
  45. if (isProblemId(selected)) {
  46. if (url.match(/message/) == undefined) {
  47. window.open('https://www.luogu.org/problem/' + selected);
  48. } else {
  49. window.open(
  50. selection.anchorNode.data.match(/评论了您的博客/) !=
  51. undefined ?
  52. 'https://' + url.match(/uid=([0-9]+)/)[1] +
  53. '.blog.luogu.org/solution-' + selected :
  54. 'https://www.luogu.org/problem/' + selected);
  55. }
  56. }
  57. }
  58.  
  59. function checkMobile() {
  60. var ua = navigator.userAgent;
  61. return window.screen.width / window.screen.height < 0.6 ||
  62. ua.indexOf('Android') > -1;
  63. }
  64.  
  65. if (checkMobile()) {
  66. document.addEventListener('selectionchange', jumpMobile);
  67. } else {
  68. document.ondblclick = jump;
  69. }

QingJ © 2025

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