├── .gitignore ├── README.md ├── LICENSE └── jump.js /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | temp.* 3 | .vscode/settings.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Luogu-Problem-Jumper 2 | 3 | ## 简介 4 | 如果别人只给你发了个题号,可是没有超链接应该怎么办? 5 | 6 | 通过双击题号的办法打开题目! 7 | 8 | 另外,按住 Ctrl 的同时双击题号,可以打开自己的题解。适用于收到他人评论了自己题解的私信等情景。(注:必须是以“博客地址/solution-题号”为 url 提交的题解) 9 | 10 | 若在安卓手机上使用该脚本,长按可代替双击,在与洛谷官方账号私信界面长按打开题解,其它界面长按打开题目。 11 | 12 | 使用效果如图(是 1.5M 的动图,可能加载较慢): 13 | ![img](https://s2.ax1x.com/2019/08/18/mlmBWQ.gif) 14 | 15 | ## 安装方法 16 | 17 | 请**不要**使用 GitHub 的 `Clone or download` 按钮安装脚本! 18 | 19 | **注意:这是一个用户脚本(userscript),在使用之前,请确保您的浏览器安装了 Tampermonkey 插件**: 20 | 21 | - [Chrome 插件下载](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo) 22 | - [国内 Chrome 插件下载](https://www.chromefor.com/tampermonkey-beta_v4-9-5960/) 23 | - [Firefox 插件下载](https://addons.mozilla.org/zh-CN/firefox/addon/tampermonkey/) 24 | 25 | 确保您的浏览器安装 Tampermonkey 插件后,请单击[这里](https://greasyfork.org/zh-CN/scripts/388947-luogu-problem-jumper)安装脚本。 26 | 27 | ## 洛谷对应讨论贴 28 | 29 | https://www.luogu.org/discuss/show/137360 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Anguei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /jump.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Luogu Problem Jumper 3 | // @version 2.0 4 | // @description 双击题号,自动跳转 5 | // @author Anguei, ouuan, abc1763613206 6 | // @match https://www.luogu.com.cn/* 7 | // @match https://*.blog.luogu.com.cn/* 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.com.cn/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 | var parent = selection.anchorNode.parentNode; 47 | if (parent.className == 'am-comment-bd' && 48 | parent.parentNode.innerHTML.match(/href="\/space\/show\?uid=3"/) != undefined) { 49 | window.open('https://' + url.match(/uid=([0-9]+)/)[1] + '.blog.luogu.com.cn/solution-' + selected); 50 | } else { 51 | window.open('https://www.luogu.com.cn/problem/' + selected); 52 | } 53 | } 54 | } 55 | 56 | function checkMobile() { 57 | var ua = navigator.userAgent; 58 | return window.screen.width / window.screen.height < 0.6 || 59 | ua.indexOf('Android') > -1; 60 | } 61 | 62 | if (checkMobile()) { 63 | document.addEventListener('selectionchange', jumpMobile); 64 | } else { 65 | document.ondblclick = jump; 66 | } --------------------------------------------------------------------------------