联通党校-刷视频积分

联通党校刷视频,输入专栏ID即可.注意,只能在主题专栏中才能正确使用,进入后未正常生效请重新刷新页面。

当前为 2023-11-02 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         联通党校-刷视频积分
// @namespace    https://gitee.com/zouyongs/js-liantongdangxiao
// @version      1.2
// @description  联通党校刷视频,输入专栏ID即可.注意,只能在主题专栏中才能正确使用,进入后未正常生效请重新刷新页面。
// @author       ZouYs
// @match        https://m.campus.chinaunicom.cn/*
// @icon         https://m.campus.chinaunicom.cn/favicon.ico
// @require      https://cdn.jsdelivr.net/npm/[email protected]/bin/jsencrypt.min.js

// @grant        unsafeWindow
// ==/UserScript==

(function () {
  'use strict';
  //悬浮展示窗
  window.onload = function () {
    let show = 0
    let showWindow = document.createElement('button')
    showWindow.style.width = '60px'
    showWindow.style.height = '40px'
    showWindow.innerText = '开刷!'
    showWindow.style.position = 'fixed'
    showWindow.style.left = '0px'
    showWindow.style.top = '150px'
    showWindow.style.zIndex = '111'
    showWindow.addEventListener('click', fuc_show)
    function fuc_show() {
      // let is_show=document.querySelector('#myWindow')
      show++
      if (show == 1) {
        myWindow.style.display = 'block'

      }
      else {
        show = 0
        myWindow.style.display = 'none'
      }
    }
    document.body.appendChild(showWindow)
    let myWindow = document.createElement('div')
    myWindow.id = 'mywin'
    myWindow.style.width = '300px'
    myWindow.style.height = '400px'
    myWindow.style.backgroundColor = '#efefef'
    myWindow.style.position = 'fixed'
    myWindow.style.left = '50px'
    myWindow.style.top = '150px'
    myWindow.style.zIndex = '111'
    myWindow.style.display = 'none'

    //浮窗控件
    // let myBtn = document.createElement('button')
    // myBtn.style.width = '50px'
    // myBtn.style.height = '30px'
    // myBtn.style.position = 'relative'
    // myBtn.style.left = '10px'
    // myBtn.style.top = '10px'
    // myBtn.innerText = '开始'
    // myBtn.addEventListener('click', myFuc)
    // function myFuc() {
    //     alert('点击按钮')
    // }
    // myWindow.appendChild(myBtn)
    //获取信息到窗口

    myWindow.innerHTML = `<button id="btn-begin">开始</button>
<button id="btn-update">更新课程</button>
睡眠时间:<input id="sleeptime" value="3" style="display: inline-block;width: 40px;"> 秒
<br>专栏ID:<div id="c-id" contenteditable="true" style="display: inline-block;width: 60px;">
${window.location.href.split('?')[1].split('=')[1]}</div><br>
当前页:<input id="c-cur" type="number" min="1"  step="1" value="1" style="display: inline-block;width: 40px;">
页课程数:<input id="c-size" type="number" min="8"  step="1" value="8" style="display: inline-block;width: 40px;">
<br>专栏总课程数:<div id="c-total"  style="display: inline-block;width: 20px;color: #f5083f;">36</div>

</div><div style="width:90%;margin: auto auto;border-radius: 10px;position: relative;border: 1px solid grey;height: 200px;margin-top: 0px;">
<ul id="ul" style=" overflow-x: auto;white-space: nowrap;margin:0px 0px 0px 0px; overflow: auto;height:100%;">
    <li>1</li>
</ul>
当前进度:
<div id="myProgress" style="width: 0%; height: 20px; background-color: green; position: relative; bottom: 0;">
        
    </div>
    <div id="progrssNum" style="display: flex;justify-content: center;position: relative; top: -20px;">0%</div>
    <div id="waitInfo" style="color:red;display: flex;justify-content: center">正在获取课程树信息中,请稍等....</div>
</div>`
    document.body.appendChild(myWindow)

    function randomStrFuc() {
      for (var n = 32, t = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"], e = "", c = 0; c < n; c++) {
        var u = parseInt(61 * Math.random() + "");
        e += t[u]
      }
      return e
    }

    var ERROR = "input is invalid type", WINDOW = "object" == typeof window, root = WINDOW ? window : {}, WEB_WORKER = (root.JS_MD5_NO_WINDOW && (WINDOW = !1),
      !WINDOW && "object" == typeof self), NODE_JS = !root.JS_MD5_NO_NODE_JS && "object" == typeof process && process.versions && process.versions.node, COMMON_JS = (NODE_JS ? root = global : WEB_WORKER && (root = self),
        !root.JS_MD5_NO_COMMON_JS && "object" == typeof module && module.exports), ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && "undefined" != typeof ArrayBuffer, HEX_CHARS = "0123456789abcdef".split(""), EXTRA = [128, 32768, 8388608, -2147483648], SHIFT = [0, 8, 16, 24], OUTPUT_TYPES = ["hex", "array", "digest", "buffer", "arrayBuffer", "base64"], BASE64_ENCODE_CHAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""), blocks = [], buffer8, buffer, buffer8, blocks, createOutputMethod = (ARRAY_BUFFER && (buffer = new ArrayBuffer(68),
          buffer8 = new Uint8Array(buffer),
          blocks = new Uint32Array(buffer)),
          !root.JS_MD5_NO_NODE_JS && Array.isArray || (Array.isArray = function (t) {
            return "[object Array]" === Object.prototype.toString.call(t)
          }
          ),
          !ARRAY_BUFFER || !root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW && ArrayBuffer.isView || (ArrayBuffer.isView = function (t) {
            return "object" == typeof t && t.buffer && t.buffer.constructor === ArrayBuffer
          }
          ))
      //进度条
      var myProgress=document.getElementById('myProgress')
      var myProgressNum=document.getElementById('progrssNum')
      var cur_courseList
    function Md5(t) {
      t ? (blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0,
        this.blocks = blocks,
        this.buffer8 = buffer8) : ARRAY_BUFFER ? (t = new ArrayBuffer(68),
          this.buffer8 = new Uint8Array(t),
          this.blocks = new Uint32Array(t)) : this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0,
        this.finalized = this.hashed = !1,
        this.first = !0
    }
    Md5.prototype.update = function (t) {
      if (!this.finalized) {
        var e, n = typeof t;
        if ("string" != n) {
          if ("object" != n)
            throw ERROR;
          if (null === t)
            throw ERROR;
          if (ARRAY_BUFFER && t.constructor === ArrayBuffer)
            t = new Uint8Array(t);
          else if (!(Array.isArray(t) || ARRAY_BUFFER && ArrayBuffer.isView(t)))
            throw ERROR;
          e = !0
        }
        for (var i, r, o = 0, a = t.length, s = this.blocks, l = this.buffer8; o < a;) {
          if (this.hashed && (this.hashed = !1,
            s[0] = s[16],
            s[16] = s[1] = s[2] = s[3] = s[4] = s[5] = s[6] = s[7] = s[8] = s[9] = s[10] = s[11] = s[12] = s[13] = s[14] = s[15] = 0),
            e)
            if (ARRAY_BUFFER)
              for (r = this.start; o < a && r < 64; ++o)
                l[r++] = t[o];
            else
              for (r = this.start; o < a && r < 64; ++o)
                s[r >> 2] |= t[o] << SHIFT[3 & r++];
          else if (ARRAY_BUFFER)
            for (r = this.start; o < a && r < 64; ++o)
              (i = t.charCodeAt(o)) < 128 ? l[r++] = i : (i < 2048 ? l[r++] = 192 | i >> 6 : (i < 55296 || 57344 <= i ? l[r++] = 224 | i >> 12 : (i = 65536 + ((1023 & i) << 10 | 1023 & t.charCodeAt(++o)),
                l[r++] = 240 | i >> 18,
                l[r++] = 128 | i >> 12 & 63),
                l[r++] = 128 | i >> 6 & 63),
                l[r++] = 128 | 63 & i);
          else
            for (r = this.start; o < a && r < 64; ++o)
              (i = t.charCodeAt(o)) < 128 ? s[r >> 2] |= i << SHIFT[3 & r++] : (i < 2048 ? s[r >> 2] |= (192 | i >> 6) << SHIFT[3 & r++] : (i < 55296 || 57344 <= i ? s[r >> 2] |= (224 | i >> 12) << SHIFT[3 & r++] : (i = 65536 + ((1023 & i) << 10 | 1023 & t.charCodeAt(++o)),
                s[r >> 2] |= (240 | i >> 18) << SHIFT[3 & r++],
                s[r >> 2] |= (128 | i >> 12 & 63) << SHIFT[3 & r++]),
                s[r >> 2] |= (128 | i >> 6 & 63) << SHIFT[3 & r++]),
                s[r >> 2] |= (128 | 63 & i) << SHIFT[3 & r++]);
          this.lastByteIndex = r,
            this.bytes += r - this.start,
            64 <= r ? (this.start = r - 64,
              this.hash(),
              this.hashed = !0) : this.start = r
        }
        return 4294967295 < this.bytes && (this.hBytes += this.bytes / 4294967296 << 0,
          this.bytes = this.bytes % 4294967296),
          this
      }
    }
    Md5.prototype.finalize = function () {
      var t, e;
      this.finalized || (this.finalized = !0,
        (t = this.blocks)[(e = this.lastByteIndex) >> 2] |= EXTRA[3 & e],
        56 <= e && (this.hashed || this.hash(),
          t[0] = t[16],
          t[16] = t[1] = t[2] = t[3] = t[4] = t[5] = t[6] = t[7] = t[8] = t[9] = t[10] = t[11] = t[12] = t[13] = t[14] = t[15] = 0),
        t[14] = this.bytes << 3,
        t[15] = this.hBytes << 3 | this.bytes >>> 29,
        this.hash())
    }
      ,
      Md5.prototype.hash = function () {
        var t, e, n, i, r, o = this.blocks, a = this.first ? ((a = ((t = ((t = o[0] - 680876937) << 7 | t >>> 25) - 271733879 << 0) ^ (e = ((e = (-271733879 ^ (n = ((n = (-1732584194 ^ 2004318071 & t) + o[1] - 117830708) << 12 | n >>> 20) + t << 0) & (-271733879 ^ t)) + o[2] - 1126478375) << 17 | e >>> 15) + n << 0) & (n ^ t)) + o[3] - 1316259209) << 22 | a >>> 10) + e << 0 : (t = this.h0,
          a = this.h1,
          e = this.h2,
          ((a += ((t = ((t += ((n = this.h3) ^ a & (e ^ n)) + o[0] - 680876936) << 7 | t >>> 25) + a << 0) ^ (e = ((e += (a ^ (n = ((n += (e ^ t & (a ^ e)) + o[1] - 389564586) << 12 | n >>> 20) + t << 0) & (t ^ a)) + o[2] + 606105819) << 17 | e >>> 15) + n << 0) & (n ^ t)) + o[3] - 1044525330) << 22 | a >>> 10) + e << 0);
        a = ((a += ((t = ((t += (n ^ a & (e ^ n)) + o[4] - 176418897) << 7 | t >>> 25) + a << 0) ^ (e = ((e += (a ^ (n = ((n += (e ^ t & (a ^ e)) + o[5] + 1200080426) << 12 | n >>> 20) + t << 0) & (t ^ a)) + o[6] - 1473231341) << 17 | e >>> 15) + n << 0) & (n ^ t)) + o[7] - 45705983) << 22 | a >>> 10) + e << 0,
          a = ((a += ((t = ((t += (n ^ a & (e ^ n)) + o[8] + 1770035416) << 7 | t >>> 25) + a << 0) ^ (e = ((e += (a ^ (n = ((n += (e ^ t & (a ^ e)) + o[9] - 1958414417) << 12 | n >>> 20) + t << 0) & (t ^ a)) + o[10] - 42063) << 17 | e >>> 15) + n << 0) & (n ^ t)) + o[11] - 1990404162) << 22 | a >>> 10) + e << 0,
          a = ((a += ((t = ((t += (n ^ a & (e ^ n)) + o[12] + 1804603682) << 7 | t >>> 25) + a << 0) ^ (e = ((e += (a ^ (n = ((n += (e ^ t & (a ^ e)) + o[13] - 40341101) << 12 | n >>> 20) + t << 0) & (t ^ a)) + o[14] - 1502002290) << 17 | e >>> 15) + n << 0) & (n ^ t)) + o[15] + 1236535329) << 22 | a >>> 10) + e << 0,
          a = ((a += ((n = ((n += (a ^ e & ((t = ((t += (e ^ n & (a ^ e)) + o[1] - 165796510) << 5 | t >>> 27) + a << 0) ^ a)) + o[6] - 1069501632) << 9 | n >>> 23) + t << 0) ^ t & ((e = ((e += (t ^ a & (n ^ t)) + o[11] + 643717713) << 14 | e >>> 18) + n << 0) ^ n)) + o[0] - 373897302) << 20 | a >>> 12) + e << 0,
          a = ((a += ((n = ((n += (a ^ e & ((t = ((t += (e ^ n & (a ^ e)) + o[5] - 701558691) << 5 | t >>> 27) + a << 0) ^ a)) + o[10] + 38016083) << 9 | n >>> 23) + t << 0) ^ t & ((e = ((e += (t ^ a & (n ^ t)) + o[15] - 660478335) << 14 | e >>> 18) + n << 0) ^ n)) + o[4] - 405537848) << 20 | a >>> 12) + e << 0,
          a = ((a += ((n = ((n += (a ^ e & ((t = ((t += (e ^ n & (a ^ e)) + o[9] + 568446438) << 5 | t >>> 27) + a << 0) ^ a)) + o[14] - 1019803690) << 9 | n >>> 23) + t << 0) ^ t & ((e = ((e += (t ^ a & (n ^ t)) + o[3] - 187363961) << 14 | e >>> 18) + n << 0) ^ n)) + o[8] + 1163531501) << 20 | a >>> 12) + e << 0,
          a = ((a += ((n = ((n += (a ^ e & ((t = ((t += (e ^ n & (a ^ e)) + o[13] - 1444681467) << 5 | t >>> 27) + a << 0) ^ a)) + o[2] - 51403784) << 9 | n >>> 23) + t << 0) ^ t & ((e = ((e += (t ^ a & (n ^ t)) + o[7] + 1735328473) << 14 | e >>> 18) + n << 0) ^ n)) + o[12] - 1926607734) << 20 | a >>> 12) + e << 0,
          a = ((a += ((r = (n = ((n += ((i = a ^ e) ^ (t = ((t += (i ^ n) + o[5] - 378558) << 4 | t >>> 28) + a << 0)) + o[8] - 2022574463) << 11 | n >>> 21) + t << 0) ^ t) ^ (e = ((e += (r ^ a) + o[11] + 1839030562) << 16 | e >>> 16) + n << 0)) + o[14] - 35309556) << 23 | a >>> 9) + e << 0,
          a = ((a += ((r = (n = ((n += ((i = a ^ e) ^ (t = ((t += (i ^ n) + o[1] - 1530992060) << 4 | t >>> 28) + a << 0)) + o[4] + 1272893353) << 11 | n >>> 21) + t << 0) ^ t) ^ (e = ((e += (r ^ a) + o[7] - 155497632) << 16 | e >>> 16) + n << 0)) + o[10] - 1094730640) << 23 | a >>> 9) + e << 0,
          a = ((a += ((r = (n = ((n += ((i = a ^ e) ^ (t = ((t += (i ^ n) + o[13] + 681279174) << 4 | t >>> 28) + a << 0)) + o[0] - 358537222) << 11 | n >>> 21) + t << 0) ^ t) ^ (e = ((e += (r ^ a) + o[3] - 722521979) << 16 | e >>> 16) + n << 0)) + o[6] + 76029189) << 23 | a >>> 9) + e << 0,
          a = ((a += ((r = (n = ((n += ((i = a ^ e) ^ (t = ((t += (i ^ n) + o[9] - 640364487) << 4 | t >>> 28) + a << 0)) + o[12] - 421815835) << 11 | n >>> 21) + t << 0) ^ t) ^ (e = ((e += (r ^ a) + o[15] + 530742520) << 16 | e >>> 16) + n << 0)) + o[2] - 995338651) << 23 | a >>> 9) + e << 0,
          a = ((a += ((n = ((n += (a ^ ((t = ((t += (e ^ (a | ~n)) + o[0] - 198630844) << 6 | t >>> 26) + a << 0) | ~e)) + o[7] + 1126891415) << 10 | n >>> 22) + t << 0) ^ ((e = ((e += (t ^ (n | ~a)) + o[14] - 1416354905) << 15 | e >>> 17) + n << 0) | ~t)) + o[5] - 57434055) << 21 | a >>> 11) + e << 0,
          a = ((a += ((n = ((n += (a ^ ((t = ((t += (e ^ (a | ~n)) + o[12] + 1700485571) << 6 | t >>> 26) + a << 0) | ~e)) + o[3] - 1894986606) << 10 | n >>> 22) + t << 0) ^ ((e = ((e += (t ^ (n | ~a)) + o[10] - 1051523) << 15 | e >>> 17) + n << 0) | ~t)) + o[1] - 2054922799) << 21 | a >>> 11) + e << 0,
          a = ((a += ((n = ((n += (a ^ ((t = ((t += (e ^ (a | ~n)) + o[8] + 1873313359) << 6 | t >>> 26) + a << 0) | ~e)) + o[15] - 30611744) << 10 | n >>> 22) + t << 0) ^ ((e = ((e += (t ^ (n | ~a)) + o[6] - 1560198380) << 15 | e >>> 17) + n << 0) | ~t)) + o[13] + 1309151649) << 21 | a >>> 11) + e << 0,
          a = ((a += ((n = ((n += (a ^ ((t = ((t += (e ^ (a | ~n)) + o[4] - 145523070) << 6 | t >>> 26) + a << 0) | ~e)) + o[11] - 1120210379) << 10 | n >>> 22) + t << 0) ^ ((e = ((e += (t ^ (n | ~a)) + o[2] + 718787259) << 15 | e >>> 17) + n << 0) | ~t)) + o[9] - 343485551) << 21 | a >>> 11) + e << 0,
          this.first ? (this.h0 = t + 1732584193 << 0,
            this.h1 = a - 271733879 << 0,
            this.h2 = e - 1732584194 << 0,
            this.h3 = n + 271733878 << 0,
            this.first = !1) : (this.h0 = this.h0 + t << 0,
              this.h1 = this.h1 + a << 0,
              this.h2 = this.h2 + e << 0,
              this.h3 = this.h3 + n << 0)
      }
      ,
      Md5.prototype.hex = function () {
        this.finalize();
        var t = this.h0
          , e = this.h1
          , n = this.h2
          , i = this.h3;
        return HEX_CHARS[t >> 4 & 15] + HEX_CHARS[15 & t] + HEX_CHARS[t >> 12 & 15] + HEX_CHARS[t >> 8 & 15] + HEX_CHARS[t >> 20 & 15] + HEX_CHARS[t >> 16 & 15] + HEX_CHARS[t >> 28 & 15] + HEX_CHARS[t >> 24 & 15] + HEX_CHARS[e >> 4 & 15] + HEX_CHARS[15 & e] + HEX_CHARS[e >> 12 & 15] + HEX_CHARS[e >> 8 & 15] + HEX_CHARS[e >> 20 & 15] + HEX_CHARS[e >> 16 & 15] + HEX_CHARS[e >> 28 & 15] + HEX_CHARS[e >> 24 & 15] + HEX_CHARS[n >> 4 & 15] + HEX_CHARS[15 & n] + HEX_CHARS[n >> 12 & 15] + HEX_CHARS[n >> 8 & 15] + HEX_CHARS[n >> 20 & 15] + HEX_CHARS[n >> 16 & 15] + HEX_CHARS[n >> 28 & 15] + HEX_CHARS[n >> 24 & 15] + HEX_CHARS[i >> 4 & 15] + HEX_CHARS[15 & i] + HEX_CHARS[i >> 12 & 15] + HEX_CHARS[i >> 8 & 15] + HEX_CHARS[i >> 20 & 15] + HEX_CHARS[i >> 16 & 15] + HEX_CHARS[i >> 28 & 15] + HEX_CHARS[i >> 24 & 15]
      }
    let cur_url = window.location.href.split('?')
    var id_cour = cur_url[1].split('=')[1];

    // let cur_url = window.location.href.split('?')
    // var id = cur_url[1];
    // var token = document.cookie.split('token=')[1].split(';')[0]
    // var timestamp=Math.floor(Date.now() / 1000);
    // var companyId=window.localStorage.getItem("companyId") || 0
    // var organizationId=window.localStorage.getItem("organizationId") || 0
    // var from='WEB'
    // var randomStr= randomStrFuc()
    var publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAooxomrujIP9vcxxNmS+Q1xxnaoxAfluwFvDR3+G+p84QMsePXDD67cLjJ+7n+79u2xoG7fVvDnzHDW+X5D/0/Dv9ajUaBpFQl3jqKwRiP3Lrx08seYzWIWDGHEjurbZrWGHRJNdoM7tEQPdPZftZC6iOm7kSjDIDiuqaIh9g3hqFSVQ5r15Dvae6qtREo1nDWKsf3tH6nkvVD2pIh3TBJUoGdfbPqnw/tNvzhwOX9tg7NjhZ8Yet1ctVt297G5HCwPSIBjhUKEtLYLk/8scPrzXnQpAU05m5WnHfDhfvvG2xoVXckveNvZhv6lvxTZqRkUBOI1pU16U9Tz4aDpCU7QIDAQAB";
    //加密参数并序列化、字符串化参数
    //返回对象,包含字符串参数和sign

    function encryptData(e,smp=true) {
      var t, c = "",
        r = Object.keys(e).sort();
      for (t in r) {
        var o = e[r[t]];
        null != o && (c += r[t] + "=" + o + "&")
      }
      if(smp){
        console.log("字符串参数: " + c)
      }
      var key_md5 = new Md5(!0).update(c)['hex']()
      if(smp){
        console.log("key_md5: " + key_md5)
      }
      return { 'serString': c, 'sign': encrypt(key_md5,smp) }
    }
    //加密,获得sign
    function encrypt(key,smp=true) {
      var rsa = new JSEncrypt();
      rsa.setPublicKey(publicKey);
      var encryptedData = rsa.encrypt(key);
      if(smp){
        console.log("sign: " + encryptedData);
      }
      return encryptedData
    }

    var e = {
      token: document.cookie.split('token=')[1].split(';')[0],
      timestamp: Math.floor(Date.now() / 1000),
      companyId: window.localStorage.getItem("companyId") || 0,
      from: "WEB",
      organizationId: window.localStorage.getItem("organizationId") || 0,
      randomStr: randomStrFuc(),
      id: document.getElementById('c-id').innerText,
      subjectId: "",
      status: 1,
      name: '',
      currentPage: document.getElementById("c-cur").value,
      pageSize: document.getElementById("c-size").value,
      total: 0
    }
    var url = {
      courseList: 'https://app.campus.chinaunicom.cn/app/themeColumn/getMyAreaInfoCourse',
      courseInfo: 'https://app.campus.chinaunicom.cn/app/course/info',
      studyCourse: 'https://app.campus.chinaunicom.cn/app/course/playtimeV2'
    }
    var cList = []
    var allCount
    cList = getData(url, e).then(v => {
      cList = v
      statistics().then(v=>{
        allCount=0
        allCount=v
        console.log('allCount:'+v)
        console.log('课程树信息已获取完毕~')
        document.getElementById('waitInfo').innerText=`课程树信息已获取~可以开始`
        document.getElementById('waitInfo').style.color='green'
      })
      
    })
    document.getElementById('btn-begin').addEventListener('click', () => {
      console.log('cList=' + cList)
      begin(cList)
    })
    document.getElementById('btn-update').addEventListener('click', () => {
      update(e)
    })
    /**
     * @description: 统计信息
     * @return {*}
     */    
    async function statistics(){
      let count=0
      for (let ll of cList){
        await getCourseInfo(ll.id,false).then(v => {
          ll.child=v
          count+=v.length
        })
      }
      return count
    }
    /**
     * @description: 
     * @return {*}
     */
    async function begin(list) {
      console.log('开始专栏ID:' + window.location.href.split('?')[1].split('=')[1])
      // console.log(typeof(cList))
      let llList=0
      for (let ll of list) {
        let courseId = ll.id
        await sleep(document.getElementById("sleeptime").value * 1000)
        for (let kk of ll.child) {
          llList++
          kk.courseId = courseId
          console.log('正在修改学习时间kpointId:' + kk.kpointId + "")
          await sleep(document.getElementById("sleeptime").value * 1000)
          studyCourse(kk).then(v => {
            console.log('本次结果:' + v.message)
            let pgr=Math.round((llList)/allCount *100)
            console.log('pgr:'+pgr)
            myProgress.style.width=`${pgr}%`
            myProgressNum.innerText=`${pgr}%`
          })

        }
      }
    }
    /**
     * @description: 
     * @return {*}
     */
    function update(e) {
      myProgress.style.width=`0%`
      myProgressNum.innerText=`0%`
      document.getElementById('waitInfo').style.color='red'
      document.getElementById('waitInfo').innerText=`正在获取课程树信息中,请稍等....`
      e.id = document.getElementById('c-id').innerText
      e.currentPage = document.getElementById("c-cur").value
      e.pageSize = document.getElementById("c-size").value
      getData(url, e).then(v => {
        cList = v
        statistics().then(v=>{
          allCount=0
          allCount=v
          console.log('allCount:'+v)
          console.log('课程树信息已获取完毕~')
          document.getElementById('waitInfo').innerText=`课程树信息已获取~可以开始`
          document.getElementById('waitInfo').style.color='green'
        })
      })

    }
    /**
     * @description: 
     * @param {*} time
     * @return {*}
     */
    async function getData(url, e) {
      try {
        const response = await request(url.courseList, encryptData(e));
        const courseList = await response.json();
        console.log(courseList.entity.courseList); // 打印获取的数据
        // 更新窗口数据
        document.getElementById('c-total').innerText = courseList.entity.page.totalResultSize;
        let li = '';
        for (let ii of courseList.entity.courseList) {
          li += `<li style="margin-bottom:5px;height: 20px;width: 100%;">已看:${(ii.playTime / ii.totalPlayTime * 100).toFixed(2)}%  ${ii.name}  id: ${ii.id} </li>`;
        }
        document.getElementById('ul').innerHTML = li;
        console.log('窗口数据已更新');
        return courseList.entity.courseList; // 返回获取的数据
      } catch (error) {
        console.error(error);
        throw error; // 处理异常情况
      }
    }
    async function sleep(time) {
      console.log('睡眠' + time / 1000 + 's')
      return await new Promise((resolve) => setTimeout(resolve, time));
    }
    //
    /**
     * @description: 获取单个课程信息
     * @param {*} id
     * @return {*}
     */
    async function getCourseInfo(id,smp=true) {
      var signleCourse = {
        token: document.cookie.split('token=')[1].split(';')[0],
        timestamp: Math.floor(Date.now() / 1000),
        companyId: window.localStorage.getItem("companyId") || 0,
        from: "WEB",
        organizationId: window.localStorage.getItem("organizationId") || 0,
        randomStr: randomStrFuc(),
        courseId: id
      }
      var courseInfo
      //发送请求
      const response = await request(url.courseInfo, encryptData(signleCourse,smp),smp)
      const data = await response.json()

      if(smp){
        console.log(data.entity.courseNode); // 这里打印获取的数据
      }
      courseInfo = data.entity.courseNode
      return courseInfo



    }

    //更改课程学习时间
    async function studyCourse(courseNode) {
      var study = {
        token: document.cookie.split('token=')[1].split(';')[0],
        timestamp: Math.floor(Date.now() / 1000),
        companyId: window.localStorage.getItem("companyId") || 0,
        from: "WEB",
        organizationId: window.localStorage.getItem("organizationId") || 0,
        randomStr: randomStrFuc(),
        type: "playback",
        kpointId: 36864,
        courseId: 26120,
        breakpoint: 331,
        studyTime: 480,
      }
      study.studyTime = courseNode.courseMinutes * 60 + courseNode.courseSeconds
      study.kpointId = courseNode.kpointId
      study.courseId = courseNode.courseId
      study.breakpoint = study.studyTime
      const response = await request(url.studyCourse, encryptData(study))
      const data = await response.json()

      return data


    }
    //发送fetchPOST请求
    //返回data
    /**
     * @description: 
     * @param {*} url
     * @param {*} e
     * @return {*}
     */
    async function request(url, e,smp=true) {
      if(smp){
        console.log('正在发送请求->url:' + url)
      }
      return fetch(url + "?" + e.serString + "sign=" + e.sign, {
        "headers": {
          "accept": "application/json, text/plain, */*",
          "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
          "content-type": "application/x-www-form-urlencoded",
          "sec-ch-ua": "\"Microsoft Edge\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"",
          "sec-ch-ua-mobile": "?0",
          "sec-ch-ua-platform": "\"Windows\"",
          "sec-fetch-dest": "empty",
          "sec-fetch-mode": "cors",
          "sec-fetch-site": "same-site"
        },
        "referrer": "https://m.campus.chinaunicom.cn/",
        "referrerPolicy": "strict-origin-when-cross-origin",
        "body": "",
        "method": "POST",
        "mode": "cors",
        "credentials": "omit"
      })
    }
  }

})();