This repository has been archived by the owner on Jul 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateMenu.js
54 lines (46 loc) · 1.75 KB
/
CreateMenu.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
var baseURL = 'https://rawgit.com/Rocket1184/fzjwHelper/master/Script/';
var navBar = document.getElementsByClassName('nav')[0];
var menuTag = document.createElement('li');
menuTag.innerHTML = '<a href="#a" class="top_link"><span class="down">教务助手</span></a>';
menuTag.className = 'top';
var menu = document.createElement('ul');
menu.className = 'sub';
function CreateMenuItem(name, href) {
var res = document.createElement('li');
var item = document.createElement('a');
item.innerHTML = name;
item.setAttribute('href', href);
res.appendChild(item);
return res;
}
function InjectScriptElement(name) {
try {
var url = chrome.extension.getURL('Script/' + name + '.js');
} catch (error) {
try {
document.getElementById('DelEmptyLi').id.length;
} catch (error) {
var del = document.createElement('script');
del.setAttribute('type', 'text/javascript');
del.setAttribute('src', baseURL + 'DelEmptyLi.js');
del.id = ('DelEmptyLi');
document.body.appendChild(del);
}
var url = baseURL + name + '.js';
}
var el = document.createElement('script');
el.setAttribute('type', 'text/javascript');
el.setAttribute('src', url);
el.id = name;
document.body.appendChild(el);
}
function RegisterMenuEntry(name, scriptName, functionName) {
InjectScriptElement(scriptName);
var menuItemElem = CreateMenuItem(name, 'javascript:' + functionName + '()');
menu.appendChild(menuItemElem);
}
RegisterMenuEntry('课程评价', 'kcpj', 'CreateBtn');
RegisterMenuEntry('平均绩点', 'pjjd', 'CalcGPAAll');
RegisterMenuEntry('已选学分', 'yxxf', 'CalcCreditAll');
menuTag.appendChild(menu);
navBar.appendChild(menuTag);