User:Mikevoir/lib.js

(function{	// Initialize library object	var lib = function {		this.setup;	};	// Delay until element exists to run function	lib.waitFor = function(query, callback, extraDelay) {		if ('function' == typeof callback && 'string' == typeof query) {			// set up the mutation observer			var observer = new MutationObserver(function (mutations, me) { // `mutations` is an array of mutations that occurred // `me` is the MutationObserver instance var targetNode = document.querySelector(query); if (targetNode) { if (extraDelay && 'number' == typeof extraDelay) {setTimeout(callback, extraDelay);} else {callback;} me.disconnect; // stop observing return; }			});			// start observing			observer.observe(document, { childList: true, subtree: true });		}	};	console.log('lib from library: ', lib);	// Add library to window for use in other scripts	window._LIB = lib; });