User:Toranosuke/itemtooltip.js

// from http://www.wowwiki.com/User:Pcj/itemtooltip.js /* var pagename = ""; var showingComp = false; var re = new RegExp(']*?class=".*?itemtooltip.*?".*?>.*? '); var sre = new RegExp(']*?class=".*?settip.*?".*?>.*? '); var re2 = new RegExp("1em; float: right; width:", "g"); var re3 = new RegExp(']*?class="setdesc req".*?>.*?]*?class="setdesc".*?>.*?]*?class="setdesc setbonus".*?>.*?]*?class="setdesc".*?>.*?]*?class="setdesc setbonus".*?>.*?]*?class="ttslot-(.*?)">.*'); var reR = new RegExp('.*]*?title="(.*?)".*');

/* detects which key is down */ document.onkeydown = KeyDownHandler; document.onkeyup = KeyUpHandler;

function KeyDownHandler(e) { var x = ''; if (document.all) { var evnt = window.event; x = evnt.keyCode; } else { x = e.keyCode; } if (x == '17' && ttCompare) { tipSwitch(true); } }

function KeyUpHandler(e) { var x = ''; if (document.all) { var evnt = window.event; x = evnt.keyCode; } else { x = e.keyCode; } if (x == '17' && ttCompare) { tipSwitch(false); } }

function tipSwitch(CTRL) { if (CTRL != showingComp) { if (showingComp) { showingComp = false; } else { showingComp = true; } var tip = document.getElementById('tfb'); var tip2 = document.getElementById('tfb2'); tempTip = tip.innerHTML; tip.innerHTML = tip2.innerHTML; tip2.innerHTML = tempTip; } }

function slotByName(slotName) { /* from InventorySlotId 0 = ear 1, 1 = shoulders, 2 = head, 3 = ear 2, 4 = wrist 1, 5 = chest, 6 = neck, 7 = back, 8 = finger 1, 9 = feet, 10 = hands, 11 = wrist 2, 12 = trinket, 13 = legs, 14 = finger 2, 15 = main hand, 16 = off hand, 17 = ranged, 18 = tool, 19 = inventory switch (slotName) { case "Ear": return 0; break case "Shoulders": return 1; break case "Head": return 2; break case "Wrist": return 4; break case "Chest": return 5; break case "Neck": return 6; break case "Back": return 7; break case "Feet": return 9; break case "Hands": return 10; break case "Trinket": return 12; break case "Legs": return 13; break case "Main Hand": case "One-Hand": case "Two-Hand": return 15; break case "Off Hand": return 16; break case "Ranged": return 17; break case "Tool": return 18; break case "Inventory": return 19; default: return -1; } }

function parseCompText { //Check to see if the XmlHttpRequests state is finished. if (getRequest.readyState == 4) { rawText = getRequest.responseText; var tip = document.getElementById('tfb2'); tip.innerHTML = ttError("item"); if (rawText) { rawText = rawText.replace(crlf, ""); rawText = rawText.replace(re2, "1em; background: transparent url(http://ja.lotro.wikia.com/images/8/82/Ttip_Background.png); width:").replace(re3, "<li").replace(re4, "<li"); tooltip = re.exec(rawText); if (tooltip != null) { tip.innerHTML = tooltip; } } } }

function parseText { //Check to see if the XmlHttpRequests state is finished. if (getRequest.readyState == 4) { rawText = getRequest.responseText; var tip = document.getElementById('tfb'); tip.innerHTML = ttError("item"); if (rawText) { rawText = rawText.replace(crlf, ""); rawText = rawText.replace(re2, "1em; background: transparent url(http://ja.lotro.wikia.com/images/8/82/Ttip_Background.png); width:").replace(re3, "<li").replace(re4, "<li"); tooltip = re.exec(rawText); if (tooltip != null) { if (ttCompare) { rawSlot = tooltip[0].replace(reC, "$1"); if (rawSlot) { getInfo(ttSlot[slotByName(rawSlot)], 3); } } tip.innerHTML = tooltip; } else if (rawText.indexOf("redirectText") != -1) { // target is a redirect actualItem = rawText.replace(reR, "$1"); if (actualItem) { getInfo(actualItem, 1); return false; } tip.innerHTML = ttHTMLStart + "Error This item is being linked to through a redirect page. You must link directly to the item page. "; } else if (rawText.indexOf("noarticletext") != -1) { // target page does not exist tip.innerHTML = ttHTMLStart + "Error The target item's page does not exist. The page must be created in order to display a tooltip. "; } } displayTip; } }

function showItemTip(i) { var Span = document.getElementById( "tt" + i ); var ttLink = Span.parentNode; if (ttLink.getAttribute("class") != "selflink") { Span.setAttribute("title", ""); if (ttLink.getAttribute("title")) { itemname = ttLink.getAttribute("title"); ttLink.setAttribute("title", ""); newSpan = document.createElement("span"); newSpan.setAttribute("title", itemname); ttLink.appendChild(newSpan); } else { itemname = ttLink.lastChild.getAttribute("title"); } getInfo(itemname, 1); } }

function showSetTip(i) { var Span = document.getElementById( "stt" + i ); var ttLink = Span.parentNode; if (ttLink.getAttribute("class") != "selflink") { Span.setAttribute("title", ""); if (ttLink.getAttribute("title")) { setname = ttLink.getAttribute("title"); ttLink.setAttribute("title", ""); newSpan = document.createElement("span"); newSpan.setAttribute("title", setname); ttLink.appendChild(newSpan); } else { setname = ttLink.lastChild.getAttribute("title"); } getInfo(setname, 2); } }

function parseSetText { //Check to see if the XmlHttpRequests state is finished. if (getRequest.readyState == 4) { rawText = getRequest.responseText; var tip = document.getElementById('tfb'); tip.innerHTML = ttError("item set"); if (rawText) { rawText = rawText.replace(crlf, ""); rawText = rawText.replace(re2, "1em; background: transparent url(http://ja.lotro.wikia.com/images/8/82/Ttip_Background.png); width:"); tooltip = sre.exec(rawText); if (tooltip != null) { tip.innerHTML = tooltip; } } displayTip; } }

function ttMouseOver { if (ttCompare) { ttfdiv2 = document.createElement("div"); ttfdiv2.setAttribute("id", "tfb2"); contentstart.insertBefore(ttfdiv2, contentstart.childNodes[0]); } var Spans = document.getElementsByTagName( "span" ); for (var i = 0; i < Spans.length; i++) { if (hasClass(Spans[i], "itemlink")) { if (Spans[i].innerHTML.toLowerCase.indexOf("") == -1) { // don't show tooltip if on item page Spans[i].setAttribute("id", "tt" + i); Spans[i].onmouseover = showItemTip.bind(Spans[i],i); Spans[i].onmouseout = hideTip; Spans[i].onmousemove = moveTip; } } if (hasClass(Spans[i], "setlink")) { Spans[i].setAttribute("id", "stt" + i); Spans[i].onmouseover = showSetTip.bind(Spans[i],i); Spans[i].onmouseout = hideTip; Spans[i].onmousemove = moveTip; } } } ttMouseOver;

/*