@@ -386,10 +386,10 @@ <h2 data-aos="fade" data-aos-duration="700" data-aos-delay="250">The Blood Pact
386
386
// Setting up the animated counter effect
387
387
let displayAge = 0 ;
388
388
resultElement . innerHTML = `
389
- <div style="font-size: 1rem; color: #2c3e50; text-align: center;">Your biological age is:</div>
390
- <div style="font-size: 2.5rem; color: #4CAF50; font-weight: bold; text-align: center;"><span id="animatedAge">0</span></div>
391
- <div id="yearsText" style="font-size: 1rem; color: #2c3e50; text-align: center;">years</div>
392
- ` ;
389
+ <div style="font-size: 1rem; color: #2c3e50; text-align: center;">Your biological age is:</div>
390
+ <div style="font-size: 2.5rem; color: #4CAF50; font-weight: bold; text-align: center;"><span id="animatedAge">0</span></div>
391
+ <div id="yearsText" style="font-size: 1rem; color: #2c3e50; text-align: center;">years</div>
392
+ ` ;
393
393
394
394
if ( isFirstTimeAnimation ) {
395
395
// Set the flag to false after the first run
@@ -430,6 +430,43 @@ <h2 data-aos="fade" data-aos-duration="700" data-aos-delay="250">The Blood Pact
430
430
isResultCalculated = true ;
431
431
}
432
432
433
+ // Mapping language or country codes to unit preferences
434
+ const unitPreferences = {
435
+ US : {
436
+ albuminUnit : '0.1' , // g/dL
437
+ creatinineUnit : '0.0113' , // mg/dL
438
+ glucoseUnit : '18.016' , // mg/dL
439
+ crpUnit : '10' , // mg/L
440
+ lymphocyteUnit : '1' , // %
441
+ mcvUnit : '1' , // fL
442
+ rcdwUnit : '1' , // %
443
+ apUnit : '1' , // U/L
444
+ wbcUnit : '1' // 1000 cells/μL
445
+ } ,
446
+ en_GB : {
447
+ albuminUnit : '1' , // g/L (SI unit, common in the UK)
448
+ creatinineUnit : '1' , // µmol/L
449
+ glucoseUnit : '1' , // mmol/L
450
+ crpUnit : '10' , // mg/L
451
+ lymphocyteUnit : '1' , // %
452
+ mcvUnit : '1' , // fL
453
+ rcdwUnit : '1' , // %
454
+ apUnit : '1' , // U/L
455
+ wbcUnit : '1' // 1000 cells/μL
456
+ } ,
457
+ default : {
458
+ albuminUnit : '1' , // g/L
459
+ creatinineUnit : '1' , // µmol/L
460
+ glucoseUnit : '1' , // mmol/L
461
+ crpUnit : '10' , // mg/L
462
+ lymphocyteUnit : '1' , // %
463
+ mcvUnit : '1' , // fL
464
+ rcdwUnit : '1' , // %
465
+ apUnit : '1' , // U/L
466
+ wbcUnit : '1' // 1000 cells/μL
467
+ }
468
+ } ;
469
+
433
470
document . addEventListener ( 'DOMContentLoaded' , function ( ) {
434
471
const unitSelects = document . querySelectorAll ( '.input-group select' ) ;
435
472
let maxWidth = 0 ;
@@ -470,7 +507,26 @@ <h2 data-aos="fade" data-aos-duration="700" data-aos-delay="250">The Blood Pact
470
507
if ( isFake ) {
471
508
fillFakeData ( ) ;
472
509
}
510
+
511
+ // Apply preferences on page load
512
+ applyLanguagePreferences ( ) ;
473
513
} ) ;
514
+
515
+ // Detect and apply preferences based on language
516
+ function applyLanguagePreferences ( ) {
517
+ const language = navigator . language || 'default' ; // Get browser language
518
+ const languageKey = language . replace ( '-' , '_' ) ; // Replace dash with underscore
519
+ const preferences = unitPreferences [ languageKey ] || unitPreferences . default ;
520
+
521
+ // Apply preferences to unit select elements
522
+ for ( const [ unitId , unitValue ] of Object . entries ( preferences ) ) {
523
+ const unitSelect = document . getElementById ( unitId ) ;
524
+ if ( unitSelect ) {
525
+ unitSelect . value = unitValue ;
526
+ }
527
+ }
528
+ }
529
+
474
530
function proceedToNextPage ( ) {
475
531
const yearInput = document . getElementById ( 'dob-year' ) . value ;
476
532
const monthInput = document . getElementById ( 'dob-month' ) . value ;
0 commit comments