-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.min.js
1 lines (1 loc) · 14.7 KB
/
popup.min.js
1
const apiBase="https://ffrkapi.azurewebsites.net/api/v1.0/",elementDict={0:"unknown",1:"",2:"-",3:"Dark",4:"Earth",5:"Fire",6:"Holy",7:"Ice",8:"Lightning",9:"NE",10:"Poison",11:"Pioson",12:"Water",13:"Wind",14:"Light.",15:"Earth",16:"Water"},schoolDict={0:"Unknown",2:"Bard",3:"Black Magic",4:"Celerity",5:"Combat",6:"Dancer",7:"Darkness",8:"Dragoon",9:"Heavy",10:"Knight",11:"Machinist",12:"Monk",13:"Ninja",14:"Samurai",15:"Sharpshooter",17:"Special",18:"Spellblade",19:"Summoning",20:"Support",21:"Thief",22:"White Magic",23:"Witch"},targetDict={0:"Unknown",1:"-",2:"All allies",3:"All enemies",4:"Ally with status",5:"Another ally",6:"Lowest HP% ally",7:"Random ally",8:"Random enemies",9:"Random enemy",10:"Self",11:"Single",12:"Single ally",13:"Single enemy",14:""},charIDs={tyro:1,warrior:2,knight:3,monk:4,"red mage":5,"black mage":6,magus:7,"white mage":8,devout:9,summoner:10,samurai:11,dragoon:12,"dark knight":13,spellblade:14,viking:15,berserker:16,ranger:17,"thief (core)":18,bard:19,ninja:20,gladiator:21,elarra:22,biggs:23,wedge:24,"dr. mog":25,"warrior of light":26,garland:27,sarah:28,wol:29,echo:30,master:31,matoya:32,meia:33,"thief (i)":34,firion:35,maria:36,guy:37,leon:38,minwu:39,gordon:40,leila:41,ricard:42,josef:43,emperor:44,hilda:45,scott:46,luneth:47,arc:48,refia:49,ingus:50,desch:51,"onion knight":52,"cloud of darkness":53,aria:54,"cecil (dark knight)":55,"cecil (paladin)":56,kain:57,rydia:58,rosa:59,edward:60,yang:61,palom:62,porom:63,tellah:64,edge:65,fusoya:66,golbez:67,"cid (iv)":68,ceodore:69,rubicante:70,ursula:71,barbariccia:72,lenna:73,galuf:74,"gogo (v)":75,gilgamesh:76,bartz:77,faris:78,dorgann:79,exdeath:80,krile:81,xezat:82,kelger:83,terra:84,locke:85,celes:86,mog:87,edgar:88,sabin:89,shadow:90,cyan:91,gau:92,setzer:93,strago:94,relm:95,"gogo (vi)":96,umaro:97,kefka:98,leo:99,cloud:100,barret:101,tifa:102,aerith:103,"red xiii":104,yuffie:105,"cait sith":106,vincent:107,zack:108,sephiroth:109,"cid (vii)":110,reno:111,angeal:112,rufus:113,shelke:114,rude:115,elena:116,squall:117,rinoa:118,quistis:119,zell:120,selphie:121,irvine:122,seifer:123,laguna:124,edea:125,raijin:126,fujin:127,kiros:128,ward:129,ultimecia:130,zidane:131,garnet:132,vivi:133,steiner:134,freya:135,quina:136,eiko:137,amarant:138,beatrix:139,kuja:140,marcus:141,tidus:142,yuna:143,wakka:144,lulu:145,kimahri:146,rikku:147,auron:148,jecht:149,braska:150,paine:151,seymour:152,shantotto:153,ayame:154,curilla:155,prishe:156,lion:157,aphmau:158,zeid:159,lilisette:160,vaan:161,balthier:162,fran:163,basch:164,ashe:165,penelo:166,gabranth:167,larsa:168,vayne:169,reks:170,lightning:171,snow:172,vanille:173,sazh:174,hope:175,fang:176,serah:177,"cid raines":178,noel:179,nabaat:180,"y'shtola":181,thancred:182,yda:183,papalymo:184,alphinaud:185,minfilia:186,"cid (xiv)":187,ysayle:188,haurchefant:189,estinien:190,noctis:191,gladiolus:192,ignis:193,prompto:194,iris:195,aranea:196,ramza:197,agrias:198,delita:199,ovelia:200,mustadio:201,orlandeau:202,gaffgarion:203,rapha:204,marach:205,meliadoul:206,marche:207,montblanc:208,alma:209,orran:210,ace:211,deuce:212,nine:213,machina:214,rem:215,queen:216,king:217,cinque:218,seven:219,sice:220,jack:221,eight:222,cater:223,sora:224,riku:225,roxas:226,axel:227,reynn:228,lann:229,morrow:230,aemo:231,wrieg:232,tama:233,enna:234},characterAliases={"onion knight":["ok","onion knight","onion"],orlandeau:["tg cid","tgc"],"cecil (dark knight)":["decil","dcecil","dark knight cecil","cecil dark knight"],"cecil (paladin)":["pecil","pcecil","paladin cecil","cecil paladin"],gilgamesh:"greg",aerith:"aeris","cid (iv)":["cid iv","cid4","cid 4"],"cid (xiv)":["cid xiv","cid 14","cid14"],"cid (vii)":["cid vii","cid7","cid 7"],elarra:"urara",barbariccia:"barb","cloud of darkness":"cod","red xiii":["nanaki","red13","red 13"],"gogo (v)":["gogo v","gogo5","gogo 5"],"gogo (vi)":["gogo vi","gogo6","gogo 6"]},abilityAliases={"bahamut (v)":["bahamut","bahamut5","bahamut v"],"bahamut (vi)":["bahamut6","bahamut vi"],voltech:["vortex"]},ignoredStatuses=["Remove","Reraise","Haste","Burst Mode","Imp","Attach","Blink"],sbRegex=/SB|SSB|BSB|USB|CSB|chain|OSB|AOSB|ASB|UOSB|GSB|FSB|AASB|Glint/gi,cmdRegex=/SB|SSB|BSB|USB|CSB|chain|OSB|AOSB|ASB|UOSB|GSB|FSB|AASB|Glint|lm|lmr|abil|ability|rm|stat|char/gi;function parseRequests(e){let t=[];if(e.includes(";")){e.split(";").forEach(function(e){e=e.trim(),t.push(getParts(e))})}else t.push(getParts(e));return t}function getParts(e){let t=[],a=e.trim().split(" "),r=a.pop().toLowerCase();return r.match(cmdRegex)?(t[0]=searchAliases(characterAliases,a.join(" ").toLowerCase()),t[1]=r,t):e}function parseSBRequest(e){let t=e[0],a=e[1],r=getCharacterID(t);if(-1===r)return Promise.reject(new Error(`${t} is not a valid character name`));if("sb"===a){return getTierSBsForCharID(r,{tierID:0},e)}if(a.match(sbRegex)){return getTierSBsForCharID(r,filterSBTier(a),e)}return Promise.reject(new Error(`${t} ${a} is not a valid request`))}function filterSBTier(e){let t=e.toLowerCase(),a={index:0};switch(hasNumber(t)&&(a.index=t.charAt(t.length-1),t=t.substring(0,t.length-1)),a.tierName=t,t){case"ssb":a.tierID=5;break;case"bsb":a.tierID=6;break;case"osb":a.tierID=7;break;case"usb":a.tierID=8;break;case"chain":case"csb":case"lcsb":a.tierID=9;break;case"glint":case"gsb":case"fsb":a.tierID=10;break;case"aosb":case"uosb":case"asb":a.tierID=12;break;case"aasb":a.tierID=13}return a}function hasNumber(e){return/\d/.test(e)}function statusAllowed(e){let t=!0;for(let a=0;a<ignoredStatuses.length;a++)if(e.includes(ignoredStatuses[a])){t=!1;break}return t}function findStatusInText(e){let t=[];if(e.includes("grants")){(t=e.split("grants")[1].split("to")[0].split(","))[t.length-1].includes("and")&&(t.push(t[t.length-1].split("and")[1]),t[t.length-2]=t[t.length-2].split("and")[0]);for(let e=0;e<t.length;e++)t[e]=t[e].trim()}return t}function searchAliases(e,t){if("WoL"===t)return"warrior of light";for(key in e)e[key].includes(t.toLowerCase())&&(t=key);return t}function getCharacterID(e){return charIDs[e]?charIDs[e]:-1}function getTierSBsForCharID(e,t,a){return new Promise(function(r,s){$.getJSON(apiBase+"/SoulBreaks/Character/"+e,function(e){let i="",n=[];0===t.tierID?e.forEach(e=>{i+=formatSBJSON(e)}):0===t.index?e.forEach(e=>{e.soulBreakTier===t.tierID&&(i+=formatSBJSON(e))}):(console.log(typeof e),console.log("index 1 of json: "+e[1]),e.forEach(e=>{e.soulBreakTier===t.tierID&&n.push(e)}),n.length>t.index-1?i+=formatSBJSON(n[t.index-1]):s(new Error(`${a[0]} does not have ${t.index} ${a[1].replace(/[0-9]/g,"")}s`))),r(i)})})}function getLMsForChar(e){let t=getCharacterID(e[0]);return-1===t?Promise.reject(new Error(e[0]+" is not a valid character name")):new Promise(function(a,r){$.getJSON(`${apiBase}/LegendMaterias/Character/${t}`,function(t){let r=`<div class='sb-result result'><h3 class='character__name'>${t[0].characterName}</h3>`,s=0;e[1].includes("lmr")&&(t=t.slice(2)),hasNumber(e[1])&&(s=sbTier.charAt(sbTier.length-1)),t.forEach(e=>{r+=formatLMJSON(e)}),a(r+="</div>")})})}function getSoulBreak(e){return new Promise(function(t,a){$.getJSON(`${apiBase}/SoulBreaks/Name/${e}`,function(r){let s="";0===r.length?a(new Error(`There is no soul break named ${e}`)):(r.forEach(e=>{s+=formatSBJSON(e)}),t(s))})})}function getAbility(e,t){let a=searchAliases(abilityAliases,e.toLowerCase());if(a in t){let e=t[a];return new Promise(function(t,a){$.getJSON(`${apiBase}/Abilities/${e}`,function(e){let a="";e.forEach(e=>{a+=formatAbilityJSON(e)}),t(a)})})}return Promise.reject(new Error(`${e} is not an acceptable ability name`))}function getRecordMateria(e){return new Promise(function(t,a){$.getJSON(`${apiBase}/RecordMaterias/Name/${e}`,function(e){let a="";e.forEach(e=>{a+=formatRMJSON(e)}),t(a)})})}function getStatus(e){return new Promise(function(t,a){$.getJSON(`${apiBase}/Statuses/CommonName/${e}`,function(e){let a="";e.forEach(e=>{a+=formatStatusJSON(e)}),t(a)})})}function getCharacter(e){return new Promise(function(t,a){let r=getCharacterID(e);if(-1===r)return Promise.reject(new Error(`${e} is not a valid character name`));$.getJSON(`${apiBase}/Characters/${r}`,function(e){let a=[],r=e[0].SchoolAccessInfos;for(let e=0;e<r.length;e++)if(r[e].AccessLevel>0){let t={};t.schoolName=r[e].SchoolName,t.accessLevel=r[e].AccessLevel,a.push(t)}let s=`<div class='result'><h3 class='result__name'>${e[0].Description}</h3>${formatSchoolTableJSON(a)}`;for(let t=0;t<e[0].RecordSpheres.length;t++){console.log(`${e[0].RecordSpheres[t].RecordSphereName} Levels: ${e[0].RecordSpheres[t].RecordSphereLevels} Length: ${e[0].RecordSpheres[t].RecordSphereLevels.length}`);for(let a=0;a<e[0].RecordSpheres[t].RecordSphereLevels.length;a++)e[0].RecordSpheres[t].RecordSphereLevels[a].Benefit.includes(String.fromCharCode(9733))&&(s+=`<p>${e[0].RecordSpheres[t].RecordSphereLevels[a].Benefit}</p>`)}t(s+="</div>")})})}function getCommands(e){let t="<div class='cmds border-top'>";for(let a=0;a<e.length;a++)t+="<div class='cmd'><img class='cmd__icon' src='"+e[a].imagePath.split('"')[0]+"'/>",t+=`<p class='cmd__effect'>${e[a].effects}</p></div>`,t+="<div class='cmd'><span class='margin-right'>",t+=`School - ${schoolDict[e[a].school]}</span>`,t+=`<span>${formatElements(e[a])}</span>`,t+="</div>",t+="<div class='cmd",a!==e.length-1?t+=" border-bottom'>":t+="'>",t+=`<span class='margin-right'>Multiplier - ${e[a].multiplier}</span>`,t+=`<span>Cast Time - ${e[a].castTime}</span></div>`;return t+="</div>"}function getSBStatuses(e,t,a){let r="<div class='status'>";for(let a=0;a<e.length;a++)if("Brave Mode"===e[a].description){if(r+="<span class='status__name'>"+e[a].description+"</span>",t[0]){r+="<p class='braveMode__condition'>Condition - "+t[0].braveCondition+"</p>",r+="<div class='flex'><span class='margin-right braveMode__castTime'>Cast Time - "+t[0].castTime+"</span>",r+="<span class='braveMode__elements'>",r+=formatElements(t[0]),r+="</span></div>";for(let e=0;e<t.length;e++)0===e&&(r+="<p class='braveMode__desc'>"+t[e].braveActionName+"</p>"),r+="<p class='braveMode__effects'>"+t[e].braveLevel+" - "+t[e].effects+"</p>"}}else statusAllowed(e[a].description)&&(r+="<span class='status__name'>"+e[a].description+"</span>",r+="<p class='status__effect'>"+e[a].effects+"</p>");return r+="</div>"}function getOtherEffects(e){let t="<div class='otherEffects'>";for(let a=0;a<e.length;a++)"Attack"!==e[a].description&&(t+="<span class='status__name'>"+e[a].description,e[a].elements.length>0?(t+=" - (",t+=formatElements(e[a]),t+=")</span>"):t+="</span>",t+="<p class='otherEffects__effect'>"+e[a].effects+"</p>");return t+="</div>"}function formatSBJSON(e){let t="<div class='sb-result'>",a=`<div class='sb'><h3 class='sb-result__name'>${e.description}</h3>`,r="<div class='sb-main'><img class='sb-result__icon' src='"+e.imagePath.split('"')[0]+"'/>",s=`<p class='sb-result__effect'>${e.effects}</p></div>`,i=`<div class='flex'><span class='margin-right entry__castTime'>Cast Time - ${e.castTime}</span><span class='entry__elements'>${formatElements(e)}</span></div></div>`,n="",o="",c="";if(0!==e.commands.length&&(n=getCommands(e.commands)),e.statuses){let t=findStatusInText(e.effects);o=getSBStatuses(e.statuses,e.braveActions,t)}return e.otherEffects&&(c=getOtherEffects(e.otherEffects)),t+=a+r+s+i+o+c+n+"</div>"}function formatCharacterJSON(e){}function formatSchoolTableJSON(e){let t="<table class='info' border='1'><thead><tr><th>School</th><th>Access Level</th></tr></thead><tbody class='center'>";for(let a=0;a<e.length;a++)t+=`<tr><td>${e[a].schoolName}</td><td>${e[a].accessLevel}</td></tr>`,a===e.length-1&&(t+="</tbody></table>");return t}function formatLMJSON(e){let t="";return t+="<div class='lm'><h4 class='lm__name'>"+e.description+"</h4>"+("<div class='lm__container'><img class='cmd__icon' src='"+e.imagePath.split('"')[0]+"'/>")+("<p class='lm__effect'>"+e.effect+"</p></div></div>")}function formatRMJSON(e){return"<div class='result'>"+("<h3 class='result__name'>"+e.recordMateriaName+"</h3>")+("<div class='icon-container'><img class='icon' src='"+e.imagePath.split('"')[0]+"'/>")+("<p class='effect'>"+e.effect+"</p></div>")+("<p class='info'>Unlock Criteria - "+e.unlockCriteria+"</p>")+"</div>"}function formatStatusJSON(e,t){let a="<h3 class='result__name'>"+e.commonName+"</h3>",r="<div><p class='effect'>"+e.effects+"</p></div>";return"append"===t?a+r:"<div class='result'>"+a+r+"</div>"}function formatAbilityJSON(e){let t="<h3 class='result__name'>"+e.abilityName+"</h3>",a="<div class='icon-container'><img class='icon' src='"+e.imagePath.split('"')[0]+"'/>",r="<p class='effect'>"+e.effects+"</p></div>",s="<div class='flex'>",i="<span class='margin-right info'>Cast Time - "+e.castTime+"</span>",n="<span class='elements info'>Elements - "+formatElements(e)+"</span>",o="<span class='info'>Total Multiplier - "+e.multiplier+"</span>";return"<div class='result'>"+t+a+r+s+i+n+"</div>"+s+("<span class='margin-right info'>School - "+schoolDict[e.school]+"</span>")+o+"</div>"+s+("<span class='margin-right info'>SB Gain - "+e.soulBreakPointsGained+"</span>")+("<span class='info'>Target - "+targetDict[e.targetType]+"</span>")+"</div>"+formatOrbRequirements(e)+"</div>"}function createAbilityDict(){let e={};return new Promise(function(t,a){$.getJSON(apiBase+"IdLists/Ability",function(a){a.forEach(t=>{e[t.value.toLowerCase()]=t.key}),t(e)})})}function parseElementNumber(e){let t=elementDict[e];return"-"===t?"NE":t}function formatElements(e){let t="";for(let a=0;a<e.elements.length;a++)t+=parseElementNumber(e.elements[a]),a!==e.elements.length-1&&(t+=", ");return t}function formatOrbRequirements(e){let t="<tr><th>Rank</th>",a="<tbody class='center'><tr><td>R1</td>",r="<tr><td>R2</td>",s="<tr><td>R3</td>",i="<tr><td>R4</td>",n="<tr><td>R5</td>";for(let o=0;o<e.orbRequirements.length;o++)switch(o%5){case 0:"Ability Record"!==e.orbRequirements[o].orbName&&(t+="<th>"+e.orbRequirements[o].orbName+"</th>",a+="<td>"+e.orbRequirements[o].orbCount+"</td>");break;case 1:r+="<td>"+e.orbRequirements[o].orbCount+"</td>";break;case 2:s+="<td>"+e.orbRequirements[o].orbCount+"</td>";break;case 3:i+="<td>"+e.orbRequirements[o].orbCount+"</td>";break;case 4:n+="<td>"+e.orbRequirements[o].orbCount+"</td>"}return"<p class='info'>Hone Requirements</p><table class='info' border='1'><thead>"+(t+="</tr></thead>")+a+r+s+i+(n+="</tbody></table>")}$(function(){Promise.resolve();let e={};createAbilityDict().then(function(t){e=t}),$("#search-button").click(function(t){t.preventDefault();let a=$("#search-text").val();$("#results").html("");let r=parseRequests(a),s=Promise.resolve();r.forEach(function(t){s=s.then(function(){return t.length>1&&t[1].match(sbRegex)?parseSBRequest(t):t.length>1&&"lm"===t[1]||"lmr"===t[1]?getLMsForChar(t):t.length>1&&"abil"===t[1]||"ability"===t[1]?getAbility(t[0],e):t.length>1&&"rm"===t[1]?getRecordMateria(t[0]):t.length>1&&"stat"===t[1]?getStatus(t[0]):t.length>1&&"char"===t[1]?getCharacter(t[0]):getSoulBreak(t)}).then(function(e){$("#results").append(e)}).catch(function(e){let t=`<div class='sb-result result'><span class='error'>${e}</span></div>`;$("#results").append(t)})})})});