Last active
December 17, 2015 23:38
-
-
Save solidfox/5690106 to your computer and use it in GitHub Desktop.
The KTH Computer Science Master program page (http://www.kth.se/student/kurser/program/TCSCM/HT10/kurslista) should be considered broken in it's current state. This code will fix it.
This file contains hidden or 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
// For use on sites with crappy KTH course lists like | |
// http://www.kth.se/student/kurser/program/TCSCM/HT10/kurslista | |
// By Daniel Schlaug May 2013 | |
var body = document.getElementsByTagName("body")[0]; | |
function buildCourseLink(courseCode) { | |
// Clumsy way of finding the course title but it works | |
$.get("/student/kurser/kurs/" + courseCode, function (coursePage) { | |
var title = $(coursePage).filter('title').text().replace(/^KTH \| /, ""); | |
$('.' + courseCode).text(title); | |
}); | |
// Wrap each course in a properly classed anchor that can be found by jQuery once we've found the course title | |
return '<a class="' + courseCode + '" href="/student/kurser/kurs/' + courseCode + '">' + courseCode + '</a>'; | |
} | |
function buildReplacement(crappyChunkOfCourseCodes) { | |
// Get some linebreaks in there | |
crappyChunkOfCourseCodes = crappyChunkOfCourseCodes.replace(/(,|(\s| | ))+/g, '<br/>'); | |
// Look up the coursenames with the function above | |
var neatListOfLinkCoursenames = crappyChunkOfCourseCodes.replace(/[A-Za-z]{2}\d{4}/g, buildCourseLink); | |
return neatListOfLinkCoursenames; | |
} | |
var replacementBody = body.innerHTML.replace(/<p>\w*([A-Za-z]{2}\d{4}(,|(\s| | ))*)+\w*<\/p>/g, buildReplacement); | |
// Fix some spelling mistakes | |
replacementBody = replacementBody.replace("sysem", "system"); | |
body.innerHTML = replacementBody; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment