@@ -3,19 +3,35 @@ document.addEventListener("DOMContentLoaded", () => {
33 papers . forEach ( ( paper , index ) => {
44 paper . style . animationDelay = `${ index * 0.25 } s` ;
55 } ) ;
6- } ) ;
76
8- document . querySelectorAll ( '.citation[data-doi]' ) . forEach ( el => {
9- const doi = el . getAttribute ( 'data-doi ') ;
7+ const citationElements = document . querySelectorAll ( '.citation[data-doi]' ) ;
8+ const totalDisplay = document . querySelector ( '.citations ') ;
109
11- const url = `https://api.crossref.org/works/${ encodeURIComponent ( doi ) } ` ;
12- fetch ( url )
13- . then ( res => res . json ( ) )
14- . then ( data => {
15- const count = data . message [ 'is-referenced-by-count' ] ;
16- el . textContent = `- CITATIONS: ${ count } -` ;
17- } )
18- . catch ( ( ) => {
19- el . textContent = '' ;
20- } ) ;
10+ let totalCitations = 0 ;
11+ let completedRequests = 0 ;
12+
13+ citationElements . forEach ( el => {
14+ const doi = el . getAttribute ( 'data-doi' ) ;
15+ const url = `https://api.crossref.org/works/${ encodeURIComponent ( doi ) } ` ;
16+
17+ fetch ( url )
18+ . then ( res => res . json ( ) )
19+ . then ( data => {
20+ const count = data . message [ 'is-referenced-by-count' ] || 0 ;
21+
22+ totalCitations += count ;
23+ el . textContent = `- CITATIONS: ${ count } -` ;
24+ } )
25+ . catch ( ( ) => {
26+ el . textContent = '' ;
27+ } )
28+ . finally ( ( ) => {
29+ completedRequests ++ ;
30+
31+ // When all DOIs are processed, update total
32+ if ( completedRequests === citationElements . length && totalDisplay ) {
33+ totalDisplay . textContent = `- CITED BY: ${ totalCitations } -` ;
34+ }
35+ } ) ;
36+ } ) ;
2137} ) ;
0 commit comments