User:Eleazaros/npctooltip.js

From Lotro-Wiki.com
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// from http://www.wowwiki.com/User:Pcj/npctooltip.js
/*
<pre>
*/

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('<div class="npcname">.*?</div>');
rawNameM = nameHTML.exec(rawText);
if (rawNameM) {
reName = new RegExp('.*<div class="npcname">(.*?)</div>.*');
rawName = rawNameM[0].replace(reName, "$1");
}
iconHTML = new RegExp('<div class="npcicon">.*?</div>');
rawIconM = iconHTML.exec(rawText);
if (rawIconM) {
reIcon = new RegExp('.*<div class="npcicon">(.*?)</div>.*');
rawIcon = '<div style="float:left;">' + rawIconM[0].replace(reIcon, "$1") + '</div>';
}
pictureHTML = new RegExp('<div[^>]*?class="npcpic">.*?</div>');
rawPictureM = pictureHTML.exec(rawText);
if (rawPictureM) {
rePicture = new RegExp('.*<div[^>]*?class="npcpic">.*?<img[^>]*src="(.*?)".*?</div>.*');
rawPicture = '<img src="' + rawPictureM[0].replace(rePicture, "$1") + '" alt="' + rawName + '" height="300"></div><div align="center">';
}
titleHTML = new RegExp('<div class="npctitle">.*?</div>');
rawTitleM = titleHTML.exec(rawText);
if (rawTitleM) {
reTitle = new RegExp('.*<div class="npctitle">(.*?)</div>.*');
rawTitle = "<br />" + rawTitleM[0].replace(reTitle, "$1");
}
levelHTML = new RegExp('<div class="npclevel">.*?</div>');
rawLevelM = levelHTML.exec(rawText);
if (rawLevelM) {
reLevel = new RegExp('.*<div class="npclevel">(.*?)</div>.*');
rawLevel = '<br />Level: ' + rawLevelM[0].replace(reLevel, "$1");
}
locHTML = new RegExp('<div class="npcloc">.*?</div>');
rawLocM = locHTML.exec(rawText);
if (rawLocM) {
reLoc = new RegExp('.*<div class="npcloc">(.*?)</div>.*');
rawLoc = "<br />" + rawLocM[0].replace(reLoc, "$1");
}
tooltip = rawPicture + rawIcon + rawName + rawTitle + rawLevel + rawLoc;
if (tooltip != null && tooltip != "") {
tip.innerHTML = ttHTMLStart + '<div align="center">' + tooltip + '</div>';
}
}
displayTip_Eleazaros();
}
}

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_Eleazaros() {
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_Eleazaros.bind(Spans[i],i);
Spans[i].onmousemove = moveTip_Eleazaros;
}
}
}
nttMouseOver_Eleazaros();

/*
</pre>
*/