Skip to content

Instantly share code, notes, and snippets.

@d-makarenko
Created October 5, 2017 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-makarenko/094503e6139f3a1ab4716e2b3cd0ce49 to your computer and use it in GitHub Desktop.
Save d-makarenko/094503e6139f3a1ab4716e2b3cd0ce49 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Classroom roster
// @namespace http://tampermonkey.net/
// @version 0.1
// @description
// @author You
// @match https://classroom.github.com/classrooms/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// this array contains pairs Name - Login. Each found Login will be replaced
// with the appropriate name
var roster = [
["Student 1", "student_1_login"],
["Student 2", "student_2_login"],
//etc
];
setTimeout(
function() {
var list = document.getElementsByClassName("assignment-repo-github-url");
for(var i = 0; i < list.length; i++) {
var login = list[i].text.trim();
for(var j = 0; j < roster.length; j++) {
if (roster[j][1] == login) {
console.log("replacing with " + roster[j][0]);
list[i].getElementsByClassName("css-truncate")[0].innerHTML = roster[j][0];
break;
}
}
}
// this function sorts students on the assignment page
// first will be shown Accepted students, then Not Accepted
// both groups are sorted alphabetically
$(".assignment-repo-list-item").sort(function(a, b) {
var result;
var aname = a.getElementsByClassName("css-truncate")[0].innerHTML;
var bname = b.getElementsByClassName("css-truncate")[0].innerHTML;
var aaccepted = a.getElementsByClassName("octicon-git-commit").length > 0;
var baccepted = b.getElementsByClassName("octicon-git-commit").length > 0;
if (aaccepted && !baccepted) {
result = -1;
} else if (baccepted && !aaccepted) {
result = 1;
}
else {
result = aname < bname ? -1 : 1;
}
console.log(aname + " " + bname + " " + result);
return result;
}).appendTo('.assignment-repo-list');
}, 3000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment