ChatPMGreeting

// 
if (mw.config.get("wgCanonicalSpecialPageName") == "Chat") {
	// global object for users' greetings
	PMGreeting = {};
	PMGreeting.data = {}; // content goes here
	// define variables
	var target = document.querySelector("#ChatHeader .private"),
		config = {childList: true, attributes: true};
	// css
	mw.util.addCSS(
		'#ChatHeader.private-header-opened {\n' +
			'\theight: 70px;\n' +
		'}\n' +
		'#ChatHeader.private-header-opened + #WikiaPage {' +
			'\ttop: 85px;\n' +
		'}\n' +
		'#ChatHeader:not(.private-header-opened) #private-header{\n' +
			'\tdisplay: none;\n' +
		'}\n' +
		'#private-header {\n' +
			'\toverflow: hidden;\n' +
			'\theight: 18px;\n' +
			'\tpadding: 2px;\n' +
			'\tbackground: #fafafa;\n' +
			'\tborder: 1px solid #cccccc;\n' +
			'\tline-height: 19px;\n' +
			'\tcolor: #999999;\n' +
			'\tfont-style: italic;\n' +
		'}'
	);
	// create element for greeting content
	$("#ChatHeader .private").after('');
	PMGreeting.observer = new MutationObserver(function() {
		var user = $("#PrivateChatList > li.selected").attr("data-user");
		if (user) {
			// a pm is selected
			if ($(target).css("display") == "none") {
				// toggled back to main chat - hide private message part
				console.log("toggled back to main chat - hide private message part");
				$("#ChatHeader").removeClass("private-header-opened");
			} else {
				// opened pm of switched current pm
				$("#ChatHeader").removeClass("private-header-opened");
				if (typeof PMGreeting.data[user] !== "undefined") {
					// user's greeting has already loaded
					console.log("user's info has already loaded");
					if (PMGreeting.data[user].length > 0) {
						// empty string if no actual valid content was inserted
						$("#private-header").html(PMGreeting.data[user]);
						$("#ChatHeader").addClass("private-header-opened");
					}
				} else {
					// need to load user's message
					console.log("Need to get user's info!");
					$('').load("/wiki/User_blog:" + encodeURIComponent(user) + "/ChatGreeting?action=render", function(data) { // remember to add path to subpage!
						$(this).find(":not(a,u,b,p,s)").remove();
						$(this).contents().each(function() {
							if (this.nodeType == 8) {
								$(this).remove();
							}
						});
						$(this).find("[style]").removeAttr("style");
						$(this).find("a").each(function() {
							$(this).attr("target","_blank");
						});
						var html = $(this).html(),
							bool = html.replace(/( |\n)*/g,"").length > 0; // boolean - if there is an actual valid content for the wall
						PMGreeting.data[user] = bool ? html : ""; // empty string if no actual content for greeting exists
						if (bool) {
							$("#private-header").html(html);
							$("#ChatHeader").addClass("private-header-opened");
						}
					});
				}
			}
		} else {
			//main chat is selected
				console.log("toggled back to main chat - hide private message part");
				$("#ChatHeader").removeClass("private-header-opened");
		}
	});
	PMGreeting.observer.observe(target, config);
}
//