commit | author | age
|
f4a54f
|
1 |
"use strict"; |
JK |
2 |
|
4bfa36
|
3 |
var ttss_urls = { |
JK |
4 |
t: 'proxy_tram.php', |
|
5 |
// t: 'http://www.ttss.krakow.pl/internetservice', |
|
6 |
b: 'proxy_bus.php', |
|
7 |
// b: 'http://91.223.13.70/internetservice', |
|
8 |
}; |
|
9 |
var ttss_types = ['t', 'b']; |
cbce8b
|
10 |
|
68aeb4
|
11 |
// Special directions |
JK |
12 |
var special_directions = { |
c57bed
|
13 |
'Zajezdnia Nowa Huta' : 'ZH', |
JK |
14 |
'Zajezdnia Podgórze' : 'ZP', |
|
15 |
'Zjazd do zajezdni' : 'Z', |
|
16 |
'Wyjazd na linię' : 'W', |
|
17 |
'Przejazd techniczny' : 'PT', |
68aeb4
|
18 |
}; |
JK |
19 |
|
572390
|
20 |
var script_version; |
JK |
21 |
var script_version_xhr; |
|
22 |
|
b16328
|
23 |
var vehicles_info = {}; |
f0bae0
|
24 |
|
572390
|
25 |
// Check for website updates |
JK |
26 |
function checkVersion() { |
|
27 |
if(script_version_xhr) script_version_xhr.abort(); |
|
28 |
|
|
29 |
script_version_xhr = $.get( |
|
30 |
'version.php' |
|
31 |
).done(function(data) { |
|
32 |
if(!script_version) { |
|
33 |
script_version = data; |
|
34 |
return; |
|
35 |
} |
|
36 |
|
|
37 |
if(script_version != data) { |
|
38 |
fail(lang.error_new_version); |
|
39 |
location.reload(true); |
|
40 |
} |
|
41 |
}); |
|
42 |
} |
|
43 |
|
|
44 |
function checkVersionInit() { |
|
45 |
checkVersion(); |
|
46 |
setInterval(checkVersion, 3600000); |
|
47 |
} |
|
48 |
|
8b6250
|
49 |
/* Parsing of received JSON parts */ |
JK |
50 |
function parseStatus(status) { |
|
51 |
switch(status.status) { |
|
52 |
case 'STOPPING': |
|
53 |
case 'PREDICTED': |
|
54 |
if(status.actualRelativeTime <= 0) |
|
55 |
return lang.boarding_sign; |
|
56 |
if(status.actualRelativeTime >= 60) |
|
57 |
return lang.time_minutes_prefix + Math.floor(status.actualRelativeTime / 60) + lang.time_minutes_suffix; |
|
58 |
return lang.time_seconds_prefix + status.actualRelativeTime + lang.time_seconds_suffix; |
|
59 |
case 'DEPARTED': |
|
60 |
return lang.time_minutes_ago_prefix + Math.floor(-status.actualRelativeTime / 60) + lang.time_minutes_ago_suffix; |
|
61 |
default: |
|
62 |
return status.mixedTime; |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
function parseTime(date, time) { |
|
67 |
var result = new Date(date.getFullYear(), date.getMonth(), date.getDay()); |
|
68 |
var time_split = time.split(':'); |
|
69 |
result.setHours(time_split[0]); |
|
70 |
result.setMinutes(time_split[1]); |
|
71 |
|
|
72 |
if(result.getTime() - date.getTime() > 72000000) { |
|
73 |
result.setTime(result.getTime() - 86400000); |
|
74 |
} |
|
75 |
|
|
76 |
if(date.getTime() - result.getTime() > 72000000) { |
|
77 |
result.setTime(result.getTime() + 86400000); |
|
78 |
} |
|
79 |
|
|
80 |
return result; |
|
81 |
} |
|
82 |
|
|
83 |
function parseDelay(status) { |
|
84 |
if(!status.actualTime) return lang.unknown_sign; |
|
85 |
if(!status.plannedTime) return lang.unknown_sign; |
|
86 |
|
|
87 |
var now = new Date(); |
|
88 |
var actual = parseTime(now, status.actualTime); |
|
89 |
var planned = parseTime(now, status.plannedTime); |
|
90 |
|
|
91 |
return lang.time_minutes_prefix + ((actual.getTime() - planned.getTime()) / 1000 / 60) + lang.time_minutes_suffix; |
|
92 |
} |
|
93 |
|
68aeb4
|
94 |
// Webservice-related functions |
JK |
95 |
function parseVehicle(vehicleId) { |
765604
|
96 |
if(!vehicleId) return false; |
f0bae0
|
97 |
if(!vehicles_info || !vehicles_info[vehicleId]) { |
765604
|
98 |
return false; |
68aeb4
|
99 |
} else { |
f0bae0
|
100 |
var vehicle = vehicles_info[vehicleId]; |
JK |
101 |
return { |
|
102 |
vehicleId: vehicleId, |
|
103 |
prefix: vehicle['num'].substr(0, 2), |
|
104 |
id: vehicle['num'].substr(2, 3), |
|
105 |
num: vehicle['num'], |
|
106 |
type: vehicle['type'], |
|
107 |
low: vehicle['low'] |
|
108 |
}; |
68aeb4
|
109 |
} |
f0bae0
|
110 |
} |
JK |
111 |
|
|
112 |
function updateVehicleInfo() { |
|
113 |
return $.get( |
|
114 |
'https://mpk.jacekk.net/vehicles/' |
|
115 |
).done(function(data) { |
|
116 |
vehicles_info = data; |
|
117 |
}); |
68aeb4
|
118 |
} |
JK |
119 |
|
f4a54f
|
120 |
function depotIdToVehicleId(depotId, typeHelper) { |
JK |
121 |
if(typeHelper) { |
|
122 |
for(var prop in vehicles_info) { |
d06aef
|
123 |
if(prop.substr(0,1) == typeHelper && vehicles_info[prop]['num'].substr(2) == depotId) { |
f4a54f
|
124 |
return prop; |
JK |
125 |
} |
|
126 |
} |
|
127 |
} else { |
|
128 |
for(var prop in vehicles_info) { |
|
129 |
if(vehicles_info[prop]['num'] == depotId) { |
|
130 |
return prop; |
|
131 |
} |
b16328
|
132 |
} |
7ca6a1
|
133 |
} |
JK |
134 |
} |
|
135 |
|
07c714
|
136 |
function displayVehicle(vehicleInfo) { |
JK |
137 |
if(!vehicleInfo) return document.createTextNode(''); |
|
138 |
|
|
139 |
var span = document.createElement('span'); |
|
140 |
span.className = 'vehicleInfo'; |
|
141 |
|
|
142 |
var floor_type = ''; |
125626
|
143 |
if(vehicleInfo.low == 0) { |
07c714
|
144 |
setText(span, lang.high_floor_sign); |
JK |
145 |
floor_type = lang.high_floor; |
125626
|
146 |
} else if(vehicleInfo.low == 1) { |
07c714
|
147 |
setText(span, lang.partially_low_floor_sign); |
JK |
148 |
floor_type = lang.partially_low_floor; |
125626
|
149 |
} else if(vehicleInfo.low == 2) { |
07c714
|
150 |
setText(span, lang.low_floor_sign); |
JK |
151 |
floor_type = lang.low_floor; |
|
152 |
} |
|
153 |
|
|
154 |
span.title = lang.tram_type_pattern |
|
155 |
.replace('$num', vehicleInfo.num) |
|
156 |
.replace('$type', vehicleInfo.type) |
|
157 |
.replace('$floor', floor_type); |
|
158 |
|
|
159 |
return span; |
|
160 |
} |
|
161 |
|
68aeb4
|
162 |
// Element mangling |
JK |
163 |
function deleteChildren(element) { |
|
164 |
while(element.lastChild) element.removeChild(element.lastChild); |
|
165 |
} |
|
166 |
|
|
167 |
function addElementWithText(parent, element, text) { |
|
168 |
var elem = document.createElement(element); |
|
169 |
elem.appendChild(document.createTextNode(text)); |
|
170 |
parent.appendChild(elem); |
|
171 |
return elem; |
|
172 |
} |
|
173 |
|
|
174 |
function addCellWithText(parent, text) { |
|
175 |
return addElementWithText(parent, 'td', text); |
|
176 |
} |
|
177 |
|
|
178 |
function addParaWithText(parent, text) { |
|
179 |
return addElementWithText(parent, 'p', text); |
|
180 |
} |
|
181 |
|
|
182 |
function setText(element, text) { |
|
183 |
deleteChildren(element); |
|
184 |
element.appendChild(document.createTextNode(text)); |
|
185 |
} |