Greasy Fork

Greasy Fork is available in English.

多分相关页面优化

多分相关页面优化改进

当前为 2021-08-04 提交的版本,查看 最新版本

// ==UserScript==
// @name         多分相关页面优化
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  多分相关页面优化改进
// @author       ds
// @match      www.moofen.net/*
// @match      http://47.92.71.131/*
// @match      www.1010jiajiao.com/*
// ==/UserScript==

//将同类别功能的代码进行了分类
var url = document.location.toString();
var m = null;
var img = null;
var i;
//---------类别零:多分相关页面优化---------

//多分新题库后台,试题录题结构管理
//http://47.92.71.131/tkn/pages/question/paper_item.html
if ((m = url.match(/^(https?:\/\/47\.92\.71\.131\/)(tkn\/pages\/question\/paper_item\.html)(.*)$/i))) {
    if (document.querySelectorAll('a.btn.btn-primary.pl-4.pr-4')[0].innerText = "录题结构管理") {
        //加载页面后自动增大CheckBox按钮尺寸,需要加上延迟才能生效
        setTimeout(function () {
            for (i = 0; i < document.querySelectorAll('input').length; i++) {
                if (document.querySelectorAll('input')[i].type == "checkbox") {
                    document.querySelectorAll('input')[i].style.zoom = 2;
                }
            }
        }, 500);
        //原先单独做了一个按钮增大
        /*
        document.querySelectorAll('button.btn.btn-outline-danger.btn-sm.ml-2')[0].insertAdjacentHTML('afterEnd', '<button type="button" class="btn btn-outline-primary btn-sm ml-5" id="zoom_all_btn">CheckBox_Zoom</button>');
        document.querySelectorAll('#zoom_all_btn')[0].onclick = CheckBox_Zoom;
        function CheckBox_Zoom() {
            //页面有很多input的type不是checkBox,而是hidden隐藏的
            for (i = 0; i < document.querySelectorAll('input').length; i++) {
                if (document.querySelectorAll('input')[i].type == "checkbox") {
                    document.querySelectorAll('input')[i].style.zoom = 2;
                }
            }
        }
        */
        var sjmc, km, nj, glth, glth_start, glth_end, tmsl, nbth, nbth_start, nbth_end;
        //试卷名称,科目,年级,关联题号,关联题号起始,关联题号结束,题目数量,内部题号,内部题号起始,内部题号结束
        sjmc = document.querySelectorAll('h1#paperTitle.mb-4.text-center')[0].innerText;
        nj = sjmc.substr(sjmc.indexOf("年级") - 1, 1);
        switch (nj) {
            case "七":
                nj = 7;
                break;
            case "八":
                nj = 8;
                break;
            case "九":
                nj = 9;
        }
        km = sjmc.slice(-2);
        console.log(nj + km);
        document.querySelectorAll('button.btn.btn-outline-danger.btn-sm.ml-2')[0].insertAdjacentHTML('afterEnd', '<button type="button" class="btn btn-outline-danger btn-sm ml-2" id="auto_link">【' + nj + km + '】自动关联</button>');
        document.querySelectorAll('#auto_link')[0].onclick = auto_link;
        document.querySelectorAll('#auto_link')[0].insertAdjacentHTML('afterEnd', '<input id="auto_link_content" type="text" class="form-control form-control-sm" placeholder="请输入综合题关联题号" required="">');
        if (km == "英语" && nj == "8") {
            document.querySelectorAll('#auto_link_content')[0].value = "79-83";
        }
        //17,关联17-1,17-2……,17-19,关联17-1,17-2,18,19
        //console.log(glth);
        document.querySelectorAll('#auto_link_content')[0].value = "8-12";
        function auto_link() {
            tmsl = document.querySelectorAll('tbody')[0].children.length;
            glth = document.querySelectorAll('#auto_link_content')[0].value;
            if (glth != "") {
                if (glth.indexOf("-") != -1) {
                    glth_start = parseInt(glth.slice(0, glth.indexOf("-")));
                    glth_end = parseInt(glth.slice(glth.indexOf("-") + 1));
                    for (i = 0; i < tmsl; i++) {
                        nbth = document.querySelectorAll('tbody')[0].children[i].children[1].innerText;
                        if (nbth.indexOf("-") != -1) {
                            nbth_start = parseInt(nbth.slice(0, nbth.indexOf("-")));
                            nbth_end = parseInt(nbth.slice(nbth.indexOf("-") + 1));
                            nbth = nbth_start;
                        }
                        if (nbth <= glth_end && nbth >= glth_start) {
                            document.querySelectorAll('tbody')[0].children[i].children[0].children[0].checked = true;
                        }
                    }
                } else {
                    for (i = 0; i < tmsl; i++) {
                        nbth = document.querySelectorAll('tbody')[0].children[i].children[1].innerText;
                        if (nbth.indexOf("-") != -1) {
                            nbth_start = parseInt(nbth.slice(0, nbth.indexOf("-")));
                            nbth_end = parseInt(nbth.slice(nbth.indexOf("-") + 1));
                            if (nbth_start == glth) {
                                document.querySelectorAll('tbody')[0].children[i].children[0].children[0].checked = true;
                            }
                        }
                    }
                }
            }
            //点击综合题关联按钮并输入关联题号
            setTimeout(function () {
                document.querySelectorAll('button.btn.btn-outline-primary.btn-sm.ml-5')[0].onclick();
            }, 100);
            setTimeout(function () {
                document.querySelectorAll('input.form-control.form-control-sm')[1].value = glth;
            }, 100);
            setTimeout(function () {
                document.querySelectorAll('div.dui-dialog-footer')[0].children[0].onclick();
            }, 100);
            /*
            //综合题关联,input的第0个是隐藏的,第1个是全选,第2个是第一题的,第17个是第二题的,第2+15n是第n题的
            for (i = 0; i < document.querySelectorAll('input').length; i++) {
                nbth=document.querySelectorAll('input')[2 + 15 * i].value;
                document.querySelectorAll('input')[2 + 15 * i].checked = true;
            }
            */
        }
    }
}

