Added last updated message
This commit is contained in:
		
							parent
							
								
									b1df8dfc7a
								
							
						
					
					
						commit
						7905df4f52
					
				
					 3 changed files with 40 additions and 1 deletions
				
			
		
							
								
								
									
										1
									
								
								base.css
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								base.css
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -33,6 +33,7 @@ body {
 | 
			
		|||
footer {
 | 
			
		||||
	margin-top: auto;
 | 
			
		||||
	display: flex;
 | 
			
		||||
	align-items: flex-end;
 | 
			
		||||
 | 
			
		||||
	background-color: #e0e0e0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,3 +82,9 @@
 | 
			
		|||
	text-align: center;
 | 
			
		||||
	grid-area: platform;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.last-refreshed {
 | 
			
		||||
	font-size: 12px;
 | 
			
		||||
	text-transform: none;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@ var date
 | 
			
		|||
var showKm = false
 | 
			
		||||
 | 
			
		||||
var trainData = null
 | 
			
		||||
var lastSuccessfulFetch = null
 | 
			
		||||
 | 
			
		||||
function onTrainData(data) {
 | 
			
		||||
	var title = document.getElementsByTagName('h1')[0]
 | 
			
		||||
| 
						 | 
				
			
			@ -186,11 +187,13 @@ function onTrainData(data) {
 | 
			
		|||
			stationPlatform.classList.add('thi', 'platform')
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	lastSuccessfulFetch = new Date()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var refreshStopToken = null
 | 
			
		||||
function refresh() {
 | 
			
		||||
	fetch(`https://scraper.infotren.dcdev.ro/v2/train/${trainNumber}?date=${date.getFullYear().toString()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`)
 | 
			
		||||
	return fetch(`https://scraper.infotren.dcdev.ro/v2/train/${trainNumber}?date=${date.getFullYear().toString()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`)
 | 
			
		||||
		.then(function (response) {
 | 
			
		||||
			return response.json()
 | 
			
		||||
		})
 | 
			
		||||
| 
						 | 
				
			
			@ -277,4 +280,33 @@ window.addEventListener('load', function (e) {
 | 
			
		|||
	})
 | 
			
		||||
 | 
			
		||||
	refresh()
 | 
			
		||||
 | 
			
		||||
	setInterval(function () {
 | 
			
		||||
		if (!lastSuccessfulFetch) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		var millis = new Date() - lastSuccessfulFetch
 | 
			
		||||
		var secs = Math.floor(millis / 1000)
 | 
			
		||||
		
 | 
			
		||||
		var timeStr = ''
 | 
			
		||||
		if (secs / 3600 >= 1) {
 | 
			
		||||
			timeStr += `${Math.floor(secs / 3600)}h`
 | 
			
		||||
			secs = secs % 3600
 | 
			
		||||
		}
 | 
			
		||||
		if (secs / 60 >= 1) {
 | 
			
		||||
			timeStr += `${Math.floor(secs / 60)}m`
 | 
			
		||||
			secs = secs % 60
 | 
			
		||||
		}
 | 
			
		||||
		if (secs >= 1) {
 | 
			
		||||
			timeStr += `${Math.floor(secs)}s`
 | 
			
		||||
		}
 | 
			
		||||
		if (!timeStr) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		document.querySelectorAll('.lsk').forEach(function (elem) {
 | 
			
		||||
			elem.textContent = `Last refreshed ${timeStr} ago`
 | 
			
		||||
			elem.classList.add('last-refreshed')
 | 
			
		||||
		})
 | 
			
		||||
	}, 500)
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue