Greasy Fork is available in English.

quizii组卷查重工具——修改后的跳转页面

try to take over the world!

// ==UserScript==
// @name         quizii组卷查重工具——修改后的跳转页面
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @description  try to take over the world!
// @author       JinJunwei
// @match        http://121.42.229.71:8200/items/search?id=*
// @match        http://121.42.229.71:8200/item/*
// @grant       GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    if (location.href.startsWith("http://121.42.229.71:8200/items/search?id=")){
        // 需要考虑习题被聚类的情况,
        // 点击搜索按钮
        const id = location.search.substring(4);
        document.querySelector("#search_by_id_form  input[name='id']").value=id;
        document.querySelector("#search_by_id_form button").click()

        // 保存id,用于自动点击“修改习题”
        localStorage.setItem("idAndTime",JSON.stringify({id:id,time:Date.now()}));

        // 自动关闭页面
        // 首次使用会被chrome浏览器拦截,提示“是否允许弹出窗口”
        setTimeout (()=>{
            const idAndTime = JSON.parse(localStorage.getItem("idAndTime"));
            if(idAndTime.id==id && idAndTime.time==-1){close();}
        }, 1000);
        return;
    }

    // 点击修改题目
    const idAndTime = JSON.parse(localStorage.getItem("idAndTime"));
    if(!idAndTime){return;}
    if(Date.now()-idAndTime.time>2000){return;}
    if (location.href.startsWith("http://121.42.229.71:8200/item/"+idAndTime.id)){
        document.querySelector("#lr-panel div.ctrl-panel td:nth-child(3) > a").click()
        // 打开成功,关闭上一个页面
        localStorage.setItem("idAndTime",JSON.stringify({id:idAndTime.id,time:-1}));
    }

})();