Greasy Fork

来自缓存

Greasy Fork is available in English.

2021华医公需课

2021华医公需课自动听课和自动考试脚本.华医的其它课程应该可以自动听课. 将其它课程的答案保存在ANSWER_DICT变量里,可以自动考试.

当前为 2021-06-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         2021华医公需课
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  2021华医公需课自动听课和自动考试脚本.华医的其它课程应该可以自动听课. 将其它课程的答案保存在ANSWER_DICT变量里,可以自动考试.
// @author       han2ee
// @include        http://cme*huayi.com/*
// @include        https://cme*huayi.com/*
// @run-at        document-start
// @grant   GM.setValue
// @grant   GM.getValue
// @grant unsafeWindow
// ==/UserScript==


(function() {
    'use strict';
    const getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = window.location.search.substring(1),
            sURLVariables = sPageURL.split('&'),
            sParameterName,
            i;

        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');

            if (sParameterName[0] === sParam) {
                return typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
            }
        }
        return false;
    };

    const findFirstLesson = function(studyImgArr) {
        if (studyImgArr) {
            for (let i = 0; i < studyImgArr.length; i++) {
                if (studyImgArr[i].src.endsWith("anniu_01a.gif")) {
                    return i;
                }
            }
        }
        return -1;
    }
    const nextLesson = async function(cwid) {
        let cid = await GM.getValue('cid');
        console.log("CID", cid);
        let hrefs = await GM.getValue(cid);
        for (let i = 0; i < hrefs.length - 1; i++) {
            if (hrefs[i].indexOf(cwid) != -1) {
                window.location = hrefs[i + 1];
            }
        }
    }

    const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

    const ANSWER_DICT = {
        '4d8f0f21-a500-4dea-971d-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'],
        'f1e74f27-c0c9-4db0-a710-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'],
        '931ae318-bf2e-4ccd-8190-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'],
        '6719c552-bf16-4111-acb5-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'],
        'eb0ecb02-b6dd-4d87-95f8-ad2d00e8f196' : ['1bbf2da1-f5ca-4dcb-ba6b-ad2e00bb3422', '5cdc4638-9d87-4c21-9edd-ad2e00bb3422'],
        '2c2ad625-6c97-49b9-b763-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'],
        'ce168b7f-1a36-40ba-ae81-ad2d00ff58e3' : ['4c7a52ac-ccf4-4c10-8c15-ad2e00be0a13', 'a8fb198d-ec7a-4777-bea6-ad2e00be0a13'],
        'baee2ed1-140d-4ecc-aba4-ad2d00ff58e3' : ['gvQuestion_rbl_0_3_0'],
        'feed2105-bb4b-42b3-ba5b-ad2d00ff58e3' : ['a00768d8-8c06-4411-932d-ad2e00bdbf42', '181c8e7a-28d7-4ad6-8395-ad2e00bdbf42'],
        '321a7b59-3c4d-4717-a7c9-ad2d00ff58e3' : ['3e4854ef-8e1a-4383-aca6-ad2e00bdeaab', 'ac0bc131-3bbc-42ec-b56a-ad2e00bdeaab'],
        '019ea052-3cd5-4307-b593-ad2d00ff58e3' : ['gvQuestion_rbl_0_0_0'],
        '3ce608c2-aeaa-412e-a7c2-ad2d00fc1ef8' : ['25bd1a55-851e-4dd8-81f6-ad2e00bdc848', '5a36cd31-b353-4c17-a41d-ad2e00bdc848', '20d59ec3-03f5-4681-995e-ad2e00bdc848'],
        '075a9616-0449-4945-918b-ad2d00fc1ef8' : ['9244ead2-2f04-4039-bdfc-ad2e00be211c', 'c1f63dcb-67bd-43ce-a7d6-ad2e00be211c'],
        '7b861782-2e3f-4bbe-a292-ad2d00fc1ef8' : ['gvQuestion_rbl_0_3_0'],
        '7f79db95-cacc-4e28-9208-ad2d00fc0c6b' : ['gvQuestion_rbl_0_1_0'],
        'c4d17528-de5a-4e6e-9565-ad2d00fc0c6b' : ['gvQuestion_rbl_0_3_0'],
        'cd1e7419-e5fb-49ee-b169-ad2d00fc0c6b' : ['191ee0f8-b7d9-4cac-8b47-ad2e00bf002a', 'ee9aaeeb-6697-442f-8a13-ad2e00bf002a'],
        'fea3522a-2625-45d6-b8c1-ad2d01229e06' : ['gvQuestion_rbl_0_0_0'],
        '3834591e-f193-4f49-8166-ad2d01229e06' : ['gvQuestion_rbl_0_0_0'],
        'ecabad40-9a14-4bb5-a0ee-ad2d01226753' : ['gvQuestion_rbl_0_0_0'],
        '7d2b66db-b46d-4ca7-a836-ad2d01229e06' : ['gvQuestion_rbl_0_1_0'],
        '3d3cc7d7-6f63-4f25-a9d8-ad2d01229e06' : ['gvQuestion_rbl_0_0_0'],
        '091759ca-1590-423c-9059-ad2d01229e06' : ['gvQuestion_rbl_0_0_0'],
        '9c25c406-fb9e-4f68-9f57-ad2d01229e06' : ['32bf0ffd-5fd7-4017-813b-ad2e00bb9efc', '6a3425da-c8c3-4cb6-94ec-ad2e00bb9efc'],
        'd57589d2-5760-41c5-9c60-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'],
        '1b998761-153a-4322-9d79-ad2d010257b7' : ['gvQuestion_rbl_0_1_0'],
        'b8cf1e4f-45d9-479c-947a-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'],
        '69546b9f-de6e-4d00-8c12-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'],
        '5c82a9ac-840b-48f5-8c1a-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'],
        '8baab50d-5f4e-4d96-a8a9-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'],
        '174ca960-ea0e-4d12-a76b-ad2d010257b7' : ['7b305eb5-069d-4401-b1ca-ad2e00bbb251', '976b752e-9120-4c5d-99b8-ad2e00bbb251'],
        '76efd366-2b6d-4f69-9e96-ad2d00e8fd5e' : ['gvQuestion_rbl_0_0_0'],
        'b13165db-3c4b-454e-a0c9-ad2d00fc0044' : ['gvQuestion_rbl_0_0_0'],
    };

    // intercept alert window
    if (getUrlParameter('cwid') || getUrlParameter('cid')) {
        var alrtScope;
        if (typeof unsafeWindow === "undefined") {
            alrtScope = window;
        } else {
            alrtScope = unsafeWindow;
        }

        alrtScope.alert = function (str) {
            console.log ("Greasemonkey intercepted alert: ", str);
        };
    }
    if (window.top !== window.self) {
        return;
    }
    // 单个课程页面
    if (window.location.pathname == '/course_ware/course_ware_polyv.aspx') {
        // 拦截first,不让加载视频中间的问题
        let inter = setInterval(function() {
            try {
                if (first) {
                    first = false;
                    console.log("FIRST:", first);
                    setInterval(inter);
                }
            } catch (err) {
                console.log(err);
            }
        }, 100);

        setInterval(async function() {
            if ($(".inputstyle2")[0]) { // finish lesson
                let cwid = getUrlParameter('cwid');
                if (ANSWER_DICT[cwid]) {
                    await wait(2000); // 等待2秒,以防考试状态更新到服务器
                    window.location = $(".inputstyle2")[0].href; // 跳到考试
                } else { // jump to next
                    await nextLesson(cwid);
                }
            }
        }, 3000);
    }

    // 考试页面
    if (window.location.pathname == '/pages/exam.aspx') {
        setInterval(async function() {
            let cwid = getUrlParameter('cwid');
            console.log("CWID:", cwid);
            let answer = ANSWER_DICT[cwid];
            if (answer) {
                for (let item of answer) {
                    if (item.startsWith('gvQuestion')){
                        $('#' + item).click();
                    } else {
                        $(`[value=${item}]`).click();
                    }
                }
                $('#btn_submit').click();

            }
        }, 3000);
    }

    // 考试结果页面
    if (window.location.pathname == '/pages/exam_result.aspx') {
        setInterval(async function() {
            let cwid = getUrlParameter('cwid');
            await nextLesson(cwid);
        }, 3000);
    }
    // 目录页面
    if (window.location.pathname == '/pages/course.aspx') {
        setInterval(async function() {
            // console.log("relocation: ", $(".course h3 a")[toStudyIndex].href);
            let hrefs = $(".course h3 a:first-child");
            let vals = [];
            for (let i = 0; i < hrefs.length; i++) {
                // if (hrefs[i].children[0].src.endsWith("anniu_01a.gif")) {
                vals.push(hrefs[i].href);
                // }
            }
            // console.log(vals);
            await GM.setValue(cid, vals);
            await GM.setValue('cid', cid);
        }, 3000);
    }
})();