class PackageIndexEntry { name; description; website; version; report; } function toHTML(entry) { let v = entry.version != null ? `${escapeHtml(entry.version)}` : ""; let d = entry.description != null ? `

${escapeHtml(entry.description)}

` : ""; let w = entry.website != null ? `Website` : ""; let r = entry.report ? `Log (View | Download)` : ""; let row = (document.createElement('tr')); row.innerHTML = `

${escapeHtml(entry.name)} ${v}

${d} ${w} ${r} `; return row; } const API_VERSION = 1; const ENDPOINT = `/api/v${API_VERSION}`; class InfoPayload { count; hakurei_version; } async function infoRequest() { const res = await fetch(`${ENDPOINT}/info`); const res_1 = await res.json(); return res_1; } class GetPayload { count; values; } var SortOrders; (function (SortOrders) { SortOrders[SortOrders["DeclarationAscending"] = 0] = "DeclarationAscending"; SortOrders[SortOrders["DeclarationDescending"] = 1] = "DeclarationDescending"; SortOrders[SortOrders["NameAscending"] = 2] = "NameAscending"; SortOrders[SortOrders["NameDescending"] = 3] = "NameDescending"; })(SortOrders || (SortOrders = {})); async function getRequest(limit, index, sort) { const res = await fetch(`${ENDPOINT}/get?limit=${limit}&index=${index}&sort=${sort.valueOf()}`); const res_1 = await res.json(); return res_1; } class State { entriesPerPage = 10; currentPage = 1; entryIndex = 0; maxEntries = 0; getEntriesPerPage() { return this.entriesPerPage; } setEntriesPerPage(entriesPerPage) { this.entriesPerPage = entriesPerPage; if (this.currentPage > this.getMaxPage()) { this.setCurrentPage(this.getMaxPage()); } } getCurrentPage() { return this.currentPage; } setCurrentPage(page) { this.currentPage = page; this.setEntryIndex((this.getCurrentPage() - 1) * this.getEntriesPerPage()); document.getElementById("page-number").innerText = String(this.getCurrentPage()); } getEntryIndex() { return this.entryIndex; } setEntryIndex(entryIndex) { this.entryIndex = entryIndex; this.updateRange(); this.updateListings(); } getMaxEntries() { return this.maxEntries; } setMaxEntries(max) { this.maxEntries = max; } getMaxPage() { return Math.ceil(this.getMaxEntries() / this.getEntriesPerPage()); } updateRange() { let max = Math.min(this.getEntryIndex() + this.getEntriesPerPage(), this.getMaxEntries()); document.getElementById("entry-counter").innerText = `${this.getEntryIndex() + 1}-${max} of ${this.getMaxEntries()}`; } updateListings() { getRequest(this.getEntriesPerPage(), this.entryIndex, 0) .then(res => { let table = document.getElementById("pkg-list"); table.innerHTML = ''; for (let i = 0; i < res.count; i++) { table.appendChild(toHTML(res.values[i])); } }); } } let STATE; function prevPage() { let current = STATE.getCurrentPage(); if (current > 1) { STATE.setCurrentPage(STATE.getCurrentPage() - 1); } } function nextPage() { let current = STATE.getCurrentPage(); if (current < STATE.getMaxPage()) { STATE.setCurrentPage(STATE.getCurrentPage() + 1); } } function escapeHtml(str) { return str .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } document.addEventListener("DOMContentLoaded", () => { STATE = new State(); infoRequest() .then(res => { STATE.setMaxEntries(res.count); document.getElementById("hakurei-version").innerText = res.hakurei_version; STATE.updateRange(); STATE.updateListings(); }); document.getElementById("count").addEventListener("change", (event) => { STATE.setEntriesPerPage(parseInt(event.target.value)); }); });