-
Notifications
You must be signed in to change notification settings - Fork 0
/
historic.html
257 lines (219 loc) · 10.8 KB
/
historic.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lonewolf Auctionhouse</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css">
<script>const whTooltips = {colorLinks: true, iconizeLinks: true, renameLinks: true};</script>
<script src="https://wow.zamimg.com/js/tooltips.js"></script>
</head>
<body class="bg-dark text-white">
<div class="container mt-5">
<h1 class="text-center mb-4">Lonewolf</h1>
<div class="input-group mb-3">
<input type="text" class="form-control" id="searchInput" placeholder="Search for an item">
<div class="input-group-append">
<button id="searchButton" class="btn btn-outline-secondary">Search</button>
</div>
</div>
<!-- Loading spinner -->
<div id="loadingSpinner" class="text-center" style="display: none;">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
<p>Loading...</p>
</div>
<table id="resultsTable" class="table table-dark table-striped">
<thead>
<tr>
<th>Item Name</th>
<th>Min Buyout (Latest)</th>
<th>Day % Change</th>
<th>Week % Change</th>
<th>Month % Change</th>
<th>Quantity</th>
<th>Num Auctions</th>
<th>Price History Chart</th>
</tr>
</thead>
<tbody>
<!-- The table content will be filled using JavaScript -->
</tbody>
</table>
<!-- Container for dynamically generated charts -->
<div id="chartContainer"></div>
<!-- Console logs container -->
<div id="consoleLogs" class="mt-5"></div>
</div>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- DataTables JS and its Bootstrap 4 integration -->
<script type="text/javascript" src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap4.min.js"></script>
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
let itemsData = [];
let pricingData = [];
let dayPricingData = [];
let weekPricingData = [];
let monthPricingData = [];
// Function to show loading spinner
function showLoadingSpinner() {
$('#loadingSpinner').show();
}
// Function to hide loading spinner
function hideLoadingSpinner() {
$('#loadingSpinner').hide();
}
// Load items data from items.json
fetch('items.json')
.then(response => response.json())
.then(data => {
itemsData = data.items;
})
.catch(error => {
console.error("Error fetching items data: ", error);
});
// Load pricing data from the JSON files
fetch('prices/latest.json')
.then(response => response.json())
.then(jsonData => {
pricingData = jsonData.pricing_data;
})
.catch(error => {
console.error("Error fetching pricing data: ", error);
});
fetch('prices/day.json')
.then(response => response.json())
.then(jsonData => {
dayPricingData = jsonData.pricing_data;
})
.catch(error => {
console.error("Error fetching day pricing data: ", error);
});
fetch('prices/week.json')
.then(response => response.json())
.then(jsonData => {
weekPricingData = jsonData.pricing_data;
})
.catch(error => {
console.error("Error fetching week pricing data: ", error);
});
fetch('prices/month.json')
.then(response => response.json())
.then(jsonData => {
monthPricingData = jsonData.pricing_data;
})
.catch(error => {
console.error("Error fetching month pricing data: ", error);
});
function searchItem() {
// Show loading spinner while searching
showLoadingSpinner();
// Resetting the DataTable and table content
if ($.fn.dataTable.isDataTable('#resultsTable')) {
$('#resultsTable').DataTable().clear().destroy();
}
let searchInput = document.getElementById("searchInput").value.toLowerCase();
let tableContent = '';
let chartData = [];
itemsData.forEach(item => {
const itemPricingLatest = pricingData.find(pricing => pricing.itemId === item.entry);
const itemPricingDay = dayPricingData.find(pricing => pricing.itemId === item.entry);
const itemPricingWeek = weekPricingData.find(pricing => pricing.itemId === item.entry);
const itemPricingMonth = monthPricingData.find(pricing => pricing.itemId === item.entry);
if (itemPricingLatest && itemPricingDay && itemPricingWeek && itemPricingMonth && item.name.toLowerCase().includes(searchInput)) {
const minBuyoutLatest = itemPricingLatest.minBuyout;
const minBuyoutDay = itemPricingDay.minBuyout;
const minBuyoutWeek = itemPricingWeek.minBuyout;
const minBuyoutMonth = itemPricingMonth.minBuyout;
const percentageChangeDay = ((minBuyoutLatest - minBuyoutDay) / minBuyoutDay) * 100;
const percentageChangeWeek = ((minBuyoutLatest - minBuyoutWeek) / minBuyoutWeek) * 100;
const percentageChangeMonth = ((minBuyoutLatest - minBuyoutMonth) / minBuyoutMonth) * 100;
const dayChangeClass = percentageChangeDay < 0 ? 'text-danger' : 'text-success';
const weekChangeClass = percentageChangeWeek < 0 ? 'text-danger' : 'text-success';
const monthChangeClass = percentageChangeMonth < 0 ? 'text-danger' : 'text-success';
const minBuyoutGold = Math.floor(minBuyoutLatest / 10000);
const minBuyoutSilver = Math.floor((minBuyoutLatest % 10000) / 100);
const minBuyoutCopper = minBuyoutLatest % 100;
const minBuyoutFormatted = `<span style="color:gold">${minBuyoutGold}g</span><span style="color:silver">${minBuyoutSilver}s</span><span style="color:chocolate">${minBuyoutCopper}c</span>`;
const wowheadLink = `<a href="https://www.wowhead.com/wotlk/item=${item.entry}" data-wowhead="item=${item.entry}" target="_blank">${item.name}</a>`;
tableContent += `<tr>
<td>${wowheadLink}</td>
<td>${minBuyoutFormatted}</td>
<td class="${dayChangeClass}">${percentageChangeDay.toFixed(2)}%</td>
<td class="${weekChangeClass}">${percentageChangeWeek.toFixed(2)}%</td>
<td class="${monthChangeClass}">${percentageChangeMonth.toFixed(2)}%</td>
<td>${itemPricingLatest.quantity}</td>
<td>${itemPricingLatest.numAuctions}</td>
<td><canvas id="${item.name.replace(/\s/g, '')}Chart" width="200" height="100"></canvas></td>
</tr>`;
// Prepare data for chart
chartData.push({
label: item.name,
data: [minBuyoutLatest, minBuyoutDay, minBuyoutWeek, minBuyoutMonth],
backgroundColor: 'rgba(255, 99, 132, 0.2)', // Example color
borderColor: 'rgba(255, 99, 132, 1)', // Example color
borderWidth: 1
});
}
});
$('#resultsTable tbody').html(tableContent);
// Initialize the DataTable
$('#resultsTable').DataTable();
// Generate charts
generateCharts(chartData);
// Hide loading spinner after search
hideLoadingSpinner();
}
// Function to generate charts using Chart.js
function generateCharts(data) {
// Clear previous charts
document.getElementById('chartContainer').innerHTML = '';
// Create chart canvas elements
data.forEach(item => {
const canvas = document.createElement('canvas');
canvas.id = item.label.replace(/\s/g, ''); // Remove spaces from label for canvas ID
canvas.width = 400;
canvas.height = 200;
// Find the corresponding table row and append the canvas to the last cell
const tableRow = document.getElementById(item.label.replace(/\s/g, '') + 'Row');
if (tableRow) {
const lastCell = tableRow.cells[tableRow.cells.length - 1];
lastCell.appendChild(canvas);
}
// Generate chart
new Chart(canvas.getContext('2d'), {
type: 'line',
data: {
labels: ['Latest', 'Day', 'Week', 'Month'],
datasets: [item]
},
options: {
responsive: false,
maintainAspectRatio: false
}
});
});
}
// Set up the Enter key event listener here, outside of the searchPlayer function
document.getElementById("searchInput").addEventListener("keyup", function(event) {
// Number 13 is the "Enter" key on the keyboard
if (event.keyCode === 13) {
// Cancel the default action (if any)
event.preventDefault();
// Trigger the search function
searchItem();
}
});
// Add event listener for search button click
document.getElementById("searchButton").addEventListener("click", function() {
searchItem();
});
</script>
</body>
</html>