GDFZOJ返回列表

增加返回列表按钮

As of 2023-07-11. See the latest version.

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

(function() {
    'use strict';
    const s=document.querySelectorAll('a');
    if(window.location.href.match('exercise')||window.location.href.match('problems$')){
        for(let i=0;i<s.length;i++)
        {
            if(s[i].href.match('problem/')){
                //console.log(s[i]);
                GM_setValue(s[i].href,window.location.href);
            }
        }
    }
    //console.log(window.location.href);
    if(window.location.href.match('problem/')&&(!window.location.href.match('contest/'))){
        console.log(GM_getValue(window.location.href));
        var x;
        const t=document.querySelectorAll('ul');
        for(let i=0;i<t.length;i++)
        {
            if(t[i].role=='tablist'){
                x=t[i];
            }
        }
        //console.log(x);
        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=GM_getValue(window.location.href);
        add.insertAdjacentElement("beforeend",y);
        x.insertAdjacentElement("beforeend",add);
    }
    // Your code here...
})();