广东省国家工作人员学法考试系统自动学习课程章节

自动阅读章节并点击下一章节,若无下一章节则回到首页

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         广东省国家工作人员学法考试系统自动学习课程章节
// @namespace    http://tampermonkey.net/
// @version      2024-10-08
// @description  自动阅读章节并点击下一章节,若无下一章节则回到首页
// @author       WFXIAN
// @match        http://xfks-study.gdsf.gov.cn/study/course/*/chapter/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bing.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //等待页面加载完成
    var sleepTimeout = 1500
    var intervalId = window.setInterval(function() {
        if (document.readyState === "complete") {
            clearInterval(intervalId);
            start()
        }
    }, 500);
    function start(){
        //获取章节id
        var u = window.location.href
        var sp = u.split('/chapter/')
        var cid = sp[1]
        sub(cid)
    }
    function sub(cid){
        console.log('提交章节id:'+cid)
        var url = "http://xfks-study.gdsf.gov.cn/study/learn/"+cid
        var httpRequest = new XMLHttpRequest()
        httpRequest.open('POST', url, true)
        httpRequest.send()

        // 响应后的回调函数
        httpRequest.onreadystatechange = function () {
            if (httpRequest.readyState == 4 && httpRequest.status == 200) {
                var json = httpRequest.responseText
                console.log('结果:'+json)
                next(json)
            }
        }
    }
    function next(res){
        if(res==='true'){
            var d = document.getElementsByClassName("next_chapter")[0]
            if(d){
                //下一章节
                console.log('下一章节')
                setTimeout(function(){
                    d.click()
                }, sleepTimeout)
            }else{
                console.log('返回首页')
                setTimeout(function(){
                    window.location.href = 'http://xfks-study.gdsf.gov.cn/study/index'
                }, sleepTimeout)
            }
        }else{
            console.log('刷新页面')
            setTimeout(function(){
                location.reload()
            }, sleepTimeout)
        }
    }
})();