This repository was archived by the owner on Apr 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.js
More file actions
58 lines (50 loc) · 1.51 KB
/
load.js
File metadata and controls
58 lines (50 loc) · 1.51 KB
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
function findList() {
var nodeList = document.querySelectorAll("a.course-title");
return nodeList;
}
function parseList(nodeList) {
var onclickData = [];
var courseNameData = [];
for (var i = 0, len = nodeList.length; i < len; i++) {
onclickData.push(nodeList[i].getAttribute('onclick'));
courseNameData.push(nodeList[i].innerHTML.trim());
}
return [onclickData, courseNameData];
}
function buildLists(data) {
var courseNameList = [];
var onclickList = [];
for (var key in data[0]) {
onclickList.push(data[0][key]);
courseNameList.push(data[1][key]);
}
return [onclickList, courseNameList];
}
function findName() {
var nameNode = document.getElementById("login-name");
return nameNode.innerText;
}
function writeList(lists) {
var onclickList = lists[0];
var courseNameList = lists[1];
var aNode, textNode, courseName;
var topDiv = document.getElementById("topDropAll");
for (var i = 0, len = onclickList.length; i < len; i++) {
courseName = courseNameList[i].replace("&", "&");
textNode = document.createTextNode(courseName);
node = document.createElement("a");
node.className = "course-title";
node.href = "student,home.0";
node.setAttribute("onclick", onclickList[i]);
node.appendChild(textNode);
topDiv.appendChild(node);
}
}
var port = chrome.runtime.connect({name: "data-link"});
var userName = findName();
port.postMessage({type:"check", data:userName})
port.onMessage.addListener(function(msg) {
if (msg.flag == "y") {
writeList(msg["data"]);
}
});