User:Toranosuke/npctooltip.js

// from http://www.wowwiki.com/User:Pcj/npctooltip.js /*

function parseNPCText { //Check to see if the XmlHttpRequests state is finished. if (getRequest.readyState == 4) { rawText = getRequest.responseText; var tip = document.getElementById('tfb'); tip.innerHTML = ttError("NPC"); if (rawText) { rawName = ""; rawIcon = ""; rawPicture = ""; rawTitle = ""; rawLevel = ""; rawLoc = ""; rawText = rawText.replace(crlf, ""); nameHTML = new RegExp(' .*? '); rawNameM = nameHTML.exec(rawText); if (rawNameM) { reName = new RegExp('.* (.*?) .*'); rawName = rawNameM[0].replace(reName, "$1"); } iconHTML = new RegExp(' .*? '); rawIconM = iconHTML.exec(rawText); if (rawIconM) { reIcon = new RegExp('.* (.*?) .*'); rawIcon = ' ' + rawIconM[0].replace(reIcon, "$1") + ' '; } pictureHTML = new RegExp(']*?class="npcpic">.*? '); rawPictureM = pictureHTML.exec(rawText); if (rawPictureM) { rePicture = new RegExp('.*]*?class="npcpic">.*?]*src="(.*?)".*? .*'); rawPicture = ' '; } titleHTML = new RegExp(' .*? '); rawTitleM = titleHTML.exec(rawText); if (rawTitleM) { reTitle = new RegExp('.* (.*?) .*'); rawTitle = " " + rawTitleM[0].replace(reTitle, "$1"); } levelHTML = new RegExp(' .*? '); rawLevelM = levelHTML.exec(rawText); if (rawLevelM) { reLevel = new RegExp('.* (.*?) .*'); rawLevel = ' Level: ' + rawLevelM[0].replace(reLevel, "$1"); } locHTML = new RegExp(' .*? '); rawLocM = locHTML.exec(rawText); if (rawLocM) { reLoc = new RegExp('.* (.*?) .*'); rawLoc = " " + rawLocM[0].replace(reLoc, "$1"); } tooltip = rawPicture + rawIcon + rawName + rawTitle + rawLevel + rawLoc; if (tooltip != null && tooltip != "") { tip.innerHTML = ttHTMLStart + ' ' + tooltip + ' '; } } displayTip; } }

function showNPCTip(i) { if (tooltipsOn) { var Span = document.getElementById( "npctt" + i ); var ttLink = Span.parentNode; if (ttLink.getAttribute("class") != "selflink") { Span.setAttribute("title", ""); if (ttLink.getAttribute("title")) { npcname = ttLink.getAttribute("title"); ttLink.setAttribute("title", ""); newSpan = document.createElement("span"); newSpan.setAttribute("title", npcname); ttLink.appendChild(newSpan); } else { npcname = ttLink.lastChild.getAttribute("title"); } getInfo(npcname, 5); } } }

function nttMouseOver { var Spans = document.getElementsByTagName( "span" ); for ( var i = 0; i < Spans.length; i++ ) { if ( hasClass( Spans[i], "npclink" ) ) { Spans[i].setAttribute("id", "npctt" + i); Spans[i].onmouseover = showNPCTip.bind(Spans[i],i); Spans[i].onmouseout = hideTip.bind(Spans[i],i); Spans[i].onmousemove = moveTip; } } } nttMouseOver;

/*