//多分新题库后台,试题编辑界面
//http://47.92.71.131/tkn/pages/question/question_content.html?errorCorrectionId=19005361
else if ((m = url.match(/^(https?:\/\/47\.92\.71\.131\/)(tkn\/pages\/question\/question_content\.html)(.*)$/i))) {
        setTimeout(function () {
            var stlb, xk, jmtx;
            //试题类别、学科、卷面题型
            stlb=document.querySelectorAll('a.nav-link.active')[1].id;
            stlb=stlb.slice(0, stlb.indexOf("-"));
            xk=document.querySelectorAll('select#subject')[0].value;
            jmtx=document.querySelectorAll('select#category')[0].value;
            if (xk==2 && stlb=="Q" && jmtx==""){document.querySelectorAll('select#category')[0].value=204;}
            if (xk==2 && stlb=="C"){document.querySelectorAll('select#category')[0].value=201;}
            //document.querySelectorAll('select#category')[0].children[4].selected=true;
        }, 500);
}

//多分题库后台,试题录题结构管理
//http://www.moofen.net/tk/pages/paper/paperItem_search.html?paperCode=
else if ((m = url.match(/^(https?:\/\/www\.moofen\.net\/)(tk\/pages\/paper\/paperItem_search\.html)(.*)$/i))) {
    //添加让左侧的选择框按钮变大的按钮
    document.querySelectorAll('button.btn.btn-danger.btn-sm')[0].insertAdjacentHTML('afterEnd', '<button type="button" class="btn btn-success btn-sm" id="zoom_all_btn">CheckBox_Zoom</button>');
    function CheckBox_Zoom() {
        //页面前有2个input不是CheckBox的type
        for (i = 2; i < document.querySelectorAll('input').length; i++) {
            document.querySelectorAll('input')[i].style.zoom = 2;
        }
        //点击卷面题号的单元格,勾选左侧对应的选择框按钮,未完成
        for (i = 0; i < document.querySelectorAll('td').length / 6; i++) {
            document.querySelectorAll('td')[i * 6 + 3].insertAdjacentHTML('afterEnd', '')
        }
    }
    document.querySelectorAll('button#zoom_all_btn.btn.btn-success.btn-sm')[0].onclick = CheckBox_Zoom;
}
//新版教师端学情分析系统
//http://www.moofen.net/school/web/pages/index.html
else if ((m = url.match(/^(https?:\/\/www\.moofen\.net\/)(school\/web\/pages\/index\.html)$/i))) {
    //教研组长试卷分析界面,下载试卷难度区分度分布表,未完成
    //获取考试与科目
    var ksmc, jsmc;
    document.querySelectorAll('i.iconfont.icon-home')[0].insertAdjacentHTML('beforeBegin', '<button id="ksxm">考试名称:</button><span id="ksmc"></span>');
    document.querySelectorAll('button#ksxm')[0].onclick = ksxm_show;
    function ksxm_show() {
        ksmc = document.querySelectorAll('select#questExam.form-control.form-control-sm')[0].innerText;
        jsmc = document.querySelectorAll('span#currRoleName.curr-role')[0].innerText;
        document.querySelectorAll('span#ksmc')[0].innerText = ksmc + "_" + jsmc;
    }
}
//试卷预览界面,点击刷新按钮,自动勾选显示所有信息,未完成
//http://www.moofen.net/tk/pages/paper/paper_preview.html
// @require        http://www.moofen.net/tk/assets/js/paper/paper_preview_single.js
// @require      http://cdn.staticfile.org/jquery/3.5.1/jquery.min.js
/* globals jQuery, $, waitForKeyElements */
else if ((m = url.match(/^(https?:\/\/www\.moofen\.net\/)(tk\/pages\/paper\/paper_preview\.html.*)$/i))) {
    //位置调整,靠右以便于左右分屏对照
    document.querySelectorAll('div.head-nav')[0].insertAdjacentHTML('afterEnd', '                         <button id="pos_adj" class="btn btn-success btn-sm">位置调整</a>');
    document.querySelectorAll('#pos_adj')[0].onclick = pos_adj;
    function pos_adj() {
        //点击刷新按钮
        document.querySelectorAll('button#reloadPaper')[0].click();
         setTimeout(function(){
             var sjbh = document.querySelectorAll('div.card.mb-3')[0].id
             //document.querySelectorAll('input#paper_check_01')[0].Checked=1
             //document.querySelectorAll('div.height-auto.col-xl-10.col-md-8.col-sm-8')[0].class="height-auto.col-xl-6.col-md-8.col-sm-8"
             //document.querySelectorAll('div#paperContent.question-check')[0].style.right="0px"
             document.querySelectorAll('div#paperSingle.content')[0].style.position = "relative";
             document.querySelectorAll('div#paperSingle.content')[0].style.left = "623px";
             document.querySelectorAll('div#paperSingle.content')[0].style.width = "920px";
             document.querySelectorAll('#pos_adj')[0].style.left = "623px";
             //显示所有基础信息 显示所有分析 显示所有答案 显示所有点评
             for (i = 0; i < document.querySelectorAll('div.show-key').length; i = i + 2) {
                 document.querySelectorAll('div.show-key')[i].style.display = "block";
             }
         },1000);
    }
}
//编辑试题界面
//http://www.moofen.net/tk/pages/qb/question_edit.html?questionId=1615948988451
else if ((m = url.match(/^(https?:\/\/www\.moofen\.net\/)(tk\/pages\/qb\/question_edit\.html.*)$/i))) {
    //位置调整,靠右以便于左右分屏对照
    document.querySelectorAll('#typeTab')[0].lastElementChild.insertAdjacentHTML('afterEnd', '<li class="nav-item"><a class="nav-link" id="pos_adj">位置调整</a></li>');
    //document.querySelectorAll('#pos_adj')[0].onclick = pos_adj;
    //function pos_adj() {
        document.querySelectorAll('section')[0].style.position = "relative";
        document.querySelectorAll('section')[0].style.left = "500px";
        document.querySelectorAll('section')[0].style.width = "920px";
        document.querySelectorAll('#question')[0].style.width = "900px";
        document.querySelectorAll('#tabContent')[0].style.width = "900px";
    //}
}
//同步试卷界面,点击复制试卷编号,未完成
//http://www.moofen.net/tk/pages/sync/paper_sync.html
else if ((m = url.match(/^(https?:\/\/www\.moofen\.net\/)(tk\/pages\/sync\/paper_sync\.html.*)$/i))) {
    document.querySelectorAll('input#oldPaperId.form-control')[0].insertAdjacentHTML('beforeBegin', '<div  id="btn1" class="btn btn-success">EhanceCOPY</div>');
    var btn1 = document.getElementById('btn1');
    function EhanceCOPY() {
        var matchs = document.getElementsByClassName('table-item');
        var clipBoardContent = "";
        for (var j = 0; j < matchs.length; j++) {
            var content_before = matchs[j].children[2].innerHTML
            var content = content_before.match(/^(<i.+\/i>)(.+)$/i);
            //var content_after = '<input type="button"> value="' + content_before + '" index="' + j + '" onclick="javascript:(function copyToClipBoard(){var clipBoardContent="";clipBoardContent+=' + content_before + ';window.clipboardData.setData("Text",clipBoardContent);})"';
            var content_after = '<button onclick="javascript:(function (){window.clipboardData.setData("Text",' + content_before + ');})">' + content_before + ' </button>';
            matchs[j].children[2].innerHTML = content_after;
        }
    }
    btn1.onclick = EhanceCOPY;
}
//http://www.moofen.net/cube/pages/cube.html
else if ((m = url.match(/^(https?:\/\/www\.moofen\.net\/)(cube\/pages\/cube\.html)$/i))) {
    var bt_all, btsl, qtsl;
    //所有标题,标题数量,切图数量;
    bt_all = document.querySelectorAll("ul.header_nav_ul")[0];
    btsl = bt_all.childElementCount;
    bt_all.lastChild.insertAdjacentHTML('afterEnd', '<li id="img_download" style="color:orange">切图下载</li>');
    bt_all.lastChild.insertAdjacentHTML('afterEnd', '<li id="img_sort" style="color:orange">切图重排</li>');
    //bt_all.insertAfter('<li id="img_sort" style="color:orange">切图重排</li>',bt_all.lastChild)

    document.querySelectorAll('#img_download')[0].onclick = img_download;
    document.querySelectorAll('#img_sort')[0].onclick = img_sort;
    //http://www.moofen.net:80/res/res/paper/1/1001614662138141/s/切图名称.gif
    function img_download() {

    }

    function img_sort() {
        var img_all = document.querySelectorAll("ul#cutImage.cutImage_ul")[0];
        qtsl = img_all.children.length;
        var img_arr = new Array(qtsl);
        for (i = 0; i < qtsl; i++) {
            nbth = img_all.children[i].innerText.replace(".gif", "");
            nbth = nbth.replace("-", "."); //方便后续作为数组排序
            img_arr[i] = nbth;
            if (nbth.indexOf("-") != -1) {
                nbth_start = nbth.slice(0, nbth.indexOf("-"));
                nbth_end = nbth.slice(nbth.indexOf("-") + 1);
            }
        }
        img_arr.sort(function (a, b) { return a - b }); //按照数值大小排序
        for (i = 0; i < qtsl; i++) {
            img_arr[i] = img_arr[i].replace(".", "-");
            var img_url = document.querySelectorAll("img.img_pdf_view")[0].src.replace(img_all.children[0].innerText, "") + img_arr[i] + ".gif";
            img_all.lastElementChild.insertAdjacentHTML('afterEnd', img_arr[i] + '<img src="' + img_url + '" style="width:100%">');
        }
        console.log(img_arr);
        //img_all.insertBefore(img_all.children[1],img_all.children[0]) //排序方法
    }
}

