Skip to content

Instantly share code, notes, and snippets.

@vikranth22446
Last active November 4, 2017 06:17
Show Gist options
  • Save vikranth22446/ebc2f1aa0c511fb22bd380e1c51f44de to your computer and use it in GitHub Desktop.
Save vikranth22446/ebc2f1aa0c511fb22bd380e1c51f44de to your computer and use it in GitHub Desktop.
Downloads an Excel Spreadsheet for badly formatted Bio Scores.
/**
- Run via pasting into inspect element in the console tab on the Bio Progress Report.
- Check the CSV for a SUM Function, and click the function button.
**/
if (document.title.match(/Progress/g) != null) {
function generateBioCSV() {
var csv_data = "Assignment Type, Title, Your Score :(, Total Score :), SUM(C:C), SUM(D:D), SUM(C:C)/SUM(D:D) \n"
$('td.home_left tr').each(function() {
var $grade = $(this).find('td:nth-child(5):not(th)');
$grade = $grade.prop('outerHTML')
if ($grade === undefined || $grade.match(/Score: [A-F]/g) === null) return;
var $grade = $(this).find('td:nth-child(5):not(th)');
console.log($grade)
var $title = $(this).find('td:nth-child(1):not(th) div').prop('innerHTML');
var titleArr = $title.match(/\w+.*/g)
console.log(titleArr)
var $score = $(this).find('td:nth-child(4)').prop('outerHTML')
var scores = $score.match(/[+-]?([0-9]*[.])?[0-9]+/g);
if (scores !== null) {
csv_data += titleArr[0].replace(/,/g, '') + "," + titleArr[3].replace(/,/g, '') + "," + parseFloat(scores[scores.length - 3]) + "," + parseFloat(scores[scores.length - 2])
csv_data += "\r\n"
}
})
console.log(csv_data)
return csv_data;
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
download("BioGrades.csv", generateBioCSV());
} else {
alert('This script can only be run on Bio Progress Report')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment