强力 OI 跳题器 Super Problem Jumper

支持在所有网页跳转到题目,支持洛谷、CodeForces、AtCoder、LOJ、UOJ、UVA 等多种题库的题目

当前为 2023-02-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         强力 OI 跳题器 Super Problem Jumper
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  支持在所有网页跳转到题目,支持洛谷、CodeForces、AtCoder、LOJ、UOJ、UVA 等多种题库的题目
// @author       0
// @match        *://*/*
// ==/UserScript==
const luogu="https://www.luogu.com.cn/problem/",
      cf="https://codeforces.com/problemset/problem/",
      at="https://atcoder.jp/contests/",
      poj="http://poj.org/problem?id=",
      loj="https://https://loj.ac/p/",
      uoj="https://https://uoj.ac/problem/",
      spoj="https://www.spoj.com/problems/",
      uva="https://onlinejudge.org/",
      spojl="https://www.luogu.com.cn/remoteJudgeRedirect/spoj/",
      uval="https://www.luogu.com.cn/remoteJudgeRedirect/uva/",
      hydro="https://hydro.ac/p/",
      vijos="https://vijos.org/p/",
      dbzoj="https://darkbzoj.cc/problem/",
      ybt="http://ybt.ssoier.cn:8088/problem_show.php?pid=",
      hdu="https://acm.hdu.edu.cn/showproblem.php?pid=",
      ural="https://acm.timus.ru/problem.aspx?space=1&num=",
      sdx="https://sdxoj.tk/p/";
var prefixPattern=[
    ['P',luogu+'P',4],
    ['B',luogu+'B',4],
    ['U',luogu+'U',4],
    ['T',luogu+'T',4],
    ['LGP',luogu+'P',4],
    ['LGB',luogu+'B',4],
    ['LGU',luogu+'U',4],
    ['LGT',luogu+'T',4],
    ['LUOGU',luogu+'P',4],
    ['LUOGUP',luogu+'P',4],
    ['LUOGUB',luogu+'B',4],
    ['LUOGUU',luogu+'U',4],
    ['LUPGUT',luogu+'T',4],
    ['AT',luogu+'AT',3],
    ['LOJ',loj,1],
    ['LIBRE',loj,1],
    ['LIBREOJ',loj,1],
    ['UOJ',uoj,1],
    ['UNIVERSAL',uoj,1],
    ['UNIVERSALOJ',uoj,1],
    ['SP',spojl,1],
    //['UVA',uval,3],
    ['UVA',luogu+'UVA',3], //由于 UVA 比较卡,UVA 题号会跳转到洛谷爬取的 UVA 题目,如果需要跳到 UVA 原站只需要取消上一行的注释
    ['POJ',poj,4],
    ['BZ',dbzoj,4],
    ['BZOJ',dbzoj,4],
    ['LYDSY',dbzoj,4],
    ['LYSBZ',dbzoj,4],
    ['DBZOJ',dbzoj,4],
    ['DARKBZOJ',dbzoj,4],
    ['HYDRO',hydro+'H',4],
    ['HYDROOJ',hydro+'H',4],
    ['VIJOS',vijos,4],
    ['YBT',ybt,4],
    ['一本通',ybt,4],
    ['HDU',hdu,4],
    ['URAL',ural,4],
    ['URALOJ',ural,4],
    ['TIMUS',ural,4],
    ['TIMUSOJ',ural,4],
    ['SDX',sdx+'P',1],
    ['SDXOJ',sdx+'P',1]
];
function isNumber(str){
    for (var i in str){
        var ascii=str.codePointAt(i);
        if(ascii<48||ascii>57) return false;
    }
    return true;
}
function JumpById(id){
    var found=false;
    var probId,contestId,contestNum;
    console.log(id);
    prefixPattern.forEach(
        function(info){
            if(id.length>=info[0].length+info[2]&&id.substr(0,info[0].length)==info[0]){
                var problemUrl=id.substr(info[0].length);
                if(isNumber(problemUrl)){
                    found=true;
                    window.open(info[1]+problemUrl);
                    return;
                }
            }
        }
    );
    if(found) return;
    if(id.match(/CF[0-9]{1,}[A-Z][0-9]?/)==id){
        probId=id[id.length-1];
        contestId='';
        if(isNumber(probId)) probId=id.substr(id.length-2);
        contestId=id.substr(2,id.length-2-probId.length);
        if(isNumber(contestId)){
            return window.open(cf+contestId+'/'+probId+'/');
        }
    }
    console.log(id.match(/AT.*[A-Z1-9]/));
    if(id.match(/AT.*[A-Z1-9]/)==id){
        probId=id[id.length-1].toLowerCase();
        contestId=id.substr(2,id.length-3).toLowerCase();
        contestNum=contestId.substr(3,3);
        if(contestId.substr(0,3)=='arc'&&parseInt(contestNum)<=34&&probId.match(/[a-z]/)==probId) probId=String(probId.codePointAt(0)-96);
        return window.open(at+contestId+'/tasks/'+contestId+'_'+probId+'/');
    }
    if(id.match(/A[BRG]C[0-9]{3,}[A-Z1-9]/)==id){
        probId=id[id.length-1].toLowerCase();
        contestId=id.substr(0,id.length-1).toLowerCase();
        contestNum=contestId.substr(3,3);
        if(contestId.substr(0,3)=='arc'&&parseInt(contestNum)<=34&&probId.match(/[a-z]/)==probId) probId=String(probId.codePointAt(0)-96);
        return window.open(at+contestId+'/tasks/'+contestId+'_'+probId+'/');
    }
    if(id.match(/HYDROOJ.*/)==id) return window.open(hydro+id.substr(7));
    if(id.match(/HYDRO.*/)==id) return window.open(hydro+id.substr(5));
    if(id.match(/SDXOJ.*/)==id) return window.open(sdx+id.substr(5));
    if(id.match(/SDX.*/)==id) return window.open(sdx+id.substr(3));
    return false;
}
(function(){
    console.log(1);
    'use strict';
    document.ondblclick=function(){
        //alert('dblckicl');
        var selText=window.getSelection().toString().toUpperCase();
        while(1){
            var prevText=selText;
            selText=selText.replace(/[ _\-\t]/,'');
            if(prevText==selText) break;
        }

        JumpById(selText);
    };
   // $('body').bind('keypress',getKeyCode);
    function getKeyCode(e) {
        var evt = e || window.event;
        var keyCode = evt.keyCode || evt.which || evt.charCode;
        alert(keyCode);
    }

})();