Greasy Fork

Greasy Fork is available in English.

超星网课助手(测试版)

自动挂机看尔雅MOOC,支持后台、切换窗口不暂停,视频自动切换,屏蔽视频内的题目,倍速播放、进度条拖动、快进快退

当前为 2018-09-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         超星网课助手(测试版)
// @namespace    [email protected]
// @version      0.0.23
// @description  自动挂机看尔雅MOOC,支持后台、切换窗口不暂停,视频自动切换,屏蔽视频内的题目,倍速播放、进度条拖动、快进快退
// @author       wyn665817
// @match        *://*.chaoxing.com/work/doHomeWorkNew*
// @run-at       document-end
// @grant        unsafeWindow
// @license      MIT
// ==/UserScript==

/**
 * 注意事项:
 * 1.此版本为自动答题功能独立版,仅具有自动答题功能,建议在指导下使用
 * 2.此版本为测试版,可能与正式版存在冲突,建议在指导下使用
 * 3.如果需要配合正式版使用,需要在正式版中开启other功能(针对正式版V1.6.0)
 */

// 设置修改后,需要刷新或重新打开网课页面才会生效
var setting = {
    // 5E3 == 5000,表示毫秒数
    time: 5E3 // 默认响应速度为5秒,不建议小于3秒

    // 1代表开启,0代表关闭
    ,auto: 1 // 自动提交功能,默认开启
},
$ = unsafeWindow.$,
UE = unsafeWindow.UE,
$div = $(
    '<div style="border: 2px dashed rgb(0, 85, 68); width: 310px; position: fixed; top: 0; right: 0; background-color: rgba(70, 196, 38, 0.6); overflow: auto;">' +
        '<div style="font-size: medium;">正在搜索答案...</div>' +
        '<button>' + (setting.auto ? '点击停止本次提交' : '点击开启自动提交') + '</button>' +
        '<button style="margin-left: 10px;">重新查询</button>' +
        '<button style="margin-left: 10px;">折叠面板</button>' +
        '<table border="1" style="font-size: 12px;">' +
            '<tr>' +
                '<td width="60%">题目</td>' +
                '<td width="40%">答案</td>' +
            '</tr>' +
        '</table>' +
    '</div>'
).appendTo('body'),
index = 0,
$check = $('.TiMu'),
timeId = setInterval(function() {
    if (index >= $check.length) {
        clearInterval(timeId);
        $div.children('div').text('已完成搜索');
        setInterval(submitThis, setting.time);
        return;
    }
    var $TiMu = $check.eq(index),
    question = $TiMu.find('.Zy_TItle:eq(0) > .clearfix').text().trim(),
    xhr = new XMLHttpRequest();
    xhr.open('POST', 'https://www.forestpolice.org/php/unify.php');
    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xhr.timeout = setting.time;
    xhr.onloadend = function() {
        if (xhr.status == 200) {
            var obj = JSON.parse(xhr.responseText);
            if (obj.code) {
                $div.children('table').append('<tr><td>' + question + '</td><td>' + obj.data + '</td></tr>');
                fillAnswer($TiMu, obj.data);
                index++;
            } else {
                $div.children('div').text(obj.data);
            }
        } else {
            $div.children('div').text('服务器异常,正在重试...');
        }
    };
    xhr.send('question=' + encodeURIComponent(question) + '&username=test00&password=123456');
}, setting.time);

$div.children('button').on('click', function() {
    var len = $(this).prevAll('button').length;
    if (len == 0) {
        setting.auto = 1 ^ setting.auto;
        $(this).text(setting.auto ? '点击停止本次提交' : '点击开启自动提交');
    } else if (len == 1) {
        location.reload();
    } else if (len == 2) {
        $(this).siblings('table').toggle();
    }
});

function fillAnswer($TiMu, data) {
    var $li = $TiMu.find('ul:eq(0) li'),
    arr = data.split('#');
    $li.each(function(event) {
        var $input = $(this).find('input');
        if ($input.val() == 'true') {
            (data == '正确' || data == '是') && $input.attr('checked', true);
        } else if ($input.val() == 'false') {
            (data == '错误' || data == '否') && $input.attr('checked', true);
        } else {
            var text = $(this).find('a').text().trim();
            arr.find(function(currentValue) {
                var tip = text.includes(currentValue);
                $input.attr('checked', tip);
                return tip;
            });
        }
    });
    if ($li.length == 1 && !data.includes('未找到答案')) {
        UE.getEditor($li.find('textarea').attr('name')).setContent(data);
    } else if (!$li.find('input:checked').length) {
        $li.find('input').eq(0).attr('checked', true);
    }
}

function submitThis($btn) {
    if (setting.auto && $('#validate', top.document).is(':hidden')) {
        if ($('#confirmSubWin').is(':hidden')) {
            ($btn = $('.Btn_blue_1')[0]) ? $btn.click() : $btn;
        } else {
            $btn = $('#tipContent').next().children(':first');
            var position = $btn.offset(),
            mouse = document.createEvent('MouseEvents');
            mouse.initMouseEvent('click', true, true, document.defaultView, 0, 0, 0, position.left + Math.floor(46 * Math.random() + 1), position.top + Math.floor(26 * Math.random() + 1));
            $btn[0].dispatchEvent(mouse);
        }
    }
}