Skip to content

Instantly share code, notes, and snippets.

@TheTimmaeh
Last active October 22, 2019 09:16
Show Gist options
  • Save TheTimmaeh/eac863a8ef8511e3b69fba8dd252134b to your computer and use it in GitHub Desktop.
Save TheTimmaeh/eac863a8ef8511e3b69fba8dd252134b to your computer and use it in GitHub Desktop.
THM Moodle Adjustments
// ==UserScript==
// @name THM Moodle Adjustments
// @namespace https://thetimmaeh.com/THM-MA
// @version 0.2
// @description Fixes various inconveniences in THM Moodle
// @author TheTimmaeh
// @match *://moodle.thm.de/*
// @exclude *://moodle.thm.de/login/index.php
// @updateURL https://gist.github.com/TheTimmaeh/eac863a8ef8511e3b69fba8dd252134b/raw/6c4530a5a5814fa06058fcb514269285dd6e8565/thm-ma.user.js
// @grant none
// ==/UserScript==
// Configuration
var navigation_width = 350;
var kurse = {
'AIABMI': 'Aktuelle Infos',
'MIB1 GDVM': 'MIB1: GDVM',
'MIB2 SoSe 2019': 'MIB2: AVM1 SP',
'MIB5 SoSe 2019': 'MIB5: MG1',
'MIB6 GDVS': 'MIB6: GDVS',
'WPR2': 'MIB7: WPR2',
'MIB8 Softwareentwicklung 2': 'MIB8: SWE2',
'MGS2/MIB9': 'MIB9: MGS2',
'MGS2 Praktikum SoSe19': 'MIB9: MGS2 PRK',
'MIB10 Mathematik für Medieninformatik': 'MIB10: MATH',
'MIB11 GDVA': 'MIB11: GDVA',
'MIB12 WiSe 2019/20': 'MIB12: AVM2',
'MT17_DBS (WS 19/20)': 'MIB13: DB',
'SWEP': 'MIB14: SWEP',
'TheoInfAlg': 'MIB15: TIA',
'WS 19 20 WSK': 'MIB16: BWL'
};
(function() {
'use strict';
// Function to add CSS to the Site
var node = document.createElement('style');
document.body.appendChild(node);
window.addStyleString = function(str){
node.innerHTML = str;
}
// Adding CSS
addStyleString(`
body {
margin-left: 0px !important;
}
#page {
margin-left: 15px;
padding-left: ${navigation_width}px;
/*width: calc(100% - ${navigation_width}px);*/
width: calc(100% - 15px);
}
#nav-drawer {
position: absolute;
height: auto;
width: ${navigation_width}px;
}
#nav-drawer {
position: absolute;
height: auto;
width: ${navigation_width}px;
}
`);
// Restore Mousewheel Functionality on Nav Drawer
document.getElementById('nav-drawer').onwheel = function(){}
let menuitems = Array.from(document.getElementsByClassName('media-body'));
// Rename Menu Items
menuitems.forEach(function(item){
if(!!kurse[item.innerText]) item.innerText = kurse[item.innerText];
});
// Filter out unnecessary Menu Items
menuitems = menuitems.filter(function(item){
return item.closest('.list-group-item').dataset.indent == '1' || false;
});
// Sort Menu Item List
let sorted = [].concat(menuitems).sort(function(a, b){
return a.innerText.localeCompare(b.innerText, undefined, {numeric: true, sensitivity: 'base'});
}).map(function(item){
return item.closest('.list-group-item').outerHTML;
});
// Sort Menu Items in DOM
for(let item in menuitems){
if(menuitems[item].innerText === sorted[item].innerText) return;
menuitems[item].closest('.list-group-item').outerHTML = sorted[item];
}
// Open Links in new Window without enforced Download
var links = Array.from(document.getElementsByTagName('a')).forEach(function(link){
if(link.href.includes('resource/view.php') || link.href.endsWith('?forcedownload=1')){
link.target = '_blank';
link.href = link.href.replace('?forcedownload=1', '');
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment