-
Notifications
You must be signed in to change notification settings - Fork 0
/
tooltips.min.js
5 lines (5 loc) · 1.85 KB
/
tooltips.min.js
1
2
3
4
5
// https://github.com/ApkalluFalls/xivdb-tooltips
(function(){function h(a,b){var c=document.createElement("figure");c.id="tooltip";c.innerHTML=b;c.style.left=a.clientX+"px";c.style.top=a.clientY+"px";document.body.appendChild(c);document.body.addEventListener("mousemove",g)}var e=Array.from(document.querySelectorAll("[data-id][data-type]")),d={},f={},g=function(a){var b=document.getElementById("tooltip");if(!b)return console.warn("Mousemove still applied after elem removed");b.style.left=a.clientX+"px";b.style.top=a.clientY+"px"}.bind(this),k=function(a){if(a=
document.getElementById("tooltip"))document.body.removeEventListener("mousemove",g),a.parentElement.removeChild(a)}.bind(this),l=function(a){var b=a.target.dataset.id,c=a.target.dataset.type;if(!f||!f[c])return console.warn(c+" not found in response object.",f);var d=f[c].filter(function(a){return a.data.id===b});if(!d.length)return console.warn(b+" not found in response's "+c+" object.",f[c]);h(a,d[0].html)}.bind(this);e.forEach(function(a){var b=a.dataset;a:switch(b.type){case "achievement":case "action":case "emote":case "enemy":case "fate":case "gathering":case "instance":case "item":case "leve":case "npc":case "minion":case "mount":case "placename":case "quest":case "recipe":case "shop":case "status":case "title":case "weather":var c=
!0;break a;default:c=!1}c&&(d["list["+b.type+"]"]||(d["list["+b.type+"]"]=[]),-1===d["list["+b.type+"]"].indexOf(b.id)&&d["list["+b.type+"]"].push(b.id),a.addEventListener("mouseout",k),a.addEventListener("mouseover",l))});e=Object.keys(d);e.length&&(e.forEach(function(a){return d[a]=d[a].join(",")}),e=Object.keys(d).map(function(a){return a+"="+encodeURIComponent(d[a])}).join("&"),fetch("https://secure.xivdb.com/tooltip?"+e,{method:"GET",mode:"cors"}).then(function(a){return a.json()}).then(function(a){return f=
a})["catch"](function(a){return console.error(a)}))})();