blob: 03b15a13a4caf8f394cddc3c203b226162dc5d2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
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);
});
});
|