Skip to content

Instantly share code, notes, and snippets.

@0xjac
Last active February 3, 2017 01:48
Show Gist options
  • Save 0xjac/a322655dd93b30f0bba8 to your computer and use it in GitHub Desktop.
Save 0xjac/a322655dd93b30f0bba8 to your computer and use it in GitHub Desktop.
Shows course names instead of ids on icorsi.
// ==UserScript==
// @name fix_icorsi
// @namespace https://gist.github.com/jacquesd/
// @version 0.4
// @description Shows the course names instead of ides on the side menu.
// @author Jacques Dafflon
// @match https://www2.icorsi.ch/*
// @website https://gist.github.com/jacquesd/a322655dd93b30f0bba8
// @source https://gist.githubusercontent.com/jacquesd/a322655dd93b30f0bba8/raw/fix_icorsi.user.js
// @updateURL https://gist.githubusercontent.com/jacquesd/a322655dd93b30f0bba8/raw/fix_icorsi.user.js
// @downloadURL https://gist.githubusercontent.com/jacquesd/a322655dd93b30f0bba8/raw/fix_icorsi.user.js
// @grant none
// @run-at document-idle
// ==/UserScript==
/* jshint -W097 */
'use strict';
function fixCourseName(course) { course.innerHTML = course.title; }
function fixCourseNames(selector) {
var courses = document.querySelectorAll(selector);
courses.forEach(fixCourseName);
}
// fix side menu
var course_page_sidemenu = document.getElementById('expandable_branch_0_mycourses');
if (course_page_sidemenu !== null) {
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
for (var i = 0; i < mutation.addedNodes.length; i++) {
if (mutation.type === 'childList') {
mutation.addedNodes[i]
.querySelectorAll('li.contains_branch > .tree_item.branch > a')
.forEach(fixCourseName);
break;
}
}
});
});
observer.observe(course_page_sidemenu.parentNode, { childList: true });
// Automatically expand the course list
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
setTimeout(function() { course_page_sidemenu.dispatchEvent(clickEvent); }, 1000);
}
// fix current course
fixCourseNames('.type_course.depth_3 > .tree_item.branch > a');
// fix breadcrumbs
fixCourseNames('#page-navbar > .breadcrumb-nav > * > .breadcrumb > li > a:not([title=\'\'])[href^=\'https://www2.icorsi.ch/course/view.php?\']');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment