]> gitweb.ps.run Git - lolstats/blob - html/script.js
c2d4fd576d40cd9fc2dffe2681a2da743e1f7bc9
[lolstats] / html / script.js
1 function getRegions() {
2   return {
3     "BR": "br1.api.riotgames.com",
4     "EUNE": "eun1.api.riotgames.com",
5     "EUW": "euw1.api.riotgames.com",
6     "JP": "jp1.api.riotgames.com",
7     "KR": "kr.api.riotgames.com",
8     "LAN": "la1.api.riotgames.com",
9     "LAS": "la2.api.riotgames.com",
10     "NA": "na1.api.riotgames.com",
11     "OCE": "oc1.api.riotgames.com",
12     "TR": "tr1.api.riotgames.com",
13     "RU": "ru.api.riotgames.com",
14     "PBE": "pbe1.api.riotgames.com",
15   };
16 }
17 function getQueues() {
18   return {
19     0           : "Custom",
20     2           : "5v5 Blind Pick",
21     4           : "5v5 Ranked Solo",
22     6           : "5v5 Ranked Premade",
23     7           : "Co-op vs AI",
24     8           : "3v3 Normal",
25     9           : "3v3 Ranked Flex",
26     14          : "5v5 Draft Pick",
27     16          : "5v5 Dominion Blind Pick",
28     17          : "5v5 Dominion Draft Pick",
29     25          : "Dominion Co-op vs AI",
30     31          : "Co-op vs AI Intro Bot",
31     32          : "Co-op vs AI Beginner Bot",
32     33          : "Co-op vs AI Intermediate Bot",
33     41          : "3v3 Ranked Team",
34     42          : "5v5 Ranked Team",
35     52          : "Co-op vs AI",
36     61          : "5v5 Team Builder",
37     65          : "5v5 ARAM",
38     70          : "One for All",
39     72          : "1v1 Snowdown Showdown",
40     73          : "2v2 Snowdown Showdown",
41     75          : "6v6 Hexakill",
42     76          : "Ultra Rapid Fire",
43     78          : "One For All: Mirror Mode",
44     83          : "Co-op vs AI Ultra Rapid Fire",
45     91          : "Doom Bots Rank 1",
46     92          : "Doom Bots Rank 2",
47     93          : "Doom Bots Rank 5",
48     96          : "Ascension",
49     98          : "6v6 Hexakill",
50     100         : "5v5 ARAM",
51     300         : "Legend of the Poro King",
52     310         : "Nemesis",
53     313         : "Black Market Brawlers",
54     315         : "Nexus Siege",
55     317         : "Definitely Not Dominion",
56     318         : "ARURF",
57     325         : "All Random",
58     400         : "5v5 Draft Pick",
59     410         : "5v5 Ranked Dynamic",
60     420         : "5v5 Ranked Solo",
61     430         : "5v5 Blind Pick",
62     440         : "5v5 Ranked Flex",
63     450         : "5v5 ARAM",
64     460         : "3v3 Blind Pick",
65     470         : "3v3 Ranked Flex",
66     600         : "Blood Hunt Assassin",
67     610         : "Dark Star: Singularity",
68     700         : "Clash",
69     800         : "Co-op vs. AI Intermediate Bot",
70     810         : "Co-op vs. AI Intro Bot",
71     820         : "Co-op vs. AI Beginner Bot",
72     830         : "Co-op vs. AI Intro Bot",
73     840         : "Co-op vs. AI Beginner Bot",
74     850         : "Co-op vs. AI Intermediate Bot",
75     900         : "ARURF",
76     910         : "Ascension",
77     920         : "Legend of the Poro King",
78     940         : "Nexus Siege",
79     950         : "Doom Bots Voting",
80     960         : "Doom Bots Standard",
81     980         : "Star Guardian Invasion: Normal",
82     990         : "Star Guardian Invasion: Onslaught",
83     1000        : "PROJECT: Hunters",
84     1010        : "Snow ARURF",
85     1020        : "One for All",
86     1030        : "Odyssey Extraction: Intro",
87     1040        : "Odyssey Extraction: Cadet",
88     1050        : "Odyssey Extraction: Crewmember",
89     1060        : "Odyssey Extraction: Captain",
90     1070        : "Odyssey Extraction: Onslaught",
91     1200        : "Nexus Blitz",
92   };
93 }
94 function getChampions() {
95   $.ajax("/lol/champions")
96     .done((data) => {
97       app.champions = JSON.parse(data);
98     });
99 }
100 function getChampLookup() {
101   $.ajax("/lol/champlookup")
102     .done((data) => {
103       app.champlookup = JSON.parse(data);
104     });
105 }
106 function getMatches() {
107   $.ajax("/lol/matches?region=" + app.region + "&summoner=" + app.summoner)
108     .done((data) => {
109       app.matches = JSON.parse(data);
110       for (m in app.matches) {
111         app.matches[m].championString = app.champlookup[app.matches[m].champion];
112         app.matches[m].queueString = app.queues[app.matches[m].queue];
113         app.matches[m].timestampString = new Date(app.matches[m].timestamp).toLocaleString();
114       }
115     });
116 }
117 function getInfo() {
118   app.summoner = $("#nameinput").val();
119   app.region = $("#regionselect").val();
120
121 function setUrl() {
122   window.history.pushState("object or string", "Title",
123     "/lol?summoner=" +
124     app.summoner +
125     "&region=" +
126     app.region +
127     "&view=" +
128     app.view);
129 }
130 function toggleStartUp() {
131   $("#start").removeClass("down");
132   $("#start").addClass("up");
133 }
134 function toggleStartDown() {
135   $("#start").removeClass("up");
136   $("#start").addClass("down");
137 }
138 function slideStartUp() {
139   $("#start").removeClass("slidedown");
140   $("#start").addClass("slideup");
141 }
142 function slideStartDown() {
143   $("#start").removeClass("slideup");
144   $("#start").addClass("slidedown");
145 }
146 function setView(view) {
147   console.log("Setting view to " + view);
148   if (view == "history") {
149     toggleStartUp();
150     $("#matchhistory").show();
151   } else if (view == "stats") {
152     toggleStartUp();
153     $("#stats").show();
154   }
155   app.view = view;
156 }
157 function changeView(view) {
158   let oldView = app.view;
159   console.log("changing view from " + oldView + " to " + view);
160   if (oldView == "start") {
161     if (view == "history") {
162       slideStartUp();
163       $("#matchhistory").show("blind", { direction: "down" }, 300);
164     } else if (view == "stats") {
165       slideStartUp();
166       $("#stats").show("blind", { direction: "down" }, 300);
167     }
168   } else if (oldView == "history") {
169     if (view == "start") {
170       $("#matchhistory").hide("blind", { direction: "down" }, 300);
171       slideStartDown();
172     } else if (view == "stats") {
173       $("#stats").show("blind", { direction: "right" });
174       $("#matchhistory").hide("blind", { direction: "left" });
175     }
176   } else if (oldView == "stats") {
177     if (view == "start") {
178       $("#stats").hide("blind", { direction: "down" }, 300);
179       slideStartDown();
180     } else if (view == "history") {
181       $("#matchhistory").show("blind", { direction: "left" });
182       $("#stats").hide("blind", { direction: "right" });
183     }
184   }
185   app.view = view;
186 }
187 let app = new Vue({
188   el: '#app',
189   data: {
190     summoner: "",
191     region: "",
192     view: "",
193     regions: getRegions(),
194     queues: getQueues(),
195     champlookup: [],
196     champions: [],
197     matchprops: [
198       { name: "championString", text: "Champion" },
199       { name: "queueString", text: "Queue" },
200       { name: "timestampString", text: "Date" },
201     ],
202     matches: [],
203   },
204   methods: {
205     submit: function() {
206       getInfo();
207       if (app.view == "start")
208         changeView("history");
209       setUrl();
210       app.matches = [];
211       getMatches();
212     },
213     historyToStats: function() {
214       changeView("stats");
215       setUrl();
216     },
217     statsToHistory: function() {
218       changeView("history");
219       setUrl();
220     },
221     refreshHistory: function() {
222       getMatches();
223     },
224     selectAll: function() {
225       $(".champselectcb").prop('checked', true);
226     },
227     selectNone: function() {
228       $(".champselectcb").prop('checked', false);
229     },
230   },
231 });
232
233 function parseUrl() {
234   let url = new URL(window.location.href);
235   if (url.searchParams.has("summoner")) {
236     app.summoner = url.searchParams.get("summoner");
237     $("#nameinput").val(app.summoner);
238   }
239   if (url.searchParams.has("region")) {
240     app.region = url.searchParams.get("region");
241     $("#regionselect").val(app.region);
242   }
243   if (url.searchParams.has("view")) {
244     let view = url.searchParams.get("view");
245     if (view != "start" && view != "history" && view != "stats") {
246       view = "start";
247     }
248     return view;
249   } else {
250     return "start";
251   }
252 }
253
254 window.addEventListener('popstate', () => {
255   let view = parseUrl();
256   changeView(view);
257 });
258 window.addEventListener('load', async () => {
259   let view = parseUrl();
260   setView(view);
261   getChampions();
262   getChampLookup();
263 });