MENU

自动播放传智播客课程视频

June 22, 2020 • Read: 25877 • 默认分类

这学期还弄了个1+web的什么考核, 天天让看视频做那个作业, 打游戏的时候还要盯着时长, 回来切视频
太麻烦了, 干脆写了个脚本自动帮我切换, 如果有习题就会播放语音提醒
(一点小提示, 可以配合tampermonkey的H5播放器控制来实现16倍速播放, 畅享极致丝滑, 几秒一个视频, 我也是听我朋友说的传智不计观看视频时长, 如果计视频观看时长给分数的话就GG了, 酌情使用)

使用方法:
在传智播客视频播放页按F12, 将下面的代码粘贴到控制台里面, 回车即可运行
(本项目已在GitHub开源, 如果对你有用的话, 顺路给个starrrrrr吧!)

console.log("欢迎使用传智自动播放插件, 作者博客:https://www.nothamor.cn");
    setTimeout(function() {
        let url = window.location.href;
        if(url.includes("http://stu.ityxb.com/lookPaper/busywork/")) {
            auto_search();
            console.log("检测到为测试页面, 开始自动查询题目");
        } else if(url.includes("http://stu.ityxb.com/preview/detail/")) {
            auto_play();
            console.log("检测到为视频播放页面, 开始自动播放视频");
        }
    }, 5000);

    function auto_play() {
        const CLASS_LIST = document.getElementsByClassName("point-progress-box");
        const CLASS_NAME = document.getElementsByClassName("point-text ellipsis");
        let question_text = document.getElementsByTagName("pre")[0];
        let player = document.getElementsByTagName("video")[0].id;
        let question_text_value;
        document.getElementById(player).click();
        let counter = 0;
        const TIMER = setInterval(function () {
            let percent = CLASS_LIST[counter].innerHTML.replace(/\ +/g, "").replace(/[\r\n]/g, "");
            let title_name = CLASS_NAME[counter].innerHTML.replace(/\ +/g, "").replace(/[\r\n]/g, "");
            if (percent.includes("100%") && counter == (CLASS_LIST.length - 1)) {
                clearInterval(TIMER);
                alert("当前页所有视频均已播放完成");
            } else if (percent.includes("100%")) {
                CLASS_LIST[counter + 1].click();
                player = document.getElementsByTagName("video")[0].id;
                document.getElementById(player).click();
                counter++;
            }
            if (title_name.includes("习题")) {
                question_text = document.getElementsByTagName("pre")[0];
                question_text_value = question_text.innerHTML;
                console.log(" ");
                GM_xmlhttpRequest({
                    method: 'GET',
                    url: 'http://jb.s759n.cn/chati.php?w=' + encodeURIComponent(QUESTION[counter].innerHTML),
                    headers: {
                        'Content-type': 'application/x-www-form-urlencoded',
                    },
                    data: 'q=' + encodeURIComponent(QUESTION[counter].innerHTML),
                    onload: function (response) {
                        if (response.status == 200) {
                            let obj = $.parseJSON(response.responseText.replace(/^操作数据失败!/, '')) || {};
                            obj.answer = obj.data;
                            console.log("题目:" + QUESTION[counter].innerHTML + "的答案为:" + obj.answer);
                            if (obj.code) {
                            } else {
                                console.log('服务器繁忙,正在重试...');
                            }
                        } else if (response.status == 403) {
                            console.log('请求过于频繁,建议稍后再试');
                        } else {
                            console.log('服务器异常,正在重试...');
                        }
                    }
                });
            }
        }, 1000);
    }
    function auto_search() {
        const QUESTION = document.getElementsByTagName("pre");
        let counter = 0;
        const SEARCH = setInterval(function() {
            GM_xmlhttpRequest({
                method: 'GET',
                url: 'http://jb.s759n.cn/chati.php?w=' + encodeURIComponent(QUESTION[counter].innerHTML),
                headers: {
                    'Content-type': 'application/x-www-form-urlencoded',
                },
                onload: function (response) {
                    if (response.status == 200) {
                        let obj = $.parseJSON(response.responseText.replace(/^操作数据失败!/, '')) || {};
                        console.log("第" + counter + "题" + "的答案为:" + obj.data);
                        if (obj.code) {
                        } else {
                            console.log('服务器繁忙,正在重试...');
                        }
                    } else if (response.status == 403) {
                        console.log('请求过于频繁,建议稍后再试');
                    } else {
                        console.log('服务器异常,正在重试...');
                    }
                }
            });
            counter++;
            if(counter == (QUESTION.length)) {
                clearInterval(SEARCH);
                console.log("题目搜索完成");
            }
        }, 1000);
    }

当然还有另外一个版本, 这个依赖于浏览器插件tampermonkey, 不用每次都手动去输入脚本内容
可以手动添加, 也可以直接在greasy fork上下载本脚本
greasy fork下载链接:https://greasyfork.org/zh-CN/scripts/405920-传智自动播放视频

