Created
May 3, 2019 21:42
-
-
Save G33kDude/3e4e70ee5ebf820b86804a0a8839eafd to your computer and use it in GitHub Desktop.
Exports grades from your student blackboard grade center
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
let doc = document; | |
if (doc.querySelector('iframe#mybbCanvas')) { | |
doc = doc.querySelector('iframe#mybbCanvas') | |
.contentDocument.querySelector('iframe#right_stream_mygrades') | |
.contentDocument; | |
} | |
let download = function(title, text) { | |
let a = doc.createElement("a"); | |
a.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(text); | |
a.download = title; | |
doc.body.appendChild(a); | |
a.click(); | |
doc.body.removeChild(a); | |
} | |
let toCSV = array => array.map(row => row.map(cell => | |
cell.indexOf(',') ? | |
'"' + cell.replace('"', '""') + '"' : | |
cell | |
)).join('\n'); | |
let reShouldDl = new RegExp("^https?://[^.]+\.blackboard\.com/.+/gradebook/notesAndFeedback/"); | |
let table = [['Item', 'Due Date', 'Points', 'Maximum', 'Comments']]; | |
doc.querySelectorAll("#grades_wrapper > .row").forEach(function(row) { | |
let nodeTitle = row.querySelector('.gradable a') || row.querySelector('.gradable').childNodes[0]; | |
let title = (nodeTitle.innerText || nodeTitle.nodeValue).trim(); | |
let elemDueDate = row.querySelector('.gradable .activityType'); | |
let dueDate = !elemDueDate ? '' : !elemDueDate.innerText.startsWith('DUE: ') ? '' : elemDueDate.innerText.slice(5); | |
let grade = row.querySelector('.grade .grade').innerText; | |
let elemMax = row.querySelector('.grade .pointsPossible') | |
let max = !elemMax ? '' : elemMax.innerText.slice(1); | |
let elemComment = row.querySelector('.grade .grade-feedback'); | |
let comment = ''; | |
if (elemComment) { | |
let onclick = elemComment.getAttribute('onclick'); | |
let html = eval('[' + onclick.slice(onclick.indexOf('(')+1, -2) + ']')[1]; | |
let el = doc.createElement( 'html' ); | |
el.innerHTML = html; | |
p = doc.createElement('p'); | |
p.innerHTML = el.querySelector('.vtbegenerated').textContent; | |
comment = p.innerText.trim(); | |
el.querySelectorAll('a').forEach(a => reShouldDl.test(a.href) ? a.click() : 0); | |
} | |
table.push([title, dueDate, grade, max, comment]); | |
}); | |
let title = doc.querySelector('.detail-heading .context').innerText + '.csv' | |
console.log(table); | |
download(title, toCSV(table)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment