// ==UserScript== // @name 学习通视频通杀 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 为学习通视频而生 // @author 汐 // @match https://mooc1.chaoxing.com/knowledge/cards* // @icon https://www.google.com/s2/favicons?domain=chaoxing.com // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== (function() { 'use strict'; var _this = window.top[0]; function Sdk(menu){ this.menu = menu; this.href = ''; this.arg = {}; this.videos = []; this.defaults = {}; this.initData(); } Sdk.prototype.md5 = function(w) { function q(v, A) { var z = (v & 65535) + (A & 65535); var w = (v >> 16) + (A >> 16) + (z >> 16); return (w << 16) | (z & 65535) } function p(v, w) { return (v << w) | (v >>> (32 - w)) } function k(B, y, w, v, A, z) { return q(p(q(q(y, B), q(v, z)), A), w) } function a(y, w, C, B, v, A, z) { return k((w & C) | ((~w) & B), y, w, v, A, z) } function h(y, w, C, B, v, A, z) { return k((w & B) | (C & (~B)), y, w, v, A, z) } function n(y, w, C, B, v, A, z) { return k(w ^ C ^ B, y, w, v, A, z) } function t(y, w, C, B, v, A, z) { return k(C ^ (w | (~B)), y, w, v, A, z) } function c(G, B) { G[B >> 5] |= 128 << (B % 32); G[(((B + 64) >>> 9) << 4) + 14] = B; var y; var A; var z; var w; var v; var F = 1732584193; var E = -271733879; var D = -1732584194; var C = 271733878; for (y = 0; y < G.length; y += 16) { A = F; z = E; w = D; v = C; F = a(F, E, D, C, G[y], 7, -680876936); C = a(C, F, E, D, G[y + 1], 12, -389564586); D = a(D, C, F, E, G[y + 2], 17, 606105819); E = a(E, D, C, F, G[y + 3], 22, -1044525330); F = a(F, E, D, C, G[y + 4], 7, -176418897); C = a(C, F, E, D, G[y + 5], 12, 1200080426); D = a(D, C, F, E, G[y + 6], 17, -1473231341); E = a(E, D, C, F, G[y + 7], 22, -45705983); F = a(F, E, D, C, G[y + 8], 7, 1770035416); C = a(C, F, E, D, G[y + 9], 12, -1958414417); D = a(D, C, F, E, G[y + 10], 17, -42063); E = a(E, D, C, F, G[y + 11], 22, -1990404162); F = a(F, E, D, C, G[y + 12], 7, 1804603682); C = a(C, F, E, D, G[y + 13], 12, -40341101); D = a(D, C, F, E, G[y + 14], 17, -1502002290); E = a(E, D, C, F, G[y + 15], 22, 1236535329); F = h(F, E, D, C, G[y + 1], 5, -165796510); C = h(C, F, E, D, G[y + 6], 9, -1069501632); D = h(D, C, F, E, G[y + 11], 14, 643717713); E = h(E, D, C, F, G[y], 20, -373897302); F = h(F, E, D, C, G[y + 5], 5, -701558691); C = h(C, F, E, D, G[y + 10], 9, 38016083); D = h(D, C, F, E, G[y + 15], 14, -660478335); E = h(E, D, C, F, G[y + 4], 20, -405537848); F = h(F, E, D, C, G[y + 9], 5, 568446438); C = h(C, F, E, D, G[y + 14], 9, -1019803690); D = h(D, C, F, E, G[y + 3], 14, -187363961); E = h(E, D, C, F, G[y + 8], 20, 1163531501); F = h(F, E, D, C, G[y + 13], 5, -1444681467); C = h(C, F, E, D, G[y + 2], 9, -51403784); D = h(D, C, F, E, G[y + 7], 14, 1735328473); E = h(E, D, C, F, G[y + 12], 20, -1926607734); F = n(F, E, D, C, G[y + 5], 4, -378558); C = n(C, F, E, D, G[y + 8], 11, -2022574463); D = n(D, C, F, E, G[y + 11], 16, 1839030562); E = n(E, D, C, F, G[y + 14], 23, -35309556); F = n(F, E, D, C, G[y + 1], 4, -1530992060); C = n(C, F, E, D, G[y + 4], 11, 1272893353); D = n(D, C, F, E, G[y + 7], 16, -155497632); E = n(E, D, C, F, G[y + 10], 23, -1094730640); F = n(F, E, D, C, G[y + 13], 4, 681279174); C = n(C, F, E, D, G[y], 11, -358537222); D = n(D, C, F, E, G[y + 3], 16, -722521979); E = n(E, D, C, F, G[y + 6], 23, 76029189); F = n(F, E, D, C, G[y + 9], 4, -640364487); C = n(C, F, E, D, G[y + 12], 11, -421815835); D = n(D, C, F, E, G[y + 15], 16, 530742520); E = n(E, D, C, F, G[y + 2], 23, -995338651); F = t(F, E, D, C, G[y], 6, -198630844); C = t(C, F, E, D, G[y + 7], 10, 1126891415); D = t(D, C, F, E, G[y + 14], 15, -1416354905); E = t(E, D, C, F, G[y + 5], 21, -57434055); F = t(F, E, D, C, G[y + 12], 6, 1700485571); C = t(C, F, E, D, G[y + 3], 10, -1894986606); D = t(D, C, F, E, G[y + 10], 15, -1051523); E = t(E, D, C, F, G[y + 1], 21, -2054922799); F = t(F, E, D, C, G[y + 8], 6, 1873313359); C = t(C, F, E, D, G[y + 15], 10, -30611744); D = t(D, C, F, E, G[y + 6], 15, -1560198380); E = t(E, D, C, F, G[y + 13], 21, 1309151649); F = t(F, E, D, C, G[y + 4], 6, -145523070); C = t(C, F, E, D, G[y + 11], 10, -1120210379); D = t(D, C, F, E, G[y + 2], 15, 718787259); E = t(E, D, C, F, G[y + 9], 21, -343485551); F = q(F, A); E = q(E, z); D = q(D, w); C = q(C, v) } return [F, E, D, C] } function o(w) { var x; var v = ""; var y = w.length * 32; for (x = 0; x < y; x += 8) { v += String.fromCharCode((w[x >> 5] >>> (x % 32)) & 255) } return v } function j(w) { var y; var v = []; v[(w.length >> 2) - 1] = undefined; for (y = 0; y < v.length; y += 1) { v[y] = 0 } var x = w.length * 8; for (y = 0; y < x; y += 8) { v[y >> 5] |= (w.charCodeAt(y / 8) & 255) << (y % 32) } return v } function i(v) { return o(c(j(v), v.length * 8)) } function u(x, A) { var w; var z = j(x); var v = []; var y = []; var B; v[15] = y[15] = undefined; if (z.length > 16) { z = c(z, x.length * 8) } for (w = 0; w < 16; w += 1) { v[w] = z[w] ^ 909522486; y[w] = z[w] ^ 1549556828 } B = c(v.concat(j(A)), 512 + A.length * 8); return o(c(y.concat(B), 512 + 128)) } function s(z) { var y = "0123456789abcdef"; var w = ""; var v; var A; for (A = 0; A < z.length; A += 1) { v = z.charCodeAt(A); w += y.charAt((v >>> 4) & 15) + y.charAt(v & 15) } return w } function l(v) { return unescape(encodeURIComponent(v)) } function e(v) { return i(l(v)) } function m(v) { return s(e(v)) } function b(v, w) { return u(l(v), l(w)) } function r(v, w) { return s(b(v, w)) } function f(w, x, v) { if (!x) { if (!v) { return m(w) } return e(w) } if (!v) { return r(x, w) } return b(x, w) } return f(w); }; Sdk.prototype.queryElement = function(selector,source){ return new Promise((resolve,rejcet)=>{ let regCount = 0; let timer = setInterval(()=>{ let body = (source || document).body; let _target = 0; if(body){ _target = body.querySelectorAll(selector); } if(_target) { clearInterval(timer); resolve(_target); } if(++regCount > 30){ rejcet(new Error('超过10秒未获取')); } },1000); }); } Sdk.prototype.isVideo = function(attachment){ return attachment.type == 'video'; } Sdk.prototype.isVideoPass = function(attachment){ return attachment.isPassed; } Sdk.prototype.getRurl = function(video,playingTime=0){ let format = "[{0}][{1}][{2}][{3}][{4}][{5}][{6}][{7}]",clipTime = (0 || "0") + "_" + (0 || window.parseInt(video.details.duration)); let enc = _this.Ext.String.format(format, this.defaults.clazzId, this.defaults.userid, video.jobid || "", video.objectId, playingTime * 1000, "d_yHJ!$pdA~5", video.details.duration * 1000, clipTime); let isdrag = 0; let rurl = ["https://mooc1.chaoxing.com/multimedia/log/a/122918840", "/", video.details.dtoken, "?clazzId=", this.defaults.clazzId, "&playingTime=", playingTime, "&duration=", video.details.duration, "&clipTime=", clipTime, "&objectId=", video.objectId, "&otherInfo=", video.otherInfo, "&jobid=", video.jobid, "&userid=", this.defaults.userid, "&isdrag=", isdrag, "&view=pc", "&enc=", this.md5(enc), "&rt=", 0.9, "&dtype=Video", "&_t=", new Date().getTime()].join(""); return rurl; } Sdk.prototype.getArg= async function(){ //return JSON.parse(/{.*}/g.exec((await this.queryElement('script'))[0].innerHTML)[0]); return _this.mArg; } Sdk.prototype.getVideoEl = async function(objectId){ let videoEls = [...(await this.queryElement('video',(await this.queryElement('iframe'))[0].contentDocument))]; return videoEls.find((videoEl)=>{ return /.*\/(.*)\/.+.mp4/.exec(videoEl.src)[1] == objectId; }); } Sdk.prototype.getVideoDetails = function(objectid){ return new Promise((resolve,rejcet)=>{ GM_xmlhttpRequest({ url:'/ananas/status/'+objectid+'?k=' + this.defaults.fid+"&flag=normal", method:'get', headers: { "Content-Type": "application/json" }, onload:function(response){ resolve(JSON.parse(response.responseText)); } }); }); } Sdk.prototype.requestKillVideo = async function(rurl){ return new Promise((resolve,rejcet)=>{ GM_xmlhttpRequest({ url:rurl, method:'get', headers: { "Content-Type": "application/json" }, onload:function(response){ resolve(JSON.parse(response.responseText)); } }); }); } Sdk.prototype.initData = async function(){ try{ this.href = window.location.href; this.arg = await this.getArg(); this.defaults = this.arg.defaults; this.videos.length = 0; for(let attachment of this.arg.attachments){ if(this.isVideo(attachment)){ attachment.videoEl = await this.getVideoEl(attachment.objectId); attachment.details = await this.getVideoDetails(attachment.objectId); this.videos.push(attachment); } } }catch(e){ console.log(e); } this.initMenu(); } Sdk.prototype.initMenu = function(){ let _targetEl = window.top.document.getElementById('xidaren'); if(_targetEl){ _targetEl.remove(); } let title = window.top.document.querySelector("#mainid > div.prev_title_pos > div").innerText; let menu = this.menu; let div = document.createElement('div'); div.id = menu.id; let html = `
${index+1} -> ${video.property.name} ->
`; }); }else{ tmpHtml += '此章节没有视频'; } html += tmpHtml + `