Skip to content

Instantly share code, notes, and snippets.

@tommetge
Created September 6, 2011 21:52
Show Gist options
  • Save tommetge/1199085 to your computer and use it in GitHub Desktop.
Save tommetge/1199085 to your computer and use it in GitHub Desktop.
hiding grades in canvas
/* Note that this does not disable viewing of grades, it simply
hides them from the students. As such, this is certainly not
bullet-proof: a smart and dedicated person will be able to
expose grades.
Given the above, it is recommended that institutions simply
wait for the official hidden grade functionality in Canvas. */
// Detect our enrollments
var enrollments = [];
$("a > span.name.ellipsis").each(function(i) {
enrollmentStr = $(this).parent().text().match(/Enrolled as a [a-zA-Z]*/)
if (enrollmentStr) {
enrollments[$(this).parent().attr('href')] = enrollmentStr[0].replace("Enrolled as a ", '');
enrollments[i] = $(this).parent().attr('href');
}
});
// Are we a teacher in the current URL?
var teacher = false;
if (enrollments[window.location.pathname.match(/\/courses\/[^\/]+/)] == "Teacher") {
teacher = true;
}
// Check for visits to unauthorized URLs
if (window.location.pathname.match(/\/grades/) && !teacher) {
window.location.replace(window.location.href.replace(/\/grades*/, ''));
}
/* These modifications are handled when the document is fully
rendered */
function removeGrades() {
// Remove all links to grades
$("a[href*='/grades']").remove();
// Remove grades and possible values from assignments list
$(".grade").remove();
$(".points_possible").remove();
if ($(".points_text").html()) {
$(".points_text").html($(".points_text").html().replace("out of", ''));
}
// Remove quiz scores
$(".quiz_score").remove();
$(".summary > tbody > tr > th:contains('Score')").parent().remove();
$(".question_points_holder").remove();
$(".user_points").remove();
// Remove grade from submission details
details = $(".details > div > a.forward").parent();
if (details.length > 0) {
details.html(details.html().replace(/Grade\: [0-9a-zA-Z|\-|\+]*/, ''));
$(".details > div > span:contains('possible')").remove();
}
}
$(document).ready(function() {
if (!teacher) {
removeGrades();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment