Skip to content

Commit

Permalink
adding grades
Browse files Browse the repository at this point in the history
  • Loading branch information
kbohinski committed Feb 4, 2017
1 parent c996592 commit 7656e21
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

<link rel="stylesheet" href="InstructureIcons-Line.css"/>
<style>
body, #body, #right-side {
min-width: 200px;
position: absolute;
margin-right: 0px;
padding-right: 0px;
width: 98%;
}
body, #body, #right-side {
min-width: 200px;
position: absolute;
margin-right: 0px;
padding-right: 0px;
width: 98%;
}
</style>
</head>
<body style="min-width: 200px !important;">
Expand Down Expand Up @@ -66,6 +66,27 @@ <h4 style="visibility: hidden;" id="loading">Thanks, loading Canvas...</h4>
if (xhr.status >= 200 && xhr.status < 400) {
body.innerHTML = getDOM(xhr.response)
body.style.visibility = 'visible'
appendGrades()
}
}
xhr.send()
}

const appendGrades = () => {
let xhr = new XMLHttpRequest()
xhr.open('GET', baseUrl + 'grades', true)
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 400) {
let bottom = document.getElementsByClassName('button-sidebar-wide')[0]
let gradesHtml = xhr.response.split('<table class="course_details student_grades">')[1].split('</table>')[0].split('<tr>')
let total = ''
const end = '</strong></p></div><div class="clear"></div></a><div class="clear"></div></li>'
const start = '<li style="margin-top: .75em;" class="event"><div class="event-details"><p>'
for (let i = 1; i < gradesHtml.length; i++) {
console.log(i, gradesHtml[i])
total += (start + gradesHtml[i].split('<td class="course">')[1].split('</td>')[0].trim() + '</p><p><strong>' + gradesHtml[i].split('<td class="percent">')[1].split('</td>')[0].trim() + end)
}
bottom.outerHTML = wrapGrades(total)
fixLinks()
}
}
Expand All @@ -89,11 +110,11 @@ <h4 style="visibility: hidden;" id="loading">Thanks, loading Canvas...</h4>
body.style.visibility = 'visible'
}

function getDOM (content) {
return '<aside id="right-side" role="complementary" style="opacity: 1; display: block;">' + content + '</aside>'
const getDOM = (content) => {
return '<div id="right-side" role="complementary" style="opacity: 1; display: block;">' + content + '</div>'
}

function fixLinks () {
const fixLinks = () => {
let links = document.getElementsByTagName('a')
for (let i = 0; i < links.length; i++) {
links[i].addEventListener('click', (e) => {
Expand All @@ -103,5 +124,12 @@ <h4 style="visibility: hidden;" id="loading">Thanks, loading Canvas...</h4>
links[i].href = '#'
}
}

const wrapGrades = (grades) => {
const first = '<div class="events_list recent_feedback"><h2>Grades</h2><ul class="right-side-list events">'
const last = '</ul></div>'

return (first + grades + last)
}
</script>
</html>

0 comments on commit 7656e21

Please sign in to comment.