-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
161 lines (145 loc) Β· 4.02 KB
/
main.js
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
import Alpine from "alpinejs";
import { fetchHelpful, addHelpfulVote } from "./helpers/fetch-helper.js";
import { getHasVoted, setHasVoted } from "./helpers/local-storage-helper";
import { generate } from "./helpers/hardcore-helper.js";
import {
formatDate,
getClassicHolidays,
getWOTLKHolidays,
isHoliday,
isPast,
} from "./helpers/date-helper.js";
window.Alpine = Alpine;
const getBrownBread = () => {
const brownBread = localStorage.getItem("brownBread");
if (!brownBread) {
return [];
}
return JSON.parse(brownBread);
};
const getAlive = () => {
const alive = localStorage.getItem("alive");
if (!alive) {
return null;
}
return JSON.parse(alive);
};
document.addEventListener("alpine:init", () => {
Alpine.data("classicEraHolidays", () => ({
year: new Date().getFullYear(),
dates() {
const warsongEpoch = new Date(2020, 2, 13);
const arathiEpoch = new Date(2020, 2, 20);
const alteracEpoch = new Date(2020, 3, 3);
const start = new Date(2020, 2, 13);
return getClassicHolidays(
this.year,
warsongEpoch,
arathiEpoch,
alteracEpoch,
start
);
},
incrementYear() {
++this.year;
},
decrementYear() {
const epochYear = 2020;
if (this.year > epochYear) {
--this.year;
}
},
isDecrementDisabled() {
const epochYear = 2020;
return this.year === epochYear;
},
formatDate,
isPast,
isHoliday,
}));
Alpine.data("wotlkHolidays", () => ({
year: new Date().getFullYear(),
dates() {
return getWOTLKHolidays(this.year);
},
incrementYear() {
++this.year;
},
decrementYear() {
const epochYear = 2022;
if (this.year > epochYear) {
--this.year;
}
},
isDecrementDisabled() {
const epochYear = 2022;
return this.year === epochYear;
},
formatDate,
isPast,
isHoliday,
}));
Alpine.data("foundHelpful", () => ({
hasVoted: getHasVoted("https://wowaholic.com/"),
text: "",
async getVotes() {
this.text = "Be right with ya, laddie...";
this.votes = await fetchHelpful("go-again.html");
if (this.hasVoted) {
if (this.votes === -1) {
this.text = "Looks like something has gone wrong on our end, laddie";
} else if (this.votes === 1) {
this.text = `You are the first Dwarven brethren that found this helpful`;
} else {
this.text = `You and ${
this.votes - 1
} Dwarven brethren found this helpful`;
}
} else {
if (this.votes === -1) {
this.text = "Looks like something has gone wrong on our end, laddie";
} else if (this.votes === 0) {
this.text = "Be the first to find this helpful, laddie";
} else {
this.text = `${this.votes} Dwarven brethren found this helpful`;
}
}
},
async addVote() {
if (this.hasVoted) {
return;
}
this.text = "Be right with ya, laddie...";
this.votes = await addHelpfulVote();
setHasVoted("https://wowaholic.com/go-again.html");
this.hasVoted = true;
if (this.votes === 1) {
this.text = `You are the first Dwarven brethren that found this helpful`;
} else {
this.text = `You and ${
this.votes - 1
} Dwarven brethren found this helpful`;
}
},
}));
Alpine.data("goAgain", () => ({
choice: getAlive(),
brownBread: getBrownBread(),
generateChoice() {
const chosen = generate();
localStorage.setItem("alive", JSON.stringify(chosen));
if (!this.choice) {
this.choice = chosen;
return;
}
this.brownBread.unshift({ ...this.choice });
localStorage.setItem("brownBread", JSON.stringify(this.brownBread));
this.choice.id = chosen.id;
this.choice.faction = chosen.faction;
this.choice.chosenClass = chosen.chosenClass;
this.choice.isMale = chosen.isMale;
this.choice.img = chosen.img;
},
}));
});
Alpine.start();