Skip to content

Commit 1cee590

Browse files
authored
Create script.js
1 parent 1487519 commit 1cee590

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

assets/script.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
document.querySelectorAll('.citation[data-doi]').forEach(el => {
2+
const doi = el.getAttribute('data-doi');
3+
const id = el.id;
4+
5+
const url = `https://api.crossref.org/works/${encodeURIComponent(doi)}`;
6+
fetch(url)
7+
.then(res => res.json())
8+
.then(data => {
9+
const count = data.message['is-referenced-by-count'];
10+
el.textContent = `- CITATIONS: ${count} -`;
11+
})
12+
.catch(() => {
13+
el.textContent = '';
14+
});
15+
});

0 commit comments

Comments
 (0)