mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-26 05:17:27 +00:00
New version of RiotAPI
This commit is contained in:
parent
55208e4442
commit
3fa63f78fe
16 changed files with 414 additions and 215 deletions
54
index.html
54
index.html
|
|
@ -12,6 +12,8 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<button class="debug"></button>
|
||||
|
||||
<div class="search">
|
||||
<div class="container">
|
||||
|
||||
|
|
@ -31,6 +33,57 @@
|
|||
<h3 class="player__rank">Default division</h3>
|
||||
<div class="player__rank-img"></div>
|
||||
<h3 class="player__ratio">Default ratio</h3>
|
||||
|
||||
|
||||
<ul class="list-matches--debug">
|
||||
<!--<li class="lose">
|
||||
Vayne - BOTTOM
|
||||
|
||||
</li>-->
|
||||
<li class="match">
|
||||
<div class="content-container">
|
||||
|
||||
<div class="first">
|
||||
<img src="/public/img/champions/Vayne.png" class="champion-img" alt="example design">
|
||||
<span class="level">17</span>
|
||||
<div class="summonerSpells">
|
||||
<img class="spell-icon" src="https://cdn.valentinkaelin.ch/riot/spells/SummonerFlash.png" alt="Flash">
|
||||
<img class="spell-icon" src="https://cdn.valentinkaelin.ch/riot/spells/SummonerDot.png" alt="Ignite">
|
||||
</div>
|
||||
<span class="champion-name">Vayne</span>
|
||||
</div>
|
||||
|
||||
<div class="second">
|
||||
<div class="map">Summoner's Rift</div>
|
||||
<div class="gamemode">Normal (Draft Mode)</div>
|
||||
</div>
|
||||
|
||||
<div class="third">
|
||||
<img src="https://cdn.valentinkaelin.ch/riot/items/3140.png" class="item" alt="example design">
|
||||
<img src="https://cdn.valentinkaelin.ch/riot/items/3153.png" class="item" alt="example design">
|
||||
<img src="https://cdn.valentinkaelin.ch/riot/items/3031.png" class="item" alt="example design">
|
||||
<img src="https://cdn.valentinkaelin.ch/riot/items/3124.png" class="item" alt="example design">
|
||||
<img src="https://cdn.valentinkaelin.ch/riot/items/3094.png" class="item" alt="example design">
|
||||
<img src="https://cdn.valentinkaelin.ch/riot/items/3006.png" class="item" alt="example design">
|
||||
<img src="https://cdn.valentinkaelin.ch/riot/items/3363.png" class="item" alt="example design">
|
||||
</div>
|
||||
|
||||
<div class="fourth">
|
||||
<div class="score">8/6/9</div>
|
||||
<div class="gold-farm">
|
||||
<div class="gold">16.2k</div>
|
||||
<div class="farm">227</div>
|
||||
</div>
|
||||
<div class="duration-date">
|
||||
<div class="duration">40:31</div>
|
||||
<div class="date">1/12/2018</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -40,6 +93,7 @@
|
|||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
|
||||
<script src="public/functions.js"></script>
|
||||
<script src="public/client.js"></script>
|
||||
</body>
|
||||
|
||||
|
|
|
|||
15
node_modules/bluebird/package.json
generated
vendored
15
node_modules/bluebird/package.json
generated
vendored
|
|
@ -1,28 +1,29 @@
|
|||
{
|
||||
"_from": "bluebird@^3.5.3",
|
||||
"_from": "bluebird",
|
||||
"_id": "bluebird@3.5.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==",
|
||||
"_location": "/bluebird",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "bluebird@^3.5.3",
|
||||
"raw": "bluebird",
|
||||
"name": "bluebird",
|
||||
"escapedName": "bluebird",
|
||||
"rawSpec": "^3.5.3",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^3.5.3"
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/",
|
||||
"/request-promise"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz",
|
||||
"_shasum": "7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7",
|
||||
"_spec": "bluebird@^3.5.3",
|
||||
"_where": "C:\\Users\\valik\\Desktop\\RiotAPIHeroku",
|
||||
"_spec": "bluebird",
|
||||
"_where": "G:\\Logiciels portables\\NodeJS\\RiotAPINode",
|
||||
"author": {
|
||||
"name": "Petka Antonov",
|
||||
"email": "petka_antonov@hotmail.com",
|
||||
|
|
|
|||
16
node_modules/body-parser/package.json
generated
vendored
16
node_modules/body-parser/package.json
generated
vendored
|
|
@ -1,27 +1,29 @@
|
|||
{
|
||||
"_from": "body-parser@1.18.3",
|
||||
"_from": "body-parser",
|
||||
"_id": "body-parser@1.18.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=",
|
||||
"_location": "/body-parser",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "body-parser@1.18.3",
|
||||
"raw": "body-parser",
|
||||
"name": "body-parser",
|
||||
"escapedName": "body-parser",
|
||||
"rawSpec": "1.18.3",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.18.3"
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/",
|
||||
"/express"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz",
|
||||
"_shasum": "5b292198ffdd553b3a0f20ded0592b956955c8b4",
|
||||
"_spec": "body-parser@1.18.3",
|
||||
"_where": "G:\\Logiciels portables\\NodeJS\\RiotAPINode\\node_modules\\express",
|
||||
"_spec": "body-parser",
|
||||
"_where": "G:\\Logiciels portables\\NodeJS\\RiotAPINode",
|
||||
"bugs": {
|
||||
"url": "https://github.com/expressjs/body-parser/issues"
|
||||
},
|
||||
|
|
|
|||
2
node_modules/lodash/package.json
generated
vendored
2
node_modules/lodash/package.json
generated
vendored
|
|
@ -21,7 +21,7 @@
|
|||
"_resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||
"_shasum": "b39ea6229ef607ecd89e2c8df12536891cac9b8d",
|
||||
"_spec": "lodash@^4.13.1",
|
||||
"_where": "C:\\Users\\valik\\Desktop\\RiotAPIHeroku\\node_modules\\request-promise-core",
|
||||
"_where": "G:\\Logiciels portables\\NodeJS\\RiotAPINode\\node_modules\\request-promise-core",
|
||||
"author": {
|
||||
"name": "John-David Dalton",
|
||||
"email": "john.david.dalton@gmail.com",
|
||||
|
|
|
|||
2
node_modules/request-promise-core/package.json
generated
vendored
2
node_modules/request-promise-core/package.json
generated
vendored
|
|
@ -21,7 +21,7 @@
|
|||
"_resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz",
|
||||
"_shasum": "3eee00b2c5aa83239cfb04c5700da36f81cd08b6",
|
||||
"_spec": "request-promise-core@1.1.1",
|
||||
"_where": "C:\\Users\\valik\\Desktop\\RiotAPIHeroku\\node_modules\\request-promise",
|
||||
"_where": "G:\\Logiciels portables\\NodeJS\\RiotAPINode\\node_modules\\request-promise",
|
||||
"author": {
|
||||
"name": "Nicolai Kamenzky",
|
||||
"url": "https://github.com/analog-nico"
|
||||
|
|
|
|||
3
node_modules/request-promise/package.json
generated
vendored
3
node_modules/request-promise/package.json
generated
vendored
|
|
@ -16,12 +16,13 @@
|
|||
"fetchSpec": "^4.2.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.2.tgz",
|
||||
"_shasum": "d1ea46d654a6ee4f8ee6a4fea1018c22911904b4",
|
||||
"_spec": "request-promise@^4.2.2",
|
||||
"_where": "C:\\Users\\valik\\Desktop\\RiotAPIHeroku",
|
||||
"_where": "G:\\Logiciels portables\\NodeJS\\RiotAPINode",
|
||||
"author": {
|
||||
"name": "Nicolai Kamenzky",
|
||||
"url": "https://github.com/analog-nico"
|
||||
|
|
|
|||
2
node_modules/stealthy-require/package.json
generated
vendored
2
node_modules/stealthy-require/package.json
generated
vendored
|
|
@ -21,7 +21,7 @@
|
|||
"_resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz",
|
||||
"_shasum": "35b09875b4ff49f26a777e509b3090a3226bf24b",
|
||||
"_spec": "stealthy-require@^1.1.0",
|
||||
"_where": "C:\\Users\\valik\\Desktop\\RiotAPIHeroku\\node_modules\\request-promise",
|
||||
"_where": "G:\\Logiciels portables\\NodeJS\\RiotAPINode\\node_modules\\request-promise",
|
||||
"author": {
|
||||
"name": "Nicolai Kamenzky",
|
||||
"url": "https://github.com/analog-nico"
|
||||
|
|
|
|||
195
public/client.js
195
public/client.js
|
|
@ -1,4 +1,23 @@
|
|||
var championsId = { 266: "Aatrox", 103: "Ahri", 84: "Akali", 12: "Alistar", 32: "Amumu", 34: "Anivia", 1: "Annie", 22: "Ashe", 136: "AurelionSol", 268: "Azir", 432: "Bard", 53: "Blitzcrank", 63: "Brand", 201: "Braum", 51: "Caitlyn", 164: "Camille", 69: "Cassiopeia", 31: "Chogath", 42: "Corki", 122: "Darius", 131: "Diana", 119: "Draven", 36: "DrMundo", 245: "Ekko", 60: "Elise", 28: "Evelynn", 81: "Ezreal", 9: "Fiddlesticks", 114: "Fiora", 105: "Fizz", 3: "Galio", 41: "Gangplank", 86: "Garen", 150: "Gnar", 79: "Gragas", 104: "Graves", 120: "Hecarim", 74: "Heimerdinger", 420: "Illaoi", 39: "Irelia", 427: "Ivern", 40: "Janna", 59: "JarvanIV", 24: "Jax", 126: "Jayce", 202: "Jhin", 222: "Jinx", 145: "Kaisa", 429: "Kalista", 43: "Karma", 30: "Karthus", 38: "Kassadin", 55: "Katarina", 10: "Kayle", 141: "Kayn", 85: "Kennen", 121: "Khazix", 203: "Kindred", 240: "Kled", 96: "KogMaw", 7: "Leblanc", 64: "LeeSin", 89: "Leona", 127: "Lissandra", 236: "Lucian", 117: "Lulu", 99: "Lux", 54: "Malphite", 90: "Malzahar", 57: "Maokai", 11: "MasterYi", 21: "MissFortune", 62: "MonkeyKing", 82: "Mordekaiser", 25: "Morgana", 267: "Nami", 75: "Nasus", 111: "Nautilus", 76: "Nidalee", 56: "Nocturne", 20: "Nunu", 2: "Olaf", 61: "Orianna", 516: "Ornn", 80: "Pantheon", 78: "Poppy", 555: "Pyke", 133: "Quinn", 497: "Rakan", 33: "Rammus", 421: "RekSai", 58: "Renekton", 107: "Rengar", 92: "Riven", 68: "Rumble", 13: "Ryze", 113: "Sejuani", 35: "Shaco", 98: "Shen", 102: "Shyvana", 27: "Singed", 14: "Sion", 15: "Sivir", 72: "Skarner", 37: "Sona", 16: "Soraka", 50: "Swain", 134: "Syndra", 223: "TahmKench", 163: "Taliyah", 91: "Talon", 44: "Taric", 17: "Teemo", 412: "Thresh", 18: "Tristana", 48: "Trundle", 23: "Tryndamere", 4: "TwistedFate", 29: "Twitch", 77: "Udyr", 6: "Urgot", 110: "Varus", 67: "Vayne", 45: "Veigar", 161: "Velkoz", 254: "Vi", 112: "Viktor", 8: "Vladimir", 106: "Volibear", 19: "Warwick", 498: "Xayah", 101: "Xerath", 5: "XinZhao", 157: "Yasuo", 83: "Yorick", 154: "Zac", 238: "Zed", 115: "Ziggs", 26: "Zilean", 142: "Zoe", 143: "Zyra" };
|
||||
var maps = { 10: "The Twisted Treeline", 11: "Summoner's Rift", 12: "Howling Abyss" };
|
||||
|
||||
var gameModes = {
|
||||
76: 'URF',
|
||||
100: 'ARAM',
|
||||
400: 'Normal (Draft)',
|
||||
420: 'Ranked (Solo)',
|
||||
430: 'Normal (Blind)',
|
||||
440: 'Ranked (Flex)',
|
||||
460: '3v3 Blind',
|
||||
470: '3v3 Ranked (Flex)',
|
||||
800: '3v3 Co-op vs. AI (Intermediate)',
|
||||
810: '3v3 Co-op vs. AI (Intro)',
|
||||
820: '3v3 Co-op vs. AI (Beginner)',
|
||||
830: 'Co-op vs. AI (Intro)',
|
||||
840: 'Co-op vs. AI (Beginner)',
|
||||
850: 'Co-op vs. AI (Intermediate)'
|
||||
};
|
||||
|
||||
var req = new XMLHttpRequest();
|
||||
var url = '/api';
|
||||
var params = 'playerName=Kalane';
|
||||
|
|
@ -56,6 +75,7 @@ changeName.addEventListener('submit', function (e) {
|
|||
* @param JSONData : big JSON with all the data of the request to the server
|
||||
*/
|
||||
function createObject(JSONData) {
|
||||
console.log('--- ALL INFOS ---')
|
||||
console.log(JSONData);
|
||||
|
||||
var userStats = JSONData[0];
|
||||
|
|
@ -82,13 +102,43 @@ function createObject(JSONData) {
|
|||
}
|
||||
}
|
||||
|
||||
var map = maps[currentMatch.mapId];
|
||||
var mode = gameModes[currentMatch.queueId];
|
||||
if (!mode)
|
||||
mode = 'Undefinded gamemode';
|
||||
var champion = currentMatch.participants[participantId - 1].championId;
|
||||
var role = currentMatch.participants[participantId - 1].timeline.lane;
|
||||
var timeAgo = timeDifference(currentMatch.gameCreation);
|
||||
var time = secToTime(currentMatch.gameDuration);
|
||||
var kills = currentMatch.participants[participantId - 1].stats.kills;
|
||||
var deaths = currentMatch.participants[participantId - 1].stats.deaths;
|
||||
var assists = currentMatch.participants[participantId - 1].stats.assists;
|
||||
var level = currentMatch.participants[participantId - 1].stats.champLevel;
|
||||
|
||||
var items = [];
|
||||
for (let i = 0; i < 6; i++) {
|
||||
var currentItem = 'item' + i;
|
||||
items.push(currentMatch.participants[participantId - 1].stats[currentItem]);
|
||||
}
|
||||
|
||||
var gold = (currentMatch.participants[participantId - 1].stats.goldEarned / 1000).toFixed(1) + 'k';
|
||||
var minions = currentMatch.participants[participantId - 1].stats.totalMinionsKilled + currentMatch.participants[participantId - 1].stats.neutralMinionsKilled;
|
||||
|
||||
matchesInfos.push({
|
||||
result: win,
|
||||
map: map,
|
||||
gamemode: mode,
|
||||
champ: champion,
|
||||
role: role
|
||||
role: role,
|
||||
date: timeAgo,
|
||||
time: time,
|
||||
kills: kills,
|
||||
deaths: deaths,
|
||||
assists: assists,
|
||||
level: level,
|
||||
items: items,
|
||||
gold: gold,
|
||||
minions: minions
|
||||
});
|
||||
}
|
||||
console.log(matchesInfos);
|
||||
|
|
@ -105,7 +155,7 @@ function createObject(JSONData) {
|
|||
|
||||
nameChosen = userStats.name;
|
||||
|
||||
console.log('=============');
|
||||
console.log('====== Saved infos ======');
|
||||
console.log(infos);
|
||||
|
||||
localStorage[nameChosen] = JSON.stringify(infos);
|
||||
|
|
@ -113,23 +163,6 @@ function createObject(JSONData) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the link of the rank image
|
||||
* @param soloQStats : stats in soloQ of the player
|
||||
*/
|
||||
function getRankImg(soloQStats) {
|
||||
if (soloQStats) {
|
||||
if (soloQStats.tier != 'MASTER' && soloQStats.tier != 'CHALLENGER') {
|
||||
return 'https://cdn.valentinkaelin.ch/riot/tier-icons/' + soloQStats.tier.toLowerCase() + '_' + soloQStats.rank.toLowerCase() + '.png';
|
||||
} else {
|
||||
return 'https://cdn.valentinkaelin.ch/riot/tier-icons/' + soloQStats.tier.toLowerCase() + '.png';
|
||||
}
|
||||
} else {
|
||||
return 'https://cdn.valentinkaelin.ch/riot/tier-icons/provisional.png';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display on the page all the dynamic content
|
||||
* @param stringData : Stringify object with all datas
|
||||
|
|
@ -146,21 +179,129 @@ function displayContent(stringData) {
|
|||
document.querySelector('.player__ratio').innerHTML = data.rankedWins ? data.rankedWins + ' wins / ' + data.rankedLosses + ' losses' : "Joueur non classé";
|
||||
|
||||
var playerContainer = document.querySelector('.player');
|
||||
var oldList = document.querySelector('.list-matches');
|
||||
var oldList = document.querySelector('.list-matches--debug');
|
||||
if (oldList)
|
||||
oldList.parentNode.removeChild(oldList);
|
||||
var matchesList = document.createElement('ul');
|
||||
matchesList.className = 'list-matches';
|
||||
matchesList.className = 'list-matches--debug';
|
||||
playerContainer.appendChild(matchesList);
|
||||
|
||||
data.matches.forEach(e => {
|
||||
var li = document.createElement('li');
|
||||
li.className = e.result ? 'win' : 'lose';
|
||||
var img = document.createElement('img');
|
||||
if (e.result)
|
||||
li.className = 'match win';
|
||||
else
|
||||
li.className = 'match lose';
|
||||
var container = document.createElement('div');
|
||||
container.className = 'content-container';
|
||||
|
||||
/* First col */
|
||||
var first = document.createElement('div');
|
||||
first.className = 'first';
|
||||
var imgChamp = document.createElement('img');
|
||||
var championName = championsId[e.champ];
|
||||
img.setAttribute('src', '/public/img/champions/' + championName + '.png');
|
||||
img.className = 'champion-icon';
|
||||
li.innerHTML = championName + ' - ' + e.role;
|
||||
li.appendChild(img);
|
||||
imgChamp.setAttribute('src', '/public/img/champions/' + championName + '.png');
|
||||
imgChamp.className = 'champion-img';
|
||||
|
||||
var level = document.createElement('span');
|
||||
level.className = 'level';
|
||||
level.innerText = e.level;
|
||||
|
||||
var summonerSpells = document.createElement('div');
|
||||
summonerSpells.className = 'summonerSpells';
|
||||
|
||||
var firstSpell = document.createElement('img');
|
||||
firstSpell.setAttribute('src', 'https://cdn.valentinkaelin.ch/riot/spells/SummonerFlash.png');
|
||||
firstSpell.className = 'spell-icon';
|
||||
summonerSpells.appendChild(firstSpell);
|
||||
|
||||
var secondSpell = document.createElement('img');
|
||||
secondSpell.setAttribute('src', 'https://cdn.valentinkaelin.ch/riot/spells/SummonerDot.png');
|
||||
secondSpell.className = 'spell-icon';
|
||||
summonerSpells.appendChild(secondSpell);
|
||||
|
||||
var name = document.createElement('span');
|
||||
name.className = 'champion-name';
|
||||
name.innerText = championName;
|
||||
|
||||
first.appendChild(imgChamp);
|
||||
first.appendChild(level);
|
||||
first.appendChild(summonerSpells);
|
||||
first.appendChild(name);
|
||||
|
||||
|
||||
/* Second col */
|
||||
var second = document.createElement('div');
|
||||
second.className = 'second';
|
||||
var map = document.createElement('div');
|
||||
map.className = 'map';
|
||||
map.innerText = e.map;
|
||||
var gamemode = document.createElement('div');
|
||||
gamemode.className = 'gamemode';
|
||||
gamemode.innerText = e.gamemode;
|
||||
|
||||
second.appendChild(map);
|
||||
second.appendChild(gamemode);
|
||||
|
||||
|
||||
/* Third col */
|
||||
var third = document.createElement('div');
|
||||
third.className = 'third';
|
||||
e.items.forEach(e => {
|
||||
var img = document.createElement('img');
|
||||
img.className = 'item';
|
||||
img.setAttribute('src', 'https://cdn.valentinkaelin.ch/riot/items/' + e + '.png');
|
||||
third.appendChild(img);
|
||||
});
|
||||
|
||||
|
||||
/* Fourth col */
|
||||
var fourth = document.createElement('div');
|
||||
fourth.className = 'fourth';
|
||||
var score = document.createElement('div');
|
||||
score.className = 'score';
|
||||
score.innerText = e.kills + '/' + e.deaths + '/' + e.assists;
|
||||
|
||||
var goldFarm = document.createElement('div');
|
||||
goldFarm.className = 'gold-farm';
|
||||
var gold = document.createElement('div');
|
||||
gold.className = 'gold';
|
||||
gold.innerText = e.gold;
|
||||
var farm = document.createElement('div');
|
||||
farm.className = 'farm';
|
||||
farm.innerText = e.minions;
|
||||
goldFarm.appendChild(gold);
|
||||
goldFarm.appendChild(farm);
|
||||
|
||||
var durationDate = document.createElement('div');
|
||||
durationDate.className = 'duration-date';
|
||||
var duration = document.createElement('div');
|
||||
duration.className = 'duration';
|
||||
duration.innerText = e.time;
|
||||
var date = document.createElement('div');
|
||||
date.className = 'date';
|
||||
date.innerText = e.date;
|
||||
durationDate.appendChild(duration);
|
||||
durationDate.appendChild(date);
|
||||
|
||||
fourth.appendChild(score);
|
||||
fourth.appendChild(goldFarm);
|
||||
fourth.appendChild(durationDate);
|
||||
|
||||
|
||||
/* End */
|
||||
container.appendChild(first);
|
||||
container.appendChild(second);
|
||||
container.appendChild(third);
|
||||
container.appendChild(fourth);
|
||||
li.appendChild(container);
|
||||
matchesList.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/* Debug button to reset localstorage */
|
||||
document.querySelector('.debug').addEventListener('click', () => {
|
||||
console.log('CLEAR LOCALSTORAGE');
|
||||
localStorage.clear();
|
||||
});
|
||||
55
public/functions.js
Normal file
55
public/functions.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Return the relative time betweeen a chosen moment and the current time
|
||||
* @param previous : time we want to get difference
|
||||
*/
|
||||
function timeDifference(previous) {
|
||||
var current = new Date();
|
||||
var msPerMinute = 60 * 1000;
|
||||
var msPerHour = msPerMinute * 60;
|
||||
var msPerDay = msPerHour * 24;
|
||||
var msPerWeek = msPerDay * 7;
|
||||
var elapsed = current - previous;
|
||||
|
||||
if (elapsed < msPerMinute) {
|
||||
return Math.round(elapsed / 1000) + 's';
|
||||
} else if (elapsed < msPerHour) {
|
||||
return Math.round(elapsed / msPerMinute) + 'm';
|
||||
} else if (elapsed < msPerDay) {
|
||||
return Math.round(elapsed / msPerHour) + 'h';
|
||||
} else if (elapsed < msPerWeek) {
|
||||
return Math.round(elapsed / msPerDay) + 'j';
|
||||
} else {
|
||||
var oldDate = new Date(previous);
|
||||
var day = oldDate.getDate() < 10 ? '0' + oldDate.getDate() : oldDate.getDate();
|
||||
var month = oldDate.getMonth() < 9 ? '0' + (oldDate.getMonth() + 1) : (oldDate.getMonth() + 1);
|
||||
return day + '.' + month + '.' + oldDate.getFullYear().toString().substr(-2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return time in a formatted way
|
||||
* @param sec : time in seconds to convert
|
||||
*/
|
||||
function secToTime(sec) {
|
||||
var min = Math.floor(sec / 60);
|
||||
var newSec = sec - min * 60;
|
||||
return min + ':' + (newSec < 10 ? '0' + newSec : newSec); //
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the link of the rank image
|
||||
* @param soloQStats : stats in soloQ of the player
|
||||
*/
|
||||
function getRankImg(soloQStats) {
|
||||
if (soloQStats) {
|
||||
if (soloQStats.tier != 'MASTER' && soloQStats.tier != 'CHALLENGER') {
|
||||
return 'https://cdn.valentinkaelin.ch/riot/tier-icons/' + soloQStats.tier.toLowerCase() + '_' + soloQStats.rank.toLowerCase() + '.png';
|
||||
} else {
|
||||
return 'https://cdn.valentinkaelin.ch/riot/tier-icons/' + soloQStats.tier.toLowerCase() + '.png';
|
||||
}
|
||||
} else {
|
||||
return 'https://cdn.valentinkaelin.ch/riot/tier-icons/provisional.png';
|
||||
}
|
||||
}
|
||||
111
public/style.css
111
public/style.css
|
|
@ -1,3 +1,17 @@
|
|||
body {
|
||||
background: #F1F5F8;
|
||||
}
|
||||
|
||||
.debug {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: #EF5753;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.search {
|
||||
background: #ebebeb;
|
||||
}
|
||||
|
|
@ -13,7 +27,7 @@
|
|||
.player {
|
||||
text-align: center;
|
||||
margin: 16px auto;
|
||||
width: 400px;
|
||||
/*width: 400px;*/
|
||||
border: 1px solid #ebebeb;
|
||||
padding: 16px;
|
||||
}
|
||||
|
|
@ -52,3 +66,98 @@
|
|||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.champion-img {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
display: block;
|
||||
margin: 0 2px 0 0;
|
||||
}
|
||||
|
||||
.spell-icon {
|
||||
width: 23px;
|
||||
height: 23px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
/* ############## */
|
||||
|
||||
|
||||
.list-matches--debug {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.match {
|
||||
background: #fff;
|
||||
padding: 10px 0;
|
||||
border-bottom: 1px solid #DAE1E7;
|
||||
}
|
||||
|
||||
.match .content-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
padding: 16px;
|
||||
|
||||
}
|
||||
|
||||
.match.win .content-container {
|
||||
border-left: 10px solid #51D88A;
|
||||
}
|
||||
|
||||
.match.lose .content-container {
|
||||
border-left: 10px solid #EF5753;
|
||||
}
|
||||
|
||||
/* First col */
|
||||
.match .first {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
flex: 1 0 0;
|
||||
}
|
||||
|
||||
.match .level {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.match .summonerSpells {
|
||||
margin: 0 8px 0 0;
|
||||
}
|
||||
|
||||
.match .spell-icon:first-child {
|
||||
margin: 0 0 2px 0;
|
||||
}
|
||||
|
||||
/* Second col */
|
||||
.match .second {
|
||||
flex: 1 0 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Third col */
|
||||
.match .third {
|
||||
flex: 1 0 0;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.third .item {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
margin: 0 2px 0 0;
|
||||
}
|
||||
|
||||
/* Fourth col */
|
||||
.match .fourth {
|
||||
flex: 1 0 0;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Riot Api Node</title>
|
||||
<link rel="stylesheet" href="public/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="player">
|
||||
<div class="player__pp"></div>
|
||||
<h1 class="player__name">Default name</h1>
|
||||
<h3 class="player__level">Default level</h3>
|
||||
<h3 class="player__rank">Default division</h3>
|
||||
<h3 class="player__ratio">Default ratio</h3>
|
||||
</div>
|
||||
|
||||
<form method="get" id="changeName">
|
||||
<input type="text" name="playerName" id="name">
|
||||
<button>Submit</button>
|
||||
</form>
|
||||
|
||||
<script src="public/client.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"name": "riotapi",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "kalane",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.16.4"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
var req = new XMLHttpRequest();
|
||||
var url = '/api';
|
||||
|
||||
req.open('GET', url, true); // set this to POST if you would like
|
||||
req.addEventListener('load', onLoad);
|
||||
req.addEventListener('error', onError);
|
||||
|
||||
req.send();
|
||||
|
||||
function onLoad() {
|
||||
var response = this.responseText;
|
||||
var parsedEntireResponse = JSON.parse(response);
|
||||
//console.log(parsedEntireResponse);
|
||||
|
||||
var userStats = parsedEntireResponse[0];
|
||||
var rankedStats = JSON.parse(parsedEntireResponse[1]);
|
||||
console.log(userStats);
|
||||
console.log(rankedStats);
|
||||
//console.log(rankedStats[0].playerOrTeamName);
|
||||
|
||||
document.querySelector('.player__pp').style.background = 'url(http://cdn.kalane.ch/riot/profileicon/' + userStats.profileIconId + '.png) center/cover';
|
||||
document.querySelector('.player__name').innerHTML = userStats.name;
|
||||
document.querySelector('.player__level').innerHTML = userStats.summonerLevel;
|
||||
document.querySelector('.player__rank').innerHTML = rankedStats.length !== 0 ? rankedStats[0].tier + ' ' + rankedStats[0].rank : "Joueur non classé";
|
||||
document.querySelector('.player__ratio').innerHTML = rankedStats.length !== 0 ? rankedStats[0].wins + ' wins / ' + rankedStats[0].losses + ' losses': "Joueur non classé";
|
||||
}
|
||||
|
||||
function onError() {
|
||||
console.log('error receiving async AJAX call');
|
||||
}
|
||||
|
||||
|
||||
/* Formulaire */
|
||||
var changeName = document.querySelector('#changeName');
|
||||
var nameToPick = document.querySelector('#name')
|
||||
changeName.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
url = '/api?' + nameToPick.value;
|
||||
req.open('GET', url, true);
|
||||
req.send();
|
||||
});
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
.player__pp {
|
||||
width: 75px;
|
||||
height: 75px;
|
||||
background: #ebebeb;
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
const express = require('express')
|
||||
const request = require('request');
|
||||
const path = require('path');
|
||||
const bodyParser = require("body-parser");
|
||||
|
||||
const app = express()
|
||||
const port = 3000
|
||||
|
||||
const key = 'RGAPI-0db7bf7a-c8a7-40d1-927b-2cd33e22d873';
|
||||
var id = 65362306;
|
||||
var pseudo = 'Chil';
|
||||
|
||||
var dataAPI;
|
||||
|
||||
/* Homepage */
|
||||
app.get('/', function (request, response) {
|
||||
response.sendFile(path.join(__dirname, 'index.html'));
|
||||
});
|
||||
|
||||
app.use('/public', express.static(__dirname + '/public'));
|
||||
|
||||
app.use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.listen(port, () => console.log(`RiotAPI test app listening on port ${port}!`))
|
||||
|
||||
|
||||
// Get data of rankeds
|
||||
function getRanked(callback) {
|
||||
request('https://euw1.api.riotgames.com/lol/league/v3/positions/by-summoner/' + id + '?api_key=' + key, function (error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
callback(body);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
getRanked(function (body) {
|
||||
dataAPI = body;
|
||||
});
|
||||
|
||||
|
||||
// send data of rankeds and of username
|
||||
app.get('/api', function (req, res) {
|
||||
var name = req.url.split('?')[1];
|
||||
if (name != undefined) {
|
||||
pseudo = name;
|
||||
}
|
||||
getAccountID(function (JSONBody) {
|
||||
id = JSONBody.id;
|
||||
getRanked(function (body) {
|
||||
dataAPI = body;
|
||||
var finalJSON = new Array();
|
||||
finalJSON.push(JSONBody);
|
||||
finalJSON.push(dataAPI);
|
||||
//console.log(finalJSON);
|
||||
res.send(finalJSON);
|
||||
//res.send(dataAPI);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Get accountId of username
|
||||
function getAccountID(callback) {
|
||||
request('https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/' + pseudo + '?api_key=' + key, function (error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
dataAPI = body;
|
||||
var JSONBody = JSON.parse(body);
|
||||
//console.log(JSONBody);
|
||||
id = JSONBody.id;
|
||||
callback(JSONBody);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ var Promise = require("bluebird");
|
|||
const app = express()
|
||||
app.set('port', (process.env.PORT || 5000))
|
||||
|
||||
const key = 'RGAPI-48b725ad-3376-4b20-856b-66787c36d348';
|
||||
const key = 'RGAPI-858eb2b5-24a7-4a54-bf71-45e8b9f3327a';
|
||||
var summonerID = 'HMOiIUvzYtfgPk5X53zWTeOZo52T-HYJQhwvhkPNh0BWxZ0';
|
||||
var accountID = 'V1xNS14bjVeP54hg03JeMxkXJB29K4TfUMvijDB85nxbD4Y';
|
||||
var pseudo = 'Chil';
|
||||
|
|
@ -91,8 +91,8 @@ function getMatches(callback) {
|
|||
if (!error && response.statusCode == 200) {
|
||||
JSONMatches = JSON.parse(body);
|
||||
|
||||
let matchsId = new Array();
|
||||
for (let i = 0; i < JSONMatches.matches.length; i++) {
|
||||
var matchsId = new Array();
|
||||
for (var i = 0; i < JSONMatches.matches.length; i++) {
|
||||
matchsId[i] = JSONMatches.matches[i].gameId;
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ function getMatches(callback) {
|
|||
function addMatchToJSON(obj) {
|
||||
//console.log(obj.gameId);
|
||||
|
||||
for (let i = 0; i < JSONMatches.matches.length; i++) {
|
||||
for (var i = 0; i < JSONMatches.matches.length; i++) {
|
||||
if(JSONMatches.matches[i].gameId == obj.gameId) {
|
||||
//console.log('yes');
|
||||
JSONMatches.matches[i] = obj;
|
||||
|
|
|
|||
Loading…
Reference in a new issue