-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
225 lines (197 loc) · 10.1 KB
/
index.html
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
219
220
221
222
223
224
225
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-142108931-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-142108931-1');
</script>
<title>Animal Crossing Birthdays</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width"/>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link href='https://fonts.googleapis.com/css?family=Dekko' rel='stylesheet'>
<meta property="og:title" content="Animal Crossing Birthdays" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://ac-birthdays.com" />
<meta property="og:image" content="https://ac-birthdays.com/img/acbirthdays_final.png" />
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/moment.js"></script>
<script src="js/moment-timezone-with-data.js"></script>
<meta name="description" content="Study Animal Crossing Birthdays">
</head>
<body style="font-family: 'Dekko';">
<header>
</header>
<main>
<section>
<p class="body centerBody">NEW! AC: New Horizons challenge BINGO</p>
<div class="rowDiv">
<button onclick="location.href='/bingo'" class="largeButton">Play Challenge BINGO</button>
</div>
<h2 id="name" class="h2"></h2>
<div class="portraitDiv">
<img id="confettiImg" class="confettiImage portraitImage" src="img/confetti.png" />
<img id="characterImg" class="characterImage portraitImage" onclick="next()" />
<img class="nookipediaImg portraitImage" onclick="nookipedia()" src="img/nookipedia.png" />
</div>
<h3 id="birthday" class="h3"></h3>
<div class="rowDiv">
<input id="search" placeholder="Search" class="searchInput" />
<button onclick="search()" class="thinButton"><i class="fas fa-search fa-fw fa-lg" style="vertical-align: middle;"></i></button>
</div>
<div class="rowDiv">
<button onclick="random()" class="largeButton">Random</button>
<button onclick="back()" class="thinButton"><i class="fas fa-chevron-left fa-fw fa-lg" style="vertical-align: middle;"></i></button>
<button onclick="next()" class="thinButton"><i class="fas fa-chevron-right fa-fw fa-lg" style="vertical-align: middle;"></i></button>
</div>
<div class="rowDiv">
<button onclick="today()" class="largeButton">Today's Birthday</button>
</div>
</section>
<script type="text/javascript">
var state = {
characters: [],
curIndex: 0
}
$.getJSON("birthdays.json", function(json) {
$.each(json, function () {
var obj = this;
var imageUrl = "img/characters/"+obj["name"]+".png";
var birthday = moment.utc(obj["birthday"], "DD-MM-YYYY");
var char = {
id: obj["id"],
name: obj["name"],
birthday: birthday,
image: imageUrl
};
state.characters.push(char);
});
// Note: sourced birthdays.json from Nintendo is not sorted by birthdate
sortByBirthdayAndID(state.characters);
loadInitialVillager();
});
function isBirthday(birthdate) {
var currentDate = moment();
if ( birthdate.month() == currentDate.month()
&& birthdate.date() == currentDate.date()) {
return true;
}
return false;
}
function isUpcommingBirthday(birthdate) {
var currentDate = moment();
if ( birthdate.month() == currentDate.month()
&& birthdate.date() >= currentDate.date()) {
return true;
}
return false;
}
function loadInitialVillager() {
var i;
for (i = 0; i <= state.characters.length - 1; i++) {
var charBirthdate = state.characters[i].birthday;
if ( isBirthday(charBirthdate)
|| isUpcommingBirthday(charBirthdate) ) {
state.curIndex = i;
break;
}
}
load(state.characters[state.curIndex]);
}
function random() {
var rngIndex = Math.floor(state.characters.length * Math.random());
state.curIndex = rngIndex;
load(state.characters[rngIndex]);
}
function today() {
loadInitialVillager();
}
function back() {
if (state.curIndex <= 0)
state.curIndex = state.characters.length;
else {
state.curIndex--;
}
load(state.characters[state.curIndex]);
}
function next() {
if (state.curIndex >= state.characters.length)
state.curIndex = 0;
else {
state.curIndex++;
}
load(state.characters[state.curIndex]);
}
var searchState = {
searchFor: null,
characters: [],
curIndex: 0
}
function search() {
var searchFor = $("#search").val().trim();
if (searchFor.length == 0) {
return;
}
if (searchFor === searchState.searchFor) {
if (searchState.curIndex >= searchState.characters.length) {
searchState.curIndex = 0;
} else {
searchState.curIndex++;
}
} else {
searchState.curIndex = 0;
searchState.searchFor = searchFor;
searchState.characters = state.characters.filter(function(e, i, a) {
return e["name"].toLowerCase().includes(searchFor.toLowerCase()) || e["name"].toLowerCase() == searchFor.toLowerCase();
});
}
if (searchState.characters.length > 0) {
var character = searchState.characters[searchState.curIndex];
state.curIndex = state.characters.findIndex(char => char["id"] === character["id"]);
load(state.characters[state.curIndex]);
}
}
document.getElementById('search').onkeypress = function(e){
if (!e) e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == '13') {
search();
}
}
function sortByBirthdayAndID(a) {
a.sort(compareBirthdayAndID);
}
function compareBirthdayAndID(a, b) {
return (a.birthday.utc() > b.birthday.utc()) || ( a.birthday.utc() == b.birthday.utc() && a.id > b.id ) ? 1 : -1;
}
function load(obj) {
var _img = document.getElementById('characterImg');
_img.onload = function() {
$("#name").text(obj["name"]);
$("#birthday").text(obj["birthday"].format("MMM Do YYYY"));
confettiImg.style.visibility = isBirthday(obj["birthday"]) ? "visible" : "hidden";
}
_img.onerror = function() {
$("#name").text(obj["name"]);
$("#birthday").text(obj["birthday"].format("MMM Do YYYY"));
confettiImg.style.visibility = isBirthday(obj["birthday"]) ? "visible" : "hidden";
}
_img.src = obj["image"];
}
function nookipedia() {
window.open("https://nookipedia.com/wiki/" + encodeURIComponent(state.characters[state.curIndex].name))
}
</script>
</main>
<footer>
<br/>
<br/>
<p class="footer"><a class="footerLink" href="https://creativecommons.org/licenses/by-sa/3.0/legalcode">CC BY-SA 3.0</a> ac-birthdays is neither owned by nor affiliated with Nintendo or the creators of Animal Crossing. © 2001 - 2020 Nintendo. Nintendo properties are trademarks of Nintendo. Images and data from <a class="footerLink" href="https://animal-crossing.com">https://animal-crossing.com</a> and <a class="footerLink" href="https://nookipedia.com">https://nookipedia.com</a>. Created by <a class="footerLink"href="https://jefhai.com">jefhai.com</a></p>
</footer>
</body>
</html>