Commit 742ffbce authored by Tobias Zeumer's avatar Tobias Zeumer
Browse files

WebSMM

parent e5893816
// ==UserScript==
// @name LBS WebSMM-Widdewiddewitt-Mode
// @namespace https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/
// @version 0.0.1
// @updateURL https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/raw/master/tub/lbs/WebSMM.js
// @description Seit LBS 2.11.4 läuft das SMM via Webinterface - Handling verbessern
// @author Tobias Zeumer
// @match https://*/lbs/smm/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Anpassungen nach Adresse (vielleicht später mehr)
if (location.href.search('administration/users')) {
// Sort Select menus numerically
let selectMitarbeiter = document.getElementById('user_num');
sortNodesByNumber(selectMitarbeiter);
}
else if (location.href.search('ous/regulations/')) {
// Sort Ausleihreglements alphabetically
let selectTabelle = document.getElementById('parameter_id');
sortNodesAlphabetically(selectTabelle);
}
else if (location.href.search('/forms/')) {
// Sort Select menus alphabetically
let selectFormulare = document.getElementById('formnr');
sortNodesAlphabetically(selectFormulare);
}
/**
* Sort node's child elements by alphabet (as found); ES6 Syntax
*
* @param parentElement A select menu for example
* @return void (node will be sorted)
*/
function sortNodesAlphabetically(parentElement) {
if (typeof parentElement === 'undefined' || parentElement === null) {
console.log('sortNodesAlphabetically() - Parameter parentElement is not a valid node');
return false;
}
// spread operator
[...parentElement.children]
.sort((a, b) => a.innerText > b.innerText ? 1 : -1)
.map(node => parentElement.appendChild(node))
}
/**
* Sort node's child elements by numbers (via RegEx); ES6 Syntax
*
* @param parentElement A select menu for example
* @return void (node will be sorted)
*/
function sortNodesByNumber(parentElement) {
if (typeof parentElement === 'undefined' || parentElement === null) {
console.log('sortNodesByNumber() - Parameter parentElement is not a valid node');
return false;
}
let re = /(.*)\s\((\d*.*?)\).*/;
// spread operator
[...parentElement.children]
.sort((a, b) => parseInt(a.innerText.replace(re, "$2")) > parseInt(b.innerText.replace(re, "$2")) ? 1 : -1)
.map(node => parentElement.appendChild(node).innerText = node.innerText.replace(re, "$2: $1"))
//.innerText.replace(re, "$2: $1")
}
// Eigenes Style-Element
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '\
.fa-user.staff {color: #2DC6C6;;} \
.fa-user.exstaff {color: #2EDCDC;} \
.fa-user.externalstaff {color: #999999;} \
.fa-user.undefinedstaff {color: #AFAFAF;} \
.fa-user.staff-unlisted {color: #4065CC;} \
';
document.getElementsByTagName('head')[0].appendChild(style);
})();
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment