]> gitweb.ps.run Git - lolstats/blob - html/script.js
88f12a4e4312d604fd8e9f5e0a39c9d8a1484855
[lolstats] / html / script.js
1 function getRegions() {
2   return [ "euw", "na", "kr", "br" ];
3 }
4 function getChampions() {
5   return [ {name: "Aatrox"}, {name: "Annie"}, {name: "Braum"}, {name: "Not"} ];
6 }
7 function getMatchProps() {
8   return [
9     {text: "Champion", name: "champ"},
10     {text: "Lane", name: "lane"},
11   ];
12 }
13 function getMatches() {
14   return [
15     {champ: "Xerath", lane: "Middle"},
16     {champ: "Quinn", lane: "Bottom"},
17     {champ: "Quinn", lane: "Bottom"},
18     {champ: "Quinn", lane: "Bottom"},
19     {champ: "Quinn", lane: "Bottom"},
20     {champ: "Quinn", lane: "Bottom"},
21     {champ: "Quinn", lane: "Bottom"},
22     {champ: "Quinn", lane: "Bottom"},
23     {champ: "Quinn", lane: "Bottom"},
24     {champ: "Quinn", lane: "Bottom"},
25     {champ: "Quinn", lane: "Bottom"},
26     {champ: "Quinn", lane: "Bottom"},
27     {champ: "Quinn", lane: "Bottom"},
28     {champ: "Quinn", lane: "Bottom"},
29     {champ: "Quinn", lane: "Bottom"},
30     {champ: "Quinn", lane: "Bottom"},
31     {champ: "Quinn", lane: "Bottom"},
32     {champ: "Quinn", lane: "Bottom"},
33     {champ: "Quinn", lane: "Bottom"},
34     {champ: "Quinn", lane: "Bottom"},
35     {champ: "Quinn", lane: "Bottom"},
36     {champ: "Quinn", lane: "Bottom"},
37     {champ: "Quinn", lane: "Bottom"},
38     {champ: "Quinn", lane: "Bottom"},
39     {champ: "Quinn", lane: "Bottom"},
40     {champ: "Quinn", lane: "Bottom"},
41     {champ: "Quinn", lane: "Bottom"},
42     {champ: "Quinn", lane: "Bottom"},
43     {champ: "Quinn", lane: "Bottom"},
44     {champ: "Quinn", lane: "Bottom"},
45     {champ: "Quinn", lane: "Bottom"},
46     {champ: "Quinn", lane: "Bottom"},
47     {champ: "Quinn", lane: "Bottom"},
48     {champ: "Quinn", lane: "Bottom"},
49     {champ: "Quinn", lane: "Bottom"},
50     {champ: "Quinn", lane: "Bottom"},
51     {champ: "Quinn", lane: "Bottom"},
52     {champ: "Quinn", lane: "Bottom"},
53     {champ: "Quinn", lane: "Bottom"},
54     {champ: "Quinn", lane: "Bottom"},
55     {champ: "Quinn", lane: "Bottom"},
56     {champ: "Quinn", lane: "Bottom"},
57     {champ: "Quinn", lane: "Bottom"},
58     {champ: "Quinn", lane: "Bottom"},
59     {champ: "Quinn", lane: "Bottom"},
60     {champ: "Quinn", lane: "Bottom"},
61     {champ: "Quinn", lane: "Bottom"},
62     {champ: "Quinn", lane: "Bottom"},
63     {champ: "Quinn", lane: "Bottom"},
64     {champ: "Quinn", lane: "Bottom"},
65     {champ: "Quinn", lane: "Bottom"},
66     {champ: "Quinn", lane: "Bottom"},
67     {champ: "Quinn", lane: "Bottom"},
68     {champ: "Quinn", lane: "Bottom"},
69     {champ: "Quinn", lane: "Bottom"},
70     {champ: "Quinn", lane: "Bottom"},
71     {champ: "Quinn", lane: "Bottom"},
72     {champ: "Quinn", lane: "Bottom"},
73   ];
74 }
75 function getInfo() {
76   app.summoner = $("#nameinput").val();
77   app.region = $("#regionselect").val();
78
79 function setUrl() {
80   window.history.pushState("object or string", "Title",
81     "/lol?summoner=" +
82     app.summoner +
83     "&region=" +
84     app.region +
85     "&view=" +
86     app.view);
87 }
88 function toggleStartUp() {
89   $("#start").removeClass("down");
90   $("#start").addClass("up");
91 }
92 function toggleStartDown() {
93   $("#start").removeClass("up");
94   $("#start").addClass("down");
95 }
96 function slideStartUp() {
97   $("#start").removeClass("slidedown");
98   $("#start").addClass("slideup");
99 }
100 function slideStartDown() {
101   $("#start").removeClass("slideup");
102   $("#start").addClass("slidedown");
103 }
104 function setView(view) {
105   console.log("Setting view to " + view);
106   if (view == "history") {
107     toggleStartUp();
108     $("#matchhistory").show();
109   } else if (view == "stats") {
110     toggleStartUp();
111     $("#stats").show();
112   }
113   app.view = view;
114 }
115 function changeView(view) {
116   let oldView = app.view;
117   console.log("changing view from " + oldView + " to " + view);
118   if (oldView == "start") {
119     if (view == "history") {
120       slideStartUp();
121       $("#matchhistory").show("slide", { direction: "down" }, 300);
122     } else if (view == "stats") {
123       slideStartUp();
124       $("#stats").show("slide", { direction: "down" }, 300);
125     }
126   } else if (oldView == "history") {
127     if (view == "start") {
128       $("#matchhistory").hide("slide", { direction: "down" }, 300);
129       slideStartDown();
130     } else if (view == "stats") {
131       $("#stats").show("blind", { direction: "right" });
132       $("#matchhistory").hide("blind", { direction: "left" });
133     }
134   } else if (oldView == "stats") {
135     if (view == "start") {
136       $("#stats").hide("slide", { direction: "down" }, 300);
137       slideStartDown();
138     } else if (view == "history") {
139       $("#matchhistory").show("blind", { direction: "left" });
140       $("#stats").hide("blind", { direction: "right" });
141     }
142   }
143   app.view = view;
144 }
145 let app = new Vue({
146   el: '#app',
147   data: {
148     summoner: "",
149     region: "",
150     view: "",
151     regions: getRegions(),
152     champions: getChampions(),
153     matchprops: getMatchProps(),
154     matches: getMatches(),
155   },
156   methods: {
157     submit: function() {
158       getInfo();
159       if (app.view == "start")
160         changeView("history");
161       setUrl();
162     },
163     historyToStats: function() {
164       changeView("stats");
165       setUrl();
166     },
167     statsToHistory: function() {
168       changeView("history");
169       setUrl();
170     },
171     refreshHistory: function() {
172     },
173   },
174 });
175
176 function parseUrl() {
177   let url = new URL(window.location.href);
178   if (url.searchParams.has("summoner")) {
179     app.summoner = url.searchParams.get("summoner");
180     $("#nameinput").val(app.summoner);
181   }
182   if (url.searchParams.has("region")) {
183     app.region = url.searchParams.get("region");
184     $("#regionselect").val(app.region);
185   }
186   if (url.searchParams.has("view")) {
187     let view = url.searchParams.get("view");
188     if (view != "start" && view != "history" && view != "stats") {
189       view = "start";
190     }
191     return view;
192   } else {
193     return "start";
194   }
195 }
196
197 window.addEventListener('popstate', () => {
198   let view = parseUrl();
199   changeView(view);
200 });
201 window.addEventListener('load', () => {
202   let view = parseUrl();
203   setView(view);
204 });