-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.min.js
1 lines (1 loc) · 9.81 KB
/
script.min.js
1
function toggleType(e){function a(a){a.push(e.attributes.skilltag.value)}function s(a){for(var s=0;s<a.length;s++)if(a[s]==e.attributes.skilltag.value){a.splice(s,1);break}}if(e.classList.contains("chip")){var l;switch(l=null==e.classList[1]?0:parseInt(e.classList[1]),l){case 0:a(enabledTypes),e.classList.add("1");break;case 1:s(enabledTypes),a(disabledTypes),e.classList.remove("1"),e.classList.add("2");break;case 2:s(disabledTypes),e.classList.remove("2")}storeSearchParams(),filterSkills(),searchSkills(previousSearch),displaySkills(),updateSkillCount()}}function toggleWeaponType(e){function a(a){a.push(e.attributes.weapontag.value)}function s(a){for(var s=0;s<a.length;s++)if(a[s]==e.attributes.weapontag.value)return void a.splice(s,1)}if(e.classList.contains("chip")){var l;switch(l=null==e.classList[1]?0:parseInt(e.classList[1]),l){case 0:a(enabledWeaponTypes),e.classList.add("1");break;case 1:s(enabledWeaponTypes),a(disabledWeaponTypes),e.classList.remove("1"),e.classList.add("2");break;case 2:s(disabledWeaponTypes),e.classList.remove("2")}storeSearchParams(),filterSkills(),searchSkills(previousSearch),displaySkills(),updateSkillCount()}}function filterSkills(){if(skills=bDataset?skillsFetchFull.slice():skillsFetch.slice(),0!=enabledTypes.length||0!=disabledTypes.length){for(var e=0;e<disabledTypes.length;e++)for(var a=0;a<skills.length;a++)for(var s=0;s<skills[a].Tags.length;s++){if(skills[a].Tags[s]==disabledTypes[e]){skills.splice(a,1),a--;break}if(s==skills[a].Tags.length-1)break}for(e=0;e<enabledTypes.length;e++)for(a=0;a<skills.length;a++)for(s=0;s<skills[a].Tags.length&&skills[a].Tags[s]!=enabledTypes[e];s++)if(s==skills[a].Tags.length-1){skills.splice(a,1),a--;break}}if(0!=enabledWeaponTypes.length||0!=disabledWeaponTypes.length){for(e=0;e<disabledWeaponTypes.length;e++)for(a=0;a<skills.length;a++)for(s=0;s<skills[a].WeaponTags.length;s++){if(skills[a].WeaponTags[s]==disabledWeaponTypes[e]){skills.splice(a,1),a--;break}if(s==skills[a].WeaponTags.length-1)break}for(e=0;e<enabledWeaponTypes.length;e++)for(a=0;a<skills.length;a++)for(s=0;s<skills[a].WeaponTags.length&&skills[a].WeaponTags[s]!=enabledWeaponTypes[e];s++)if(s==skills[a].WeaponTags.length-1){skills.splice(a,1),a--;break}}}function searchChange(e){previousSearch.length<e.length?(previousSearch=e,searchSkills(e),displaySkills(),updateSkillCount()):(previousSearch=e,filterSkills(),searchSkills(e),displaySkills(),updateSkillCount()),storeSearchParams()}function searchSkills(e){if(""!=e)for(var a=0;a<skills.length;a++){var s=skills[a].Name.toLowerCase();-1==s.search(e.toLowerCase())&&(skills.splice(a,1),a--)}}async function displaySkills(){DisplayCanelled=!0,await new Promise(e=>setTimeout(e,1)),skillListElement.innerHTML="",DisplayCanelled=!1;for(var e=0;e<skills.length&&!DisplayCanelled;e++)createSkillIcon(e),e%25==0&&await new Promise(e=>setTimeout(e,1))}function createSkillIcon(e){var a=document.createElement("a");a.classList.add("skill"),a.setAttribute("i",e),a.href="https://www.poewiki.net/wiki/"+skills[e].Name.replace(/ /g,"_").replace(/'/g,"%27");var s=document.createElement("div");s.classList.add("icon");var l=skills[e].IconId%iconPositionsPerRow,t=(skills[e].IconId-l)/iconPositionsPerRow;s.style.backgroundPosition=l*-iconSize+"px "+t*-iconSize+"px";var i=document.createElement("p");i.innerText=skills[e].Name,a.appendChild(s),a.appendChild(i),skillListElement.appendChild(a),addSkillMenuEvents(a)}function getAndDisplaySkills(){fetch("data.json").then(e=>e.json()).then(e=>{skillsFetch=e,skills=e,filterSkills(),searchSkills(previousSearch),displaySkills(),updateSkillCount()}).then(fetch("data_full.json").then(e=>e.json()).then(e=>{skillsFetchFull=e,applySearchParams()}))}function addSkillMenuEvents(e){e.addEventListener("mouseover",function(a){var s=document.getElementById("skillMenu");return targetName=e.lastChild.innerText,targetDescription=this.attributes.href.nodeValue,document.getElementById("skillMenuName").innerText=targetName,document.getElementById("skillMenuDescription").innerText=skills[e.attributes.i.value].Description,document.getElementById("skillMenuSkillTags").innerText=skillTagsToString(skills[e.attributes.i.value].Tags),document.getElementById("skillMenuWeaponTags").innerText=weaponTagsToString(skills[e.attributes.i.value].WeaponTags),s.style.display="block",s.style.left=a.pageX+20+"px",s.style.left=e.getBoundingClientRect().x+74+"px",a.clientY>window.innerHeight-200?(s.style.top=a.pageY-155+"px",s.style.top=e.getBoundingClientRect().y-document.body.getBoundingClientRect().y-s.getBoundingClientRect().height+"px"):(s.style.top=a.pageY+"px",s.style.top=e.getBoundingClientRect().y-document.body.getBoundingClientRect().y+"px"),!1},!1),e.addEventListener("mouseout",function(e){var a=document.getElementById("skillMenu");return a.style.display="none",!1},!1)}function skillTagsToString(e){var a="";if(0==e.length)return"No Skill Tags";for(var s of e)switch(s){case 0:a+="Attack, ";break;case 1:a+="Spell, ";break;case 2:a+="Projectile, ";break;case 4:a+="Buff, ";break;case 5:a+="Minion, ";break;case 7:a+="Area, ";break;case 8:a+="Duration, ";break;case 9:a+="Shield, ";break;case 18:a+="Chaining, ";break;case 19:a+="Melee, ";break;case 20:a+="Strike, ";break;case 25:a+="Totem, ";break;case 27:a+="Physical, ";break;case 28:a+="Fire, ";break;case 29:a+="Cold, ";break;case 30:a+="Lightning, ";break;case 32:a+="Trap, ";break;case 33:a+="Movement, ";break;case 34:a+="Damage Over Time, ";break;case 35:a+="Mine, ";break;case 36:a+="Trigger, ";break;case 37:a+="Vaal, ";break;case 38:a+="Aura, ";break;case 41:a+="Chaos, ";break;case 47:a+="Channelling, ";break;case 50:a+="Golem, ";break;case 62:a+="Warcry, ";break;case 63:a+="Instant, ";break;case 64:a+="Brand, ";break;case 68:a+="Curse, ";break;case 77:a+="Guard, ";break;case 78:a+="Travel, ";break;case 79:a+="Blink, ";break;case 83:a+="Nova, ";break;case 91:a+="Slam, ";break;case 96:a+="Hex, ";break;case 97:a+="Mark, ";break;case 99:a+="Orb, ";break;case 101:a+="Prismatic, ";break;case 103:a+="Arcane, ";break;case 106:a+="Link, "}return a=a.substring(0,a.length-2),a}function weaponTagsToString(e){var a="";if(0==e.length)return"Any Weapon";for(var s of e)switch(s){case 6:a+="Claw, ";break;case 7:a+="Dagger, ";break;case 8:a+="Wand, ";break;case 9:a+="One Hand Sword, ";break;case 10:a+="Thrusting One Hand Sword, ";break;case 11:a+="One Hand Axe, ";break;case 12:a+="One Hand Mace, ";break;case 13:a+="Bow, ";break;case 14:a+="Staff, ";break;case 15:a+="Two Hand Sword, ";break;case 16:a+="Two Hand Axe, ";break;case 17:a+="Two Hand Mace, ";break;case 26:a+="Shield, ";break;case 32:a+="Sceptre, ";break;case 36:a+="Unarmed, ";break;case 56:a+="Rune Dagger, ";break;case 57:a+="Warstaff, "}return a=a.substring(0,a.length-2),a}function updateSkillCount(){var e=skills.length;e!=skillCountDisplay&&(element=document.getElementById("matchingSkillsHeader"),skillCountDisplay>e?skillCountDisplay-=Math.ceil(.05*(skillCountDisplay-e)):skillCountDisplay+=Math.ceil(.05*(e-skillCountDisplay)),element.innerText=skillCountDisplay+" Matching Skills:",requestAnimationFrame(updateSkillCount))}function toggleDataset(e){if(e.classList.contains("chip")){var a;switch(a=null==e.classList[1]?0:1,a){case 0:bDataset=!0,e.classList.add("1");break;case 1:bDataset=!1,e.classList.remove("1")}storeSearchParams(),filterSkills(),searchSkills(previousSearch),displaySkills(),updateSkillCount()}}function applySearchParams(){URLSearchParams.forEach(function(e,a){var s=e.split(",");if(s[0].length>0)switch(a){case"es":enabledTypes=s,enabledTypes.forEach(e=>{setStyle(e,"skill",1)});break;case"ds":disabledTypes=s,disabledTypes.forEach(e=>{setStyle(e,"skill",2)});break;case"ew":enabledWeaponTypes=s,enabledWeaponTypes.forEach(e=>{setStyle(e,"weapon",1)});break;case"dw":disabledWeaponTypes=s,disabledWeaponTypes.forEach(e=>{setStyle(e,"weapon",2)});break;case"d":bDataset="true"==s[0],bDataset&&document.querySelector('button[onclick="toggleDataset(this);"]').classList.add(1);break;case"s":previousSearch=s.join(),document.getElementById("skillNameSearch").value=previousSearch}filterSkills(),searchSkills(previousSearch)})}function setStyle(e,a,s){"skill"==a?document.querySelector('button[skilltag="'+e+'"]').classList.add(s):document.querySelector('button[weapontag="'+e+'"]').classList.add(s)}function storeSearchParams(){URLSearchParams.set("es",enabledTypes),URLSearchParams.set("ds",disabledTypes),URLSearchParams.set("ew",enabledWeaponTypes),URLSearchParams.set("dw",disabledWeaponTypes),URLSearchParams.set("d",bDataset),URLSearchParams.set("s",previousSearch),history.replaceState({},"",location.pathname+"?"+URLSearchParams.toString())}function resetFilter(){elements=document.querySelectorAll("button.chip"),elements.forEach(e=>{for(let a=0;a<e.classList.length;a++)a>0&&e.classList.remove(e.classList[a])}),document.getElementById("skillNameSearch").value="",enabledTypes=[],disabledTypes=[],enabledWeaponTypes=[],disabledWeaponTypes=[],bDataset=!1,previousSearch="",filterSkills(),displaySkills(),updateSkillCount(),storeSearchParams()}function collapseTagSection(e){var a=getComputedStyle(e).height;e.style.height=a,e.offsetWidth,e.style.height="0px"}function expandTagSection(e){e.style.height="initial";var a=getComputedStyle(e).height;e.style.height="0px",e.offsetWidth,e.style.height=a,setTimeout(function(){removeHeight(e)},150)}function removeHeight(e){"0px"!=e.style.height&&(e.style.height=null)}function collapse(e){collapseTagSection(e.parentElement.lastElementChild),e.onclick=function(){expand(e)},e.style.opacity=.5}function expand(e){expandTagSection(e.parentElement.lastElementChild),e.onclick=function(){collapse(e)},e.style.opacity=1}skillListElement=document.getElementById("skilllist");var skills,skillsFetch,skillsFetchFull,bDataset=!1,previousSearch="",skillCountDisplay=520,DisplayCanelled=!1;getAndDisplaySkills(),enabledTypes=[9001],disabledTypes=[],enabledWeaponTypes=[],disabledWeaponTypes=[];var URLSearchParams=new URLSearchParams(window.location.search),iconPositionsPerRow=24,iconSize=64;