Benoit Debled

Software Developer
Firmware Developer
SysAdmin
Entrepreneur

Hide Classes you currently Don't Attend From Moodle

Ever since I’ve used Moodle for school, I’ve thought that it was missing an option: to hide some classes!

Every time the school year starts, I get auto signed up to the classes I have that year. But why would I need classes from the second semester when I’m in the first semester ? I could sign out of those classes, but the problem is that I need a passkey to sign back in. A passkey that the teacher should know, but always forget it. So I got around that problem by creating a small JavaScript to hide the classes that I didn’t have at that time.

As I use chromium, I run that JavaScript by using the TamperMonkey plugin.

So here is the JavaScript code:


// ==UserScript==
// @name Hide classes from moodle that you no longer have
// @namespace https://moodle.umons.ac.be/
// @version 0.1
// @description none
// @author Benoit Debled
// @include https://moodle.umons.ac.be/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// @grant none
// ==/UserScript==
var classes = ["class1", "class2", "class3"];
for (i = 0; i < classes.length; i++) {
var badDivs = $("div.coursebox h3.coursename:contains('"+classes[i]+"')");
badDivs.parent().parent().remove ();

badDivs = $("li a:contains('"+classes[i]+"')");
badDivs.parent().parent().remove ();
}

So, the principle of the script I’ve created is pretty simple : the variable classes contains every classes’ title that you want to hide. For each of these classes : the lines 15-16 of the JavaScript will hide the whole “coursebox” (element 1 on picture below) the lines 18-19 of the JavaScript will hide the little link on the left of your page. (element 2 on picture below)

How to install this trick

  1. Install TamperMonkey on chrome or chromium
  2. click on the new little icon on the right of the address bar : img
  3. Then, click on "add a new script…"
  4. Copy paste the above code to the text editor.
  5. Change https://moodle.umons.ac.be/ and https://moodle.umons.ac.be/* to your moodle address edit the variable classes
  6. Save your modifications
  7. Check if it worked on moodle !

Enjoy!