From da61bf68d93ee8deb5242555c2ac7808385f57b4 Mon Sep 17 00:00:00 2001 From: dginovker Date: Thu, 10 Dec 2020 15:13:48 -0500 Subject: [PATCH] Added rank showing and better filters to match it --- services/m=hiscore/helpers.js | 13 +++++- services/m=hiscore/hiscores.html | 5 ++- services/m=hiscore/hiscores.js | 42 +++++++++++++++--- site/css/hiscores-17.css | 6 +-- site/img/hiscores/search_custom_largeeccb.png | Bin 601 -> 627 bytes 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/services/m=hiscore/helpers.js b/services/m=hiscore/helpers.js index 032f14eaa..fdd233364 100644 --- a/services/m=hiscore/helpers.js +++ b/services/m=hiscore/helpers.js @@ -30,7 +30,7 @@ hiscores.sName = [ hiscores.page = 0; hiscores.currentSkillId = ""; -hiscores.apiURL = "https://18f35cfbb30b.ngrok.io"; +hiscores.apiURL = "http://localhost:3000"; hiscores.tableData = []; hiscores.defaultTableData = []; @@ -84,7 +84,6 @@ hiscores.initalizeRightsideButtons = () => { document.getElementById("filter_submit").addEventListener("click", function (e) { e.preventDefault(); - hiscores.page++; let pageRemovedFiltersLocation = window.location.search.split(/\?iron=[A-z]+|\?ultiron=[A-z]+|\?hciron=[A-z]+|\?maxXP=\d+/).join(''); const ironparam = `?iron=${document.getElementById('check_iron').checked}`; const ultironparam = `?ultiron=${document.getElementById('check_ultiron').checked}`; @@ -92,6 +91,16 @@ hiscores.initalizeRightsideButtons = () => { const maxXP = `?maxXP=${document.getElementById("maxXP").value}`; window.location.replace(`./hiscores.html${pageRemovedFiltersLocation}${ironparam}${ultironparam}${hcironparam}${maxXP}`); }); + + if (document.getElementById("filter_clear")) { + console.log("filter clear is here"); + // Filter clear only appears when filters are present + document.getElementById("filter_clear").addEventListener("click", function (e) { + e.preventDefault(); + let pageRemovedFiltersLocation = window.location.search.split(/\?iron=[A-z]+|\?ultiron=[A-z]+|\?hciron=[A-z]+|\?maxXP=\d+/).join(''); + window.location.replace(`./hiscores.html${pageRemovedFiltersLocation}`); + }) + } } hiscores.filter = (result) => { diff --git a/services/m=hiscore/hiscores.html b/services/m=hiscore/hiscores.html index 3d9bde68a..1ff65b3b2 100644 --- a/services/m=hiscore/hiscores.html +++ b/services/m=hiscore/hiscores.html @@ -587,7 +587,7 @@ English
Filter
-
+
+
+ +
Legend
diff --git a/services/m=hiscore/hiscores.js b/services/m=hiscore/hiscores.js index 3812797e5..d238d09c4 100644 --- a/services/m=hiscore/hiscores.js +++ b/services/m=hiscore/hiscores.js @@ -45,6 +45,14 @@ hiscores.loadUserTable = (username) => { hiscores.populatePlayerHSTable(); hiscores.setHeadSkillText(hiscores.formatName(username, 0, result.info.exp_multiplier, true)); }) + .then(() => { + // Now get the player ranks (done seperately) + fetch(`${hiscores.apiURL}/highscores/rankedMap`) + .then(response => response.json()) + .then(result => { + hiscores.populatePlayerRanks(username, result); + }) + }) .catch(error => { document.getElementById('search_name').style.color = 'red'; console.log('error', error); @@ -71,7 +79,7 @@ hiscores.populatePlayerHSTable = () => { row.childNodes[1].replaceWith(document.createElement("td")); row.childNodes[1].className = "rankCol"; - row.childNodes[1].innerHTML = "0"; + row.childNodes[1].innerHTML = ""; row.childNodes[3].replaceWith(document.createElement("td")); row.childNodes[3].className = "alL"; @@ -87,6 +95,18 @@ hiscores.populatePlayerHSTable = () => { } } +hiscores.populatePlayerRanks = (username, result) => { + for (let i = 1; i <= 24; i++) { + result[i - 1] = hiscores.filter(result[i - 1]); + row = document.getElementsByClassName(`row row${i}`)[0]; + + row.childNodes[1].replaceWith(document.createElement("td")); + row.childNodes[1].className = "rankCol"; + let rank = (result[i - 1].findIndex(player => player.username === username) + 1) + row.childNodes[1].innerHTML = rank ? rank : i % 2 === 1 ? "N/A" : "Bad Filter"; + } +} + hiscores.loadSkillTable = (skillId) => { fetch(`${hiscores.apiURL}/highscores/playersBySkill/${skillId}`) .then(response => response.json()) @@ -125,9 +145,6 @@ hiscores.populateSkillHSTable = () => { } } -hiscores.initializePageArrows(); -hiscores.initalizeRightsideButtons(); -hiscores.linkLeftTabSkillNames(); /** * In URL ?player=guthix, passing param "player" will return "guthix" @@ -153,8 +170,16 @@ if (getParam("skill")) { } if (getParam("iron")) { - document.getElementById("filter_submit").value = "Filter"; document.getElementById('check_iron').checked = getParam("iron") === "true"; + + document.getElementById("filter_submit").value = "Filter"; + document.getElementById("filter_div").style.height = "134px"; + // Add disable button + document.getElementById("filter_clear_div").innerHTML = `` +} else { + document.getElementById("filter_clear_div").innerHTML = ""; + // Change width to 134 minus button size + document.getElementById("filter_div").style.height = "110px"; } if (getParam("ultiron")) { document.getElementById('check_ultiron').checked = getParam("ultiron") === "true"; @@ -165,4 +190,9 @@ if (getParam("hciron")) { if (getParam("maxXP")) { document.getElementById('maxXP').value = getParam("maxXP"); document.getElementById('maxXPoutput').innerHTML = getParam("maxXP"); -} \ No newline at end of file +} + + +hiscores.initializePageArrows(); +hiscores.initalizeRightsideButtons(); +hiscores.linkLeftTabSkillNames(); diff --git a/site/css/hiscores-17.css b/site/css/hiscores-17.css index 2752cd97c..c0d429fac 100644 --- a/site/css/hiscores-17.css +++ b/site/css/hiscores-17.css @@ -605,11 +605,11 @@ background: transparent url(../img/hiscores/search_largeeccb.png?3) repeat-x; } .search_tiny_bit_more_large { - height: 114px; - background: transparent url(../img/hiscores/search_tiny_bit_more_largeeccb.png?3) repeat-x; + height: 134px; + background: transparent url(../img/hiscores/search_custom_largeeccb.png?3) repeat-x; } .search_custom_large { - height: 122px; + height: 102px; background: transparent url(../img/hiscores/search_custom_largeeccb.png?3) repeat-x; } #friends_search { diff --git a/site/img/hiscores/search_custom_largeeccb.png b/site/img/hiscores/search_custom_largeeccb.png index 7f1ec04e9f5aad977831acf31e6adab16ef03f94..01cce20d04d20d0892d43bfd83d49af1376557bb 100644 GIT binary patch delta 615 zcmV-t0+{{T1oH%t7k{7#1^@s6%~b}%0004QX+uL$X=7sm04R}lkvmHRK@^3*L?sd< zDYOu=NTFh(5F&`B#v)CS5EYEtY&I_;8<*V#3ATcbgB~Nq*het3f`~7Qw-G66i`iHiaWB>pF32;bRa{vGf z5dZ)S5dnW>Uy%R+0INwvK~yLeb&=5#fG`L{dyeBM&fxxQAcUq3sDAVc;RUGUzD_%a ze{$F`hE@dBd5UVinJugfjVN_az5KFA^^?9!kQ`cumFC!}^=Ol-O2X~jD*SMpVNo-e zbss{qzhDCFe^mJaVeh|#Ypu=Ed{2N9&4u&E!lf@Axg@HoQ%m422g;4Y3MCT0_kiq002ovPDHLkV1hOU B7K#7> delta 589 zcmV-T0vUv%cWZ6v+u@!7A1Pjr|SK&XI`fryw{X79(DIhUC;;EL*6&T0%nE?+cbk+5%Jamm;GihqYzx*4E1u35(9%uJNJ zl?+ z;*7%|ip{y$6u4ARU*;DlezBG{bHc;I{+wRYs^?KR@uc$evr_wH_G1wvLKq(jO01$& zBq%j6nf>nzReyZb6vU&+-(Ve692v6W4TxHjt|_T$(Nps2tgGDr=4quzN1X1SFf={e z_WK|-??QRUw!e>UyLzlqY*db70E5r zl}^Lk8FVZ{=Pk4?J6ToNIemb+4SAv)*gt?F+3#KX0e|DhXZ?A1y?_7!010qNS#tmY z3labT3lag+-G2N40059lL_t(26?Krw5r9w#LmA7l6l<{mHjtfw>cL^je-P-tPCiIJ z|1ohy5@e)Z$uPAS%q6a_l%_5vtKqx}STz`_P)K#j%_|f({)U&>edzYfOi&UKe$(5R zc%5#U=|(|)Sbs6SH5vTYx>&Q5=za=Vc-Td~;r8jM&xFu-m-N_xH{KfQwGZ7C2PJiu bdQEr_w_{{*emS}000000NkvXXu0mjf%5xS+