-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
218 lines (200 loc) · 6.26 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<template>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Here you can view your stats from our Mario Kart 8 Deluxe Yuzu Lounge! dsc.gg/yuzuonline" />
<meta property="og:title" content="MK8DX-Yuzu Leaderboard" />
<meta property="og:site_name" content="dsc.gg/yuzuonline" />
<meta property="al:web:url" content="https://dsc.gg/yuzuonline" />
<meta property="og:description" content="Here you can view your stats from our Mario Kart 8 Deluxe Yuzu Lounge!" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://mk8dx-yuzu.github.io/" />
<meta property="og:image" content="https://mk8dx-yuzu.github.io/favicon/ms-icon-310x310.png" />
<div>
<div class="gradient-bg"></div>
<nav class="h-14 bg-slate-950 flex justify-between">
<nuxt-link to="/">
<img :src="!uwu ? '/favicon/android-icon-192x192.png' : '/images/kawaii_icon_by_kevnkkm.png'" alt="icon" class="w-14 h-14" />
</nuxt-link>
<div class="mr-48 self-center text-center">
<UPopover v-model:open="isSearchOpen" v-if="route.fullPath == '/'">
<UTooltip text="Search" :shortcuts="['CTRL', 'K']" :popper="{ placement: 'left' }">
<UIcon name="i-heroicons-magnifying-glass" class="w-5 h-5" />
</UTooltip>
<template #panel>
<div class="p-4">
<p class="text-2xl">Search players</p>
<div class="flex space-x-4">
<!-- <div>
<p>By Rank:</p>
<USelectMenu v-model="selectedRank" :options="ranks">
<template #leading>
<img v-if="selectedRank != 'any'" :src="`/images/ranks/${selectedRank}.webp`" class="w-5 h-5" />
<p v-else>any</p>
</template>
</USelectMenu>
</div> -->
<div class="flex text-center items-center">
<UInput v-model="searchQuery" />
<UIcon name="i-heroicons-x-mark" class="absolute right-5 cursor-pointer" @click="searchQuery = ''" />
</div>
</div>
</div>
</template>
</UPopover>
</div>
<DownloadBtn @click="downloadSheet" />
</nav>
<NuxtPage />
</div>
</template>
<script setup>
const uwu = useCookie("uwu");
const route = useRoute();
if (route.query.uwu) {
uwu.value = true;
}
const url = useState("url", () => "https://mk8dx-yuzu.kevnkkm.de/api/leaderboard");
const hasLoaded = useState("loaded", () => false);
const hasMounted = useState("mounted", () => false);
const playerData = useState("data", () => []);
function sortByMMR(data) {
// 1. Create a new array to store sorted objects
const sortedData = [];
// 2. Loop through the original data
for (const item of data) {
// 3. Find the appropriate insertion point in the sorted array
let insertionIndex = 0;
while (insertionIndex < sortedData.length && item.mmr >= sortedData[insertionIndex].mmr) {
insertionIndex++;
}
// 4. Insert the object at the found position
sortedData.splice(insertionIndex, 0, item);
}
// 5. Return the sorted array
return sortedData;
}
onMounted(async () => {
hasMounted.value = true;
try {
var data = await $fetch(url.value);
} catch (e) {
console.log(e);
var data = [];
}
playerData.value = sortByMMR(
data.map((player) => ({
name: player.name || player.Player,
mmr: player.mmr || player.MMR,
history: player.history || [],
wins: player.history.filter((delta) => delta >= 0).length,
losses: player.history.filter((delta) => delta < 0).length,
discord: player.discord_id || undefined,
disconnects: player.disconnects || 0,
}))
).reverse();
hasLoaded.value = true;
// ANIMATION
nextTick(() => {
const cells = document.querySelectorAll("#leaderboard-table td");
cells.forEach((cell, index) => {
cell.style.opacity = 0;
cell.style.animation = "tiltanimation 0.75s forwards";
cell.style.animationDelay = index * 0.005 + "s";
});
});
});
async function downloadSheet() {
try {
const response = await fetch(url.value);
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}
const data = await response.json();
let date = new Date();
const filename = `leaderboard-${date.toISOString().split("T")[0]}.json`;
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
if (window.navigator.webkitURL) {
// Chrome and Safari
const link = document.createElement("a");
link.href = window.navigator.webkitURL.createObjectURL(blob);
link.download = filename;
link.click();
} else {
// Firefox
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = filename;
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
} catch (error) {
console.error("Error downloading JSON:", error);
}
}
const ranks = ["any", "wood", "bronze", "silver", "gold", "platinum", "diamond", "master"];
const searchQuery = useState("searchQuery", () => "");
const selectedRank = ref(ranks[0]);
const isSearchOpen = ref(false);
defineShortcuts({
meta_k: {
usingInput: true,
handler: () => {
isSearchOpen.value = !isSearchOpen.value;
},
},
});
useHead({
title: "MK8DX-Yuzu Leaderboard",
meta: [
{
name: "viewport",
content: "width=device-width, initial-scale=1.0",
},
{
name: "description",
content: "Here you can view your stats from our Mario Kart 8 Deluxe Yuzu Lounge! dsc.gg/yuzuonline",
},
{
property: "og:title",
content: "MK8DX-Yuzu Leaderboard",
},
{
property: "og:site_name",
content: "dsc.gg/yuzuonline",
},
{
property: "al:web:url",
content: "https://dsc.gg/yuzuonline",
},
{
property: "og:description",
content: "Here you can view your stats from our Mario Kart 8 Deluxe Yuzu Lounge!",
},
{
property: "og:type",
content: "website",
},
{
property: "og:url",
content: "https://mk8dx-yuzu.github.io/",
},
{
property: "og:image",
content: "https://mk8dx-yuzu.github.io/images/kawaii_icon_by_kevnkkm.png",
},
],
});
</script>
<style>
.page-enter-active,
.page-leave-active {
transition: all 0.4s;
}
.page-enter-from,
.page-leave-to {
opacity: 0;
filter: blur(1rem);
transform: rotate3d(1, 1, 1, 2deg);
}
</style>