分类 挂机教程 下的文章

江西2023(2023jxqy.yanxiu.com)

网址:2023jxqy.yanxiu.com

脚本功能:解决点我继续计时

// ==UserScript==
// @name         江西2023(2023jxqy.yanxiu.com)
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  江西省2022-2023学年度初中“互联网+教师专业发展”全员培训,解决点我继续计时
// @author       You
// @match        http://i.yanxiu.com/uft/course/courseview.vm?trainingid=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=yanxiu.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    window.sleep = function(ms){
        return new Promise(resolve => setTimeout(resolve, ms || 1000))
    };

    // 延时10秒后加载功能
    (async () => {
        await sleep(10*1000);
        console.info("脚本开始加载运行...");
        setInterval("$('.clock-tip').click()",10000);
    })();
})();

2021-2022学年度江西省中小学(幼儿园)“互联网+教师专业发展”全员培训项目

项目首页:https://pn202236005.stu.teacher.com.cn/
脚本功能:自动开始未完成课程,文档类课程停留5分钟切换,最后一课的不再跳转。

// ==UserScript==
// @name         2021-2022江西继续教育
// @namespace    http://herokay.cn/
// @version      0.2
// @description   2021-2022江西继续教育
// @author       herokay
// @match        https://pn202236005.stu.teacher.com.cn/course/intoSelectCourseVideo*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    window.sleep = function(ms){
        return new Promise(resolve => setTimeout(resolve, ms || 1000))
    };
    // 延时3秒后进入未学课程
    (async () => {
        await sleep(3000);
        if($(".cid_"+courseCataId ).hasClass("icon_1"))
        {
            $("li.ovd").each(function()
            {
                // icon_1代表已学 icon_3代表未学
                if($(this).children("em").hasClass("icon_3")!=false)
                {
                    console.info($(this).children("a").attr("href"));
                    window.location.href=$(this).children("a").attr("href");
                    return false;
                };
            });
        }
        else
        {
            player.play();
        }
    })();

    var timer1=self.setInterval("myScript()",15000);
    var timer2=self.setInterval("countss=0",1000*9*60);
    var t=0;
    window.myScript=function()
    {
        //course-type-doc pdf文档 course-type-video视频
        if($("div.course-type-con>div").attr("class")=="course-type-doc")
        {
            t++;
            //大约5分钟结束阅读
            console.info(Date().toString()+t.toString()+"\t时间未到,跳过!");
            if(t==40)
            {
                $("li.ovd").each(function()
                                 {
                    // icon_1代表已学 icon_3代表未学
                    if($(this).children("em").hasClass("icon_1")!=false)
                    {
                        console.info($(this).children("a").attr("href"));
                        window.location.href=$(this).children("a").attr("href");
                        return false;
                    };
                });
            }
            return true;
        }
        //课程学习完
        if(player.getPosition()>=player.getDuration())
        {
            window.clearInterval(timer1)
            $(".layui-layer-btn0")[0].click();
            $("li.ovd").each(function()
                             {
                // icon_1代表已学 icon_3代表未学
                if($(this).children("em").hasClass("icon_3")!=false)
                {
                    console.info($(this).children("a").attr("href"));
                    window.location.href=$(this).children("a").attr("href");
                    return false;
                };
            });
        }
        else
        {
            console.info(Date().toString()+"\t还未学习完成,跳过!");
        }
    };
})();

脚本下载:tampermonkey_scripts.zip

Tampermonkey挂机常用代码片段

跳转

 window.location.href = "http://www.herokay.com/";

延时执行

为什么不用setTimeout??自行体会

    window.sleep = function(ms){
        return new Promise(resolve => setTimeout(resolve, ms || 1000))
    };
    // 延时3秒后进入未学课程
    (async () => {
        await sleep(3000);
        //执行后执行代码
    })();

遍历元素

 $("li.ovd").each(function()
{
    //执行代码
});

点击元素

$(el).trigger("click");
$("#img_right")[0].click();

使用本地js

// @require      file:///C:/js/jquery.js

屏蔽alert弹窗

unsafeWindow.alert=function(msg) {console.info(msg);};
window.alert=function(msg){console.info(msg);};

失去焦点暂停

window.onblur=null;

移除事件

下面代码仅限控制台使用,因为getEventListeners属于Devtool API,js无法直接使用

getEventListeners(document).visibilitychange.forEach(fn => document.removeEventListener("visibilitychange",fn.listener));

下面代码通用,在tampermonkey中加入run-at document-start

let oldadd=EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener=function (...args)
{
    if(args[0] == "visibilitychange")
    {
        console.info("拦截成功");
    }
    else
    {
        oldadd.call(this,...args);
    }
}