HisInOne GreaseMonkey Script zum direkten Anzeigen der Raum-IDs

Quick and Dirty Script, um im His automatisch die roomId in den Suchergebnissen und Detailseiten zu Räumen anzuzeigen (direkt neben Raumname).

@match anpassen nicht vergessen!

// ==UserScript==
// @name         Show HISinOne room ids
// @version      0.2
// @description  try to take over the world!
// @author       You
// @match        https://campus.uni-freiburg.de/*
// ==/UserScript==

(function() {
	'use strict';
	var COMPLETED_READY_STATE = 4;
	var RealXHRSend = XMLHttpRequest.prototype.send;
	function proxifyOnReadyStateChange(xhr) {
		if (xhr.hasMyProxy) return;
		xhr.hasMyProxy = true;
		var realOnReadyStateChange = xhr.onreadystatechange;
		xhr.onreadystatechange = function() {
			var r;
			if (realOnReadyStateChange) {
				r = realOnReadyStateChange();
			}
			if( xhr.readyState === COMPLETED_READY_STATE ) {
				ajaxCompleted(xhr);
			}
			return r;
		};
	}
	// Wire
	(function() {
		// Override send method of all XHR requests
		console.log('Patching send');
		XMLHttpRequest.prototype.send = function() {
			// Wire response callbacks
			var r = RealXHRSend.apply(this, arguments);
			proxifyOnReadyStateChange(this);
			return r;
		};
	})();
	function ajaxCompleted(xhr) {
		setTimeout(showRoomIds, 100);
	}
	function showRoomIds() {
		var btns = document.querySelectorAll('BUTTON.linkTable');
		var data;
		for (var b = 0; b < btns.length; ++b) {
			if (!btns[b].onclick) continue;
			if (btns[b].hasRid) continue;
			btns[b].hasRid = true;
			if (btns[b].getElementsByTagName('SPAN').length === 0) continue;
			data = btns[b].onclick.toString().match(/\['(?:room|entity)Id','(\d+)']/);
			if (!data || data.length < 2) continue;
			btns[b].parentNode.appendChild(document.createTextNode(' (RID: ' + data[1] + ')'));
		}
		data = false;
		var txt = document.getElementById('plan:permalink:permalinkPopup:permalink')
			|| document.getElementById('roomDetail:top:permalink:permalinkPopup:permalink');
		if (txt && txt.value) {
			data = txt.value.match(/roomId=(\d+)(&|$)/);
		}
		if (!data || data.length < 2) {
			txt = document.querySelectorAll('optgroup option[selected]');
			if (txt && txt.length) {
				for (b = 0; b < txt.length; ++b) {
					if (txt[b].value && txt[b].value.match(/^\d+$/)) {
						data = [ 0, txt[b].value ];
						break;
					}
				}
			}
		}
		if (data && data.length > 1) {
			var dst = document.getElementById('hisinoneTitle') || txt.parentNode;
			if (!dst.hasRid) {
				dst.hasRid = true;
				dst.appendChild(document.createTextNode(' (RID: ' + data[1] + ')'));
			}
		}
	}
	showRoomIds();
})();
Drucken/exportieren