//cube-知识点标注-上传试卷界面,根据上传文件名称自动选择相应选项,未完成
//http://www.moofen.net/cube/pages/cube.html
/*
else if ((m = url.match(/^(https?:\/\/www\.moofen\.net\/)(cube\/pages\/cube\.html)$/i))) {
        //document.querySelectorAll('li')[6].insertAdjacentHTML('afterEnd', '<input type="search" class="form-control" width="100" placeholder="请输入试卷名称">');
        document.querySelectorAll('li')[6].insertAdjacentHTML('afterEnd', '<button class="btn btn-primary" type="button" id="uploadPaper" onclick="MARK.onClickUploadPaper()">上传试卷</button>');
        document.querySelectorAll('li')[6].insertAdjacentHTML('afterEnd', '<div  id="btn1" class="btn btn-success">EhanceUPLOAD</div>');
        document.querySelectorAll('select#grade.form-control.form-control-sm.required')[0].value=8;
        btn1 = document.getElementById('btn1');
        function EhanceUPLOAD() {
            document.querySelectorAll('select#grade.form-control.form-control-sm.required')[0].value=8;
            var matchs = document.getElementsByClassName('table-item');
        }
        btn1.onclick = EhanceUPLOAD;
}
*/
//可弃用,uBlock插件更容易实现
//青夏教育,试题搜索结果页面去掉干扰
//http://www.1010jiajiao.com/czsx/shiti_id_7d8dda54d23f54ee9d80e1a05b5eb272
else if ((m = url.match(/^(https?:\/\/www\.1010jiajiao\.com\/)(czsx\/shiti_id_.+)$/i))) {
            document.querySelectorAll('div.sublist')[2].remove();
            document.querySelectorAll('div.ndwz')[0].remove();
            document.querySelectorAll('div#daan_recommend')[0].remove();
            document.querySelectorAll('div.xt')[0].remove();
}