// ==UserScript==
// @name         传智自动播放视频
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  自动播放传智播客课程视频, 开发者博客:http://www.nothamor.cn
// @author       nothamor
// @match        *.ityxb.com/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    console.log("欢迎使用传智自动播放插件, 作者博客:https://www.nothamor.cn");
    setTimeout(function() {
        let url = window.location.href;
        if(url.includes("http://stu.ityxb.com/lookPaper/busywork/")) {
            auto_search();
            console.log("检测到为测试页面, 开始自动查询题目");
        } else if(url.includes("http://stu.ityxb.com/preview/detail/")) {
            auto_play();
            console.log("检测到为视频播放页面, 开始自动播放视频");
        }
    }, 5000);

    function auto_play() {
        const CLASS_LIST = document.getElementsByClassName("point-progress-box");
        const CLASS_NAME = document.getElementsByClassName("point-text ellipsis");
        let question_text = document.getElementsByTagName("pre")[0];
        let player = document.getElementsByTagName("video")[0].id;
        let question_text_value;
        document.getElementById(player).click();
        let counter = 0;
        const TIMER = setInterval(function () {
            let percent = CLASS_LIST[counter].innerHTML.replace(/\ +/g, "").replace(/[\r\n]/g, "");
            let title_name = CLASS_NAME[counter].innerHTML.replace(/\ +/g, "").replace(/[\r\n]/g, "");
            if (percent.includes("100%") && counter == (CLASS_LIST.length - 1)) {
                clearInterval(TIMER);
                alert("当前页所有视频均已播放完成");
            } else if (percent.includes("100%")) {
                CLASS_LIST[counter + 1].click();
                player = document.getElementsByTagName("video")[0].id;
                document.getElementById(player).click();
                counter++;
            }
            if (title_name.includes("习题")) {
                question_text = document.getElementsByTagName("pre")[0];
                question_text_value = question_text.innerHTML;
                console.log(" ");
                GM_xmlhttpRequest({
                    method: 'GET',
                    url: 'http://jb.s759n.cn/chati.php?w=' + encodeURIComponent(QUESTION[counter].innerHTML),
                    headers: {
                        'Content-type': 'application/x-www-form-urlencoded',
                    },
                    data: 'q=' + encodeURIComponent(QUESTION[counter].innerHTML),
                    onload: function (response) {
                        if (response.status == 200) {
                            let obj = $.parseJSON(response.responseText.replace(/^操作数据失败!/, '')) || {};
                            obj.answer = obj.data;
                            console.log("题目:" + QUESTION[counter].innerHTML + "的答案为:" + obj.answer);
                            if (obj.code) {
                            } else {
                                console.log('服务器繁忙,正在重试...');
                            }
                        } else if (response.status == 403) {
                            console.log('请求过于频繁,建议稍后再试');
                        } else {
                            console.log('服务器异常,正在重试...');
                        }
                    }
                });
            }
        }, 1000);
    }
    function auto_search() {
        const QUESTION = document.getElementsByTagName("pre");
        let counter = 0;
        const SEARCH = setInterval(function() {
            GM_xmlhttpRequest({
                method: 'GET',
                url: 'http://jb.s759n.cn/chati.php?w=' + encodeURIComponent(QUESTION[counter].innerHTML),
                headers: {
                    'Content-type': 'application/x-www-form-urlencoded',
                },
                onload: function (response) {
                    if (response.status == 200) {
                        let obj = $.parseJSON(response.responseText.replace(/^操作数据失败!/, '')) || {};
                        console.log("第" + counter + "题" + "的答案为:" + obj.data);
                        if (obj.code) {
                        } else {
                            console.log('服务器繁忙,正在重试...');
                        }
                    } else if (response.status == 403) {
                        console.log('请求过于频繁,建议稍后再试');
                    } else {
                        console.log('服务器异常,正在重试...');
                    }
                }
            });
            counter++;
            if(counter == (QUESTION.length)) {
                clearInterval(SEARCH);
                console.log("题目搜索完成");
            }
        }, 1000);
    }
})();

Last Modified: September 17, 2023
Leave a Comment

57 Comments
  1. Lx Lx

    用了插件,但是没有反应呢。

    1. @Lx什么页面下没有反应,什么功能不好使

  2. 小呆呆 小呆呆

    搜题一直显示“李恒雅在睡觉觉”,是什么原因?

    1. @小呆呆题库没有完善,没有搜索到查询的题目

    2. 小呆呆 小呆呆

      @欧尼酱啥时候完善,或者可以引用别的题库么

    3. @小呆呆明天我看一下,看一下哪个题库更全一些,进行更换

  3. 1256 1256

    userscript.html?name=%E4%BC%A0%E6%99%BA%E8%87%AA%E5%8A%A8%E6%92%AD%E6%94%BE%E8%A7%86%E9%A2%91.user.js&id=747f202e-b03e-4350-98ab-84b9756d23e1:84 Uncaught TypeError: Cannot read property 'innerHTML' of undefined

    at Window.eval (userscript.html?name=%E4%BC%A0%E6%99%BA%E8%87%AA%E5%8A%A8%E6%92%AD%E6%94%BE%E8%A7%86%E9%A2%91.user.js&id=747f202e-b03e-4350-98ab-84b9756d23e1:84) at <anonymous>:3:98 at G.c.<computed> (eval at exec_fn (762ec5809ac347f789f634550a1b9073?courseId=2a9f2fcaae214d64ab31cb329ed66885:1), <anonymous>:42:472)
    1. @1256在什么页面发生的问题, 有没有截图

  4. 123 123

    不能用啊大佬

    1. @123什么情况下不能使用,什么页面呢

    2. 123 123

      @欧尼酱http://stu.ityxb.com/writePaper/busywork/22760fd09490474b9ad434dea580af28?courseId=2a9f2fcaae214d64ab31cb329ed66885
      这个网站播放视频有题目弹出

    3. @123我明天看一下,感谢反馈

  5. tffv tffv

    提供快递单号、空包代发有底单、内网www.88danhw.com