GDFZOJ返回列表

增加返回列表按钮

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GDFZOJ返回列表
// @version      1.3
// @description  增加返回列表按钮
// @author       MlkMathew
// @match        *://*.gdfzoj.com*/*
// @grant        GM_setValue
// @grant        GM_getValue
// @namespace    https://greasyfork.org/users/1068192
// ==/UserScript==

(function() {
    'use strict';
    var webs=window.location.href,id='',str;
    function get_last_id(nam){
        var dig=1,res=0;
        for(let i=nam.length-1;i>=0;i--)
        {
            if(nam[i]=='/'){
                break;
            }
            res+=dig*(nam[i]-'0');
            dig*=10;
        }
        return res;
    }
    function get(pid,tim){
        if(tim>5){
            return ;
        }
        $.get("http://www.gdfzoj.com:23380/exercise/"+pid,function(res){
            console.clear();
            console.log('exercise',pid,'success to catch data');
            for(let i=0;i+6<res.length;i++)
            {
                if(res.substr(i,7)=='problem'){
                    var id='';
                    for(let j=i+8;j<res.length;j++)
                    {
                        if(res[j]=='"'){
                            break;
                        }
                        id+=res[j];
                    }
                    if(id==''){
                        continue;
                    }
                    GM_setValue(id,pid);
                }
            }
        }).fail(function () {
            get(pid,tim+1);
            console.clear();
            console.log('exercise',pid,'failed to catch data');
        });
    }
    function get_exercise(num){
        console.log('catch data number:',num);
        for(let i=1;i<=num;i++)
        {
            get(i,0);
        }
    }
    if(!webs.substr(7,webs.length-8).match('/')){
        let but=document.createElement("a");
        but.className="btn btn-primary btn";
        but.textContent="爬取题单";
        but.style.color="rgb(255,255,255)";
        document.querySelector("#UOJnavbars > ul:nth-child(2) > li.nav-item.dropdown").insertAdjacentElement("beforebegin",but);
        but.onclick=function(){
            let txt=document.createElement("a");
            txt.textContent="正在爬取数据中...";
            but.insertAdjacentElement("afterend",txt);
            setTimeout(()=>{
                get_exercise(500);
                console.clear();
                console.log("success to catch data");
                txt.remove();
            },100);
        }
        return ;
    }
    const s=document.querySelectorAll('a');
    if(webs.match('exercise')||webs.match('problems$')){
        for(let i=0;i<s.length;i++)
        {
            if(s[i].href.match('problem/')){
                GM_setValue(get_last_id(s[i].href),get_last_id(webs));
            }
        }
    }
    if(webs.match('problem/')&&(!webs.match('contest/'))){
        var x;
        const t=document.querySelectorAll('ul');
        for(let i=0;i<t.length;i++)
        {
            if(t[i].role=='tablist'){
                x=t[i];
            }
        }
        var add=document.createElement("li");
        add.className="nav-item";
        var y;
        for(let i=0;i<s.length;i++)
        {
            if(s[i].textContent==' 提交'){
                y=s[i].cloneNode(true);
            }
        }
        y.textContent=' 返回列表';
        y.dataset.toggle='';
        y.href="http://www.gdfzoj.com:23380/exercise/"+GM_getValue(get_last_id(webs)).toString();
        add.insertAdjacentElement("beforeend",y);
        x.insertAdjacentElement("beforeend",add);
    }
})();