-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (51 loc) · 2.25 KB
/
index.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
import { bggClient, ThingTypeEnum } from './modules/bgg-client/index.js';
document.addEventListener('DOMContentLoaded', async () => {
const boardGamesIdsByRank = await bggClient.getBoardGamesIdsByRank();
const boardGames = await bggClient.getThingItems({
ids: boardGamesIdsByRank,
thingTypes: [ThingTypeEnum.BoardGame],
stats: true,
});
const boardGamesSortedByWeight = _.sortBy(boardGames, [
function (boardGame) {
return -boardGame.statistics.averageweight;
},
]);
const boardGamesWeightRankingTableBody = document
.getElementById('board-games-weight-ranking-table')
.querySelector('tbody');
for (const boardGame of boardGamesSortedByWeight) {
const newRow = boardGamesWeightRankingTableBody.insertRow();
const thumbnailCell = newRow.insertCell();
const thumbnailNode = document.createElement('img');
thumbnailNode.src = boardGame.thumbnail;
thumbnailCell.appendChild(thumbnailNode);
const nameCell = newRow.insertCell();
const nameNode = document.createElement('div');
nameNode.textContent = boardGame.name;
nameNode.className = 'has-text-weight-medium';
nameCell.appendChild(nameNode);
const averageWeightCell = newRow.insertCell();
const averageWeightNode = document.createElement('div');
averageWeightNode.textContent = boardGame.statistics.averageweight;
averageWeightNode.className = 'has-text-weight-semibold';
averageWeightCell.appendChild(averageWeightNode);
const numWeightsCell = newRow.insertCell();
const numWeightsNode = document.createTextNode(
boardGame.statistics.numweights
);
numWeightsCell.appendChild(numWeightsNode);
const rankCell = newRow.insertCell();
const rankNode = document.createTextNode(
boardGame.statistics.ranks.find((rank) => rank.name === 'boardgame').value
);
rankCell.appendChild(rankNode);
const yearPublishedCell = newRow.insertCell();
const yearPublishedNode = document.createTextNode(boardGame.yearpublished);
yearPublishedCell.appendChild(yearPublishedNode);
const descriptionCell = newRow.insertCell();
const descriptionNode = document.createElement('div');
descriptionNode.innerHTML = boardGame.description;
descriptionCell.appendChild(descriptionNode);
}
});