greasemonkeying towards a better Moodle

This isn’t going to turn into another rant about how frustrating Moodle 2 is … honest! Rather let’s instead take the position that any web-page that hasn’t been custom designed for a specific individual will always, no matter how good it is, leave something to be desired.

This, for me, is where greasemonkey comes in.

This is a good moment for a slight aside. Greasemonkey is fantastically revolutionary. It allows you the user to define some stuff (javascript) that should run (client side) on a webpage after it loads. I am strongly of the opinion that every website in the world should be devoid of style, and formatting, and simply consist of well marked up code requiring all users to use their own user scripts to turn into something usable. A minimum bar to using the web, as it were. I’m not sure this will catch on…

So, there are things Moodle does that I wish it did slightly differently. So this is where greasemonkey comes in. I write some scripts to make it behave differently for me.

Backup

When creating a backup of a Moodle course there are a series of pages with checkboxes with different options. I always use the same options – which aren’t the defaults. So a little bit of javascript later and each page will tick or untick according to my preference every time I use the backup feature. With ‘next’ buttons appearing at the bottom of the page I even made the page scroll to the bottom for me.

Reset

As with backups, I want reset to use my defaults, so a script does this for me too.

Advanced search

When searching for users in Moodle the default filter is the user full name, with other fields hidden. When showing the other fields there are so many it obscures the ones I want (email and username).

Moodle 2 user searchA tiny bit of scripting and application of some CSS rules, and now the default shown filters include email and username.

Improving assignments

When students submit assignments the assignment submission box lists their names, with their files etc. It does not list some of their other more useful profile fields. For handy user identification we populate the field ‘department’ via ldap with student ID numbers. Unfortunately this field is near invisible in the VLE and not much use.

Moodle 2 submissions no-scriptA bit of (rather complicated) javascript and jquery later, we now look at the name column and get the URL it links to. This URL includes the student’s Moodle database number. We then do an ajax background request to the edit profile for the given user which exposes the department field. We return back that id, and strip it down to just the 9 digit number. We then insert a new cell in the table following the name containing the students ID number.

Moodle 2 submissions with scriptThis isn’t fast, as each new cell requires an ajax call pulling back a whole page of Moodle (slow), and then stripping it down to the bit we want. But this is a darn sight faster than copy/pasting what’s on the screen, dumping into a spreadsheet, and then manually looking up student numbers and hoping you don’t have two students in the same course with the same name.

Non-greasemonkey javascript

In addition to the above I also use javascript in bookmarks to do certain things. When in a Moodle course if I want to make a backup I can hunt down where the backup link is. Or I can just click my ‘Moodle Backup’ bookmark.

javascript:(function(){window.location=window.location.toString().replace(/course\/view/,'backup/backup')})();

This is rather trivial, it just changes the URL replacing ‘course/view’ with ‘backup/backup’. So for the URL https://subdomain.domain.ac.uk/course/view.php?id=192 it takes me to https://subdomain.domain.ac.uk/course/view.php?id=192 which is of course the exact right place for taking a backup.

I use a similar bookmarklet script for Moodle course resets.

javascript:(function(){window.location=window.location.toString().replace(/course\/view/,'course/reset')})();