User:Shameermbm/common.js

function addStyleSheet(pageTitle, sucCallback) { var cssLink = $(" "); $("head").append(cssLink); cssLink.attr({		rel: "stylesheet",		type: "text/css",		href: "https://en.wikiversity.org/w/index.php?action=raw&ctype=text/css&title=" + pageTitle	}); console.log('loading CSS file ' + pageTitle); if (typeof sucCallback !== 'undefined') { checkForStyleSheet(pageTitle, sucCallback); } } function checkForStyleSheet(name, sucCallback) { var styleSheets = document.styleSheets; var loaded = false; for (var i = 0; i < styleSheets.length; i++) { var styleSheet = styleSheets[i]; if (styleSheet.href !== null && styleSheet.href.match(name)) { try { var rules = styleSheet.rules ? styleSheet.rules : styleSheet.cssRules; if (rules !== null && rules.length > 0) { loaded = true; break; }			} catch (e) { break; }		}	}	if (loaded) { console.log('stylesheet ' + name + ' loaded.'); sucCallback; } else { console.log('waiting for stylesheet ' + name + '...'); setTimeout(function {			checkForStyleSheet(name, sucCallback);		}, 50); } } function addJavaScript(pageTitle, sucCallback) { var promise = $.getScript("https://en.wikiversity.org/w/index.php?action=raw&ctype=text/javascript&title=" + pageTitle).fail(function(jqxhr, settings, e) {		if (jqxhr.readyState === 0) {			console.log('resource loader (JS): failed to load script "' + pageTitle + '" (not found)');		} else {			console.log('resource loader (JS): failed to load script "' + pageTitle + '" (script contains syntax errors)');			console.log(jqxhr.status + ', e: ' + e);		}	}); if (sucCallback !== 'undefined') { console.log('JS loaded: ' + pageTitle); promise.done(sucCallback); } } $(document).ready(function{	$('#resource-loader').each(function { var namespace = 'User:Sebschlicht'; var resources = $(this).text.split(','); var numResources = resources.length; for (var iResource = 0; iResource < numResources; iResource++) { var resource = $.trim(resources[iResource]); if (resource.substring(0, namespace.length) !== namespace) { console.log('did not load resource "' + resource + '": not in namespace ' + namespace); continue; }			if (resource.length > 4 && resource.substr(resource.length - 4) == '.css') { addStyleSheet(resource); } else if (resource.length > 3 && resource.substr(resource.length - 3) == '.js') { addJavaScript(resource); }		}	}); });