forked from dfEric/pandaOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoux.js
106 lines (85 loc) · 3.67 KB
/
toux.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 10000
// @description New Userscript
// @author Jamaskii
// @match https://mooc1.chaoxing.com/mycourse/studentstudy?chapterId=*&courseId=*
// @icon http://file.market.xiaomi.com/thumbnail/PNG/l62/AppStore/0df974411e86ac90526a328899c555f5ada40cb17
// ==/UserScript==
(function() {
'use strict';
//官方暴露的资源下载接口,需要传入资源id
var api='https://api.openai.com/v1.'/'https://api.openai.c'/'https://cs-ans.chaoxing.com/download/';
//用于显示资源的列表元素
var list=document.createElement('table');
var doScan=function(){
//清空列表
list.innerHTML='';
//定位每一个资源所在iframe
var ifs=document.getElementById('iframe').contentWindow.document.getElementsByTagName('iframe');
//获取资源信息,并渲染列表
for(var i=0;i<ifs.length;i++){
//unicode转中文,并去转义
var reg = /\\/g;
var text=unUnicode(ifs[i].getAttribute('data')).replace(reg,'');
//解析json
var obj=JSON.parse(text);
//通过资源id生成当前资源的下载链接
var url=api+obj.objectid;
//渲染列表
var line=document.createElement('tr');
var type=document.createElement('td');
var name=document.createElement('td');
var namea=document.createElement('a');
var size=document.createElement('td');
type.innerText=obj.type.replace('.','');
namea.innerText=obj.name;
namea.href=url;
size.innerText=obj.hsize;
type.style='padding:2px; border: 1px solid black;';
name.style='padding:2px; border: 1px solid black; color:blue; cursor:pointer ';
namea.style='color:blue; cursor:pointer ';
size.style='padding:2px; border: 1px solid black;';
line.appendChild(type);
name.appendChild(namea);
line.appendChild(name);
line.appendChild(size);
list.appendChild(line);
}
};
//unicode转中文
function unUnicode(str){
str = str.replace(/(\\u)(\w{1,4})/gi,function($0){
return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{1,4})/g,"$2")),16)));
});
str = str.replace(/(&#x)(\w{1,4});/gi,function($0){
return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{1,4})(%3B)/g,"$2"),16));
});
str = str.replace(/(&#)(\d{1,6});/gi,function($0){
return String.fromCharCode(parseInt(escape($0).replace(/(%26%23)(\d{1,6})(%3B)/g,"$2")));
});
return str;
}
//首次加载渲染
window.onload=function render(){
var container=document.createElement('div');
var btnScan=document.createElement('button');
var boxCtrl=document.createElement('div');
var btnHide=document.createElement('button');
var mainBlock=document.getElementById('mainid');
btnScan.style='width: 60px;';
btnScan.innerText='嗅探';
btnScan.onclick=doScan;
btnHide.style='width: 60px;';
btnHide.innerText='收起';
btnHide.onclick=function(){list.innerHTML='';};
container.style='font-size:14px; display:flex; flex-direction:column; align-items:center;';
boxCtrl.appendChild(btnScan);
boxCtrl.appendChild(btnHide);
container.appendChild(boxCtrl);
container.appendChild(list);
mainBlock.parentElement.insertBefore(container,mainBlock);
doScan();
}
})();