Greasy Fork is available in English.

Better Luogu Problem Searcher

洛谷题目跳转器优化

2019/05/06のページです。最新版はこちら。

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         Better Luogu Problem Searcher
// @namespace    n/a
// @version      0.0.1
// @description  洛谷题目跳转器优化
// @author       iotang
// @match        https://www.luogu.org
// @match        https://www.luogu.org/
// @match        https://www.luogu.org/#feed
// @match        https://www.luogu.org/#feed/
// @match        http://www.luogu.org
// @match        http://www.luogu.org/
// @match        http://www.luogu.org/#feed
// @match        http://www.luogu.org/#feed/
// @grant        none
// ==/UserScript==

(function()
{
    'use strict';

    function jumpfn()
    {
        var target = document.getElementsByClassName("am-form-field")[0].value;
        if(target === "")return;

        var go = "https://www.luogu.org/fe/problem/list?keyword=" + target + "&content=true";
        location.href = go;
    }

    function searchfn()
    {
        var target = document.getElementsByClassName("am-form-field")[0].value;
        if(target === "")return;

        var targetu = target.toUpperCase();
        var go = "";

        if(target.match(/^[1-9][0-9][0-9][0-9]+$/) == target)
        {
            go = "https://www.luogu.org/fe/problem/P" + target;
        }
        else if(targetu.match(/^[0-9]+[A-Z][0-9]?$/) == targetu)
        {
            go = "https://www.luogu.org/fe/problem/CF" + targetu;
        }
        else if(targetu.match(/^(?:P|CF|SP|AT|UVA)[0-9]+[A-Z]?[0-9]?$/) == targetu)
        {
            go = "https://www.luogu.org/fe/problem/" + targetu;
        }
        else
        {
            go = "https://www.luogu.org/fe/problem/list?keyword=" + target + "&content=true";
        }

        location.href = go;
    }

    var locations =
        document.getElementsByClassName("lg-index-content")[0]
    .getElementsByClassName("lg-article lg-index-stat")[0]
    .getElementsByClassName("am-btn am-btn-primary am-btn-sm")[0]
    .parentNode;

    var button = document.createElement("button");
    button.className = "am-btn am-btn-success am-btn-sm";
    button.name = "gotosearch";
    button.id = "gotosearch";
    button.innerHTML = "搜索";
    button.onclick = function(){jumpfn();}

    locations.appendChild(button);

    document.getElementsByClassName("am-form-field")[0].placeholder = "输入题号或题目名,按回车确认";
    document.getElementsByClassName("am-form-field")[0].onkeyup = function(event){if(event.keyCode === 13){searchfn();}}

    document.getElementsByClassName("lg-article lg-index-stat")[0].getElementsByTagName("h2")[0].innerHTML = "问题搜索";
})();