-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicroster.html
More file actions
117 lines (101 loc) · 3.67 KB
/
Copy pathicroster.html
File metadata and controls
117 lines (101 loc) · 3.67 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
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
107
108
109
110
111
112
113
114
115
116
117
<!doctype html>
<html>
<head>
<title>PerryMa*tk Computer Science</title>
<link rel="stylesheet" type="text/css" href="default.css">
<link rel="shortcut icon" type="image/png" href="/favicon.png">
<link rel="canonical" href="https://perryma.tk/" />
<script src="gears.js"></script>
<script src="https://use.fontawesome.com/8e8d811efd.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body onload="//doGears(document.body);">
<div class="page">
<div class="title">
Perryma<span class="tiny"><i class="fa fa-cog fa-spin"></i></span>tk: Computer Science For Perry High School
</div>
<div class="wrapper">
<div class="main">
Copy and paste your Infinite Campus Roster of students here:<br>
<textarea id="pasted" onChange="processStudents()" onkeypress="processStudents()" style="width: 100%;"></textarea>
<div id="processed"></div>
</div>
</div>
</div>
<script>
function processStudents() {
var txt = document.getElementById("pasted").value + "\n";
var lines = txt.split('\n');
var container = document.getElementById("processed");
while (container.firstChild) {
container.removeChild(container.firstChild);
}
var table = document.createElement("table");
container.appendChild(table);
var header = extractStudent(null);
appendStudent(header, table);
while (lines.length > 0) {
var foundNext = false;
while (lines.length > 0 && !foundNext) {
lines[0] = lines[0].trim();
if (lines[0].length === 0) {
lines.splice(0, 1); // Remove empty lines before the next student
}
else {
foundNext = true;
}
}
var student = extractStudent(lines);
appendStudent(student, table);
}
}
function extractStudent(lines) {
if (lines === null) {
var student = new Object();
student.lname = "Last Name";
student.fname = "First Name";
student.id = "ID";
student.gender = "Gender";
student.grade = "Grade";
student.dob = "DOB";
return student;
}
if (lines.length > 5) {
var student = new Object();
var name = lines[0].split(',');
console.log(name);
student.lname = name[0].trim();
student.fname = name[1].trim().split(' ')[0].trim();
student.id = lines[1].split('#')[1].trim();
student.gender = lines[2].trim();
student.grade = lines[3].trim();
student.dob = lines[4].trim();
lines.splice(0, 5); // Remove the student's lines
return student;
}
else {
lines.splice(0, 5);
return null;
}
}
function appendStudent(student, table) {
if (student === null) {
return;
}
var tr = document.createElement("tr");
table.appendChild(tr);
appendCell(student.id, tr);
appendCell(student.lname, tr);
appendCell(student.fname, tr);
appendCell(student.dob, tr);
appendCell(student.gender, tr);
appendCell(student.grade, tr);
}
function appendCell(text, row) {
var td = document.createElement("td");
row.appendChild(td);
td.textContent = text;
}
</script>
</body>
</html>