Manipulate history when viewing yesterday's train
This commit is contained in:
		
							parent
							
								
									0833765a84
								
							
						
					
					
						commit
						708f25ce83
					
				
					 2 changed files with 18 additions and 2 deletions
				
			
		
							
								
								
									
										2
									
								
								sw.js
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								sw.js
									
										
									
									
									
								
							| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
const VERSION = 'v33'
 | 
					const VERSION = 'v34'
 | 
				
			||||||
const API_ORIGIN = 'https://scraper.infotren.dcdev.ro/'
 | 
					const API_ORIGIN = 'https://scraper.infotren.dcdev.ro/'
 | 
				
			||||||
const API_TRAINS = `${API_ORIGIN}v3/trains`
 | 
					const API_TRAINS = `${API_ORIGIN}v3/trains`
 | 
				
			||||||
const API_STATIONS = `${API_ORIGIN}v3/stations`
 | 
					const API_STATIONS = `${API_ORIGIN}v3/stations`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -89,6 +89,16 @@ function onTrainData(data, fetchDate) {
 | 
				
			||||||
		e.preventDefault()
 | 
							e.preventDefault()
 | 
				
			||||||
		// Implement date switcher
 | 
							// Implement date switcher
 | 
				
			||||||
		yesterday = !yesterday
 | 
							yesterday = !yesterday
 | 
				
			||||||
 | 
							if (!yesterday) {
 | 
				
			||||||
 | 
								history.back()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else {
 | 
				
			||||||
 | 
								const yesterdayUrl = new URL(location.href)
 | 
				
			||||||
 | 
								const newDate = new Date(date.getTime())
 | 
				
			||||||
 | 
								newDate.setDate(newDate.getDate() - 1)
 | 
				
			||||||
 | 
								yesterdayUrl.searchParams.set('date', newDate.toISOString())
 | 
				
			||||||
 | 
								history.pushState('', '', yesterdayUrl)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		refresh()
 | 
							refresh()
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -495,7 +505,13 @@ function rsk() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
window.addEventListener('popstate', function (e) {
 | 
					window.addEventListener('popstate', function (e) {
 | 
				
			||||||
	groupIndex = null
 | 
						if (yesterday) {
 | 
				
			||||||
 | 
							yesterday = false
 | 
				
			||||||
 | 
							trainData = null
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else {
 | 
				
			||||||
 | 
							groupIndex = null
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if (trainData) {
 | 
						if (trainData) {
 | 
				
			||||||
		onTrainData(trainData)
 | 
							onTrainData(trainData)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue