Thanks for your message Thomas, I didn't end up using the js. I did fix it though.
What I ended up doing, in case it helps anyone else here, is to replace this line in lib/navigationlib.php:
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my/'), self::TYPE_ROOTNODE, null, 'mycourses');
with this:
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), null, self::TYPE_ROOTNODE, null, 'mycourses');