User:Mikevoir/lib.js

(function{	this._LIB = {		// Delay until element exists to run function		waitFor: function(query, callback, extraDelay) {			if ('function' == typeof callback && 'string' == typeof query) {				extraDelay = extraDelay || 0;				if (document.querySelector(query)) {					setTimeout(callback, extraDelay);				} else {					// 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) { setTimeout(callback, extraDelay); me.disconnect; // stop observing return; }					});					// start observing					observer.observe(document, { childList: true, subtree: true });				}			}		},		escapeSearch: function(string) {		   return string.replace(/[.*+?^${}|[\]\\]/g, '\\$&'); // $& means the whole matched string		},		escapeReplace: function(string) {		    return string.replace(/\$/g, '$$$$');		}	}; });