import * as ajax from './lib/ajax'; import * as dom from './lib/dom'; async function updateLikeCount(el) { const type = parseInt(el.getAttribute('content-type'), 10); const contentId = parseInt(el.getAttribute('content-id'), 10); if (isNaN(type) || isNaN(contentId)) { return; } const count = await ajax.get(`/api/likes/count?id=${contentId}&type=${type}`, {}); el.textContent = count; } dom.ready(() => { dom.withClass('like-count') .forEach(el => { updateLikeCount(el); }); });