@@ -372,7 +372,31 @@ function sortAndSliceData(companyCounts) {
372372
373373document . addEventListener ( 'DOMContentLoaded' , async function ( ) {
374374
375- async function fetchOffers ( ) {
375+ async function fetchLastUpdatedPhrase ( ) {
376+ const span = document . getElementById ( 'lastUpdatedPhrase' ) ;
377+ if ( ! span ) return ;
378+ const url = 'https://api.github.com/repos/kuutsav/leetcode-compensation/commits?sha=master&path=data&per_page=1' ;
379+ try {
380+ const res = await fetch ( url , { headers : { Accept : 'application/vnd.github+json' } } ) ;
381+ if ( ! res . ok ) throw new Error ( ) ;
382+ const commit = ( await res . json ( ) ) [ 0 ] ;
383+ const date = commit ?. commit ?. committer ?. date || commit ?. commit ?. author ?. date ;
384+ span . textContent = `updated ${ date ? formatTimeAgo ( new Date ( date ) ) : 'recently' } ↺` ;
385+ } catch {
386+ span . textContent = 'updated recently ↺' ;
387+ }
388+ }
389+
390+ function formatTimeAgo ( date ) {
391+ const mins = Math . floor ( ( Date . now ( ) - date ) / 60000 ) ;
392+ const rtf = Intl ?. RelativeTimeFormat && new Intl . RelativeTimeFormat ( undefined , { numeric : 'auto' } ) ;
393+ const fmt = ( v , u ) => rtf ? rtf . format ( - v , u ) : `${ v } ${ u } ${ v !== 1 ? 's' : '' } ago` ;
394+ if ( mins < 60 ) return fmt ( mins , 'minute' ) ;
395+ const hrs = Math . floor ( mins / 60 ) ;
396+ if ( hrs < 24 ) return fmt ( hrs , 'hour' ) ;
397+ return fmt ( Math . floor ( hrs / 24 ) , 'day' ) ;
398+ }
399+ async function fetchOffers ( ) {
376400 const response = await fetch ( 'data/parsed_comps.json' ) ;
377401 const data = await response . json ( ) ;
378402 offers = data ;
@@ -382,7 +406,8 @@ document.addEventListener('DOMContentLoaded', async function () {
382406 }
383407
384408 await fetchOffers ( ) ;
385-
409+ // Fetch and show last updated phrase
410+ fetchLastUpdatedPhrase ( ) ;
386411 // Initialize charts and stats
387412 setStatsStr ( filteredOffers ) ;
388413 plotHistogram ( filteredOffers , 'total' ) ;
0 commit comments