File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ document.addEventListener("DOMContentLoaded", () => {
99
1010 let totalCitations = 0 ;
1111 let completedRequests = 0 ;
12+ let anyFailed = false ;
13+ const citationCounts = [ ] ;
1214
1315 citationElements . forEach ( el => {
1416 const doi = el . getAttribute ( 'data-doi' ) ;
@@ -18,19 +20,30 @@ document.addEventListener("DOMContentLoaded", () => {
1820 . then ( res => res . json ( ) )
1921 . then ( data => {
2022 const count = data . message [ 'is-referenced-by-count' ] || 0 ;
21-
2223 totalCitations += count ;
24+ citationCounts . push ( count ) ;
2325 el . textContent = `- CITATIONS: ${ count } -` ;
2426 } )
2527 . catch ( ( ) => {
2628 el . textContent = '' ;
29+ anyFailed = true ;
2730 } )
2831 . finally ( ( ) => {
2932 completedRequests ++ ;
3033
3134 // When all DOIs are processed, update total
32- if ( completedRequests === citationElements . length && totalDisplay ) {
33- totalDisplay . textContent = `- CITED BY: ${ totalCitations } -` ;
35+ if ( completedRequests === citationElements . length && totalDisplay && ! anyFailed ) {
36+ // Compute h‑index
37+ const sorted = citationCounts . slice ( ) . sort ( ( a , b ) => b - a ) ;
38+ let hIndex = 0 ;
39+ for ( let i = 0 ; i < sorted . length ; i ++ ) {
40+ if ( sorted [ i ] >= i + 1 ) {
41+ hIndex = i + 1 ;
42+ } else {
43+ break ;
44+ }
45+ }
46+ totalDisplay . textContent = `- CITED BY: ${ totalCitations } - H-INDEX: ${ hIndex } -` ;
3447 }
3548 } ) ;
3649 } ) ;
You can’t perform that action at this time.
0 commit comments