commit | author | age
|
68aeb4
|
1 |
// Special directions |
JK |
2 |
var special_directions = { |
|
3 |
'Zajezdnia Nowa Huta' : 'NH', |
|
4 |
'Zajezdnia Podgórze' : 'P', |
|
5 |
}; |
|
6 |
|
572390
|
7 |
var script_version; |
JK |
8 |
var script_version_xhr; |
|
9 |
|
|
10 |
// Check for website updates |
|
11 |
function checkVersion() { |
|
12 |
if(script_version_xhr) script_version_xhr.abort(); |
|
13 |
|
|
14 |
script_version_xhr = $.get( |
|
15 |
'version.php' |
|
16 |
).done(function(data) { |
|
17 |
if(!script_version) { |
|
18 |
script_version = data; |
|
19 |
return; |
|
20 |
} |
|
21 |
|
|
22 |
if(script_version != data) { |
|
23 |
fail(lang.error_new_version); |
|
24 |
location.reload(true); |
|
25 |
} |
|
26 |
}); |
|
27 |
} |
|
28 |
|
|
29 |
function checkVersionInit() { |
|
30 |
checkVersion(); |
|
31 |
setInterval(checkVersion, 3600000); |
|
32 |
} |
|
33 |
|
8b6250
|
34 |
/* Parsing of received JSON parts */ |
JK |
35 |
function parseStatus(status) { |
|
36 |
switch(status.status) { |
|
37 |
case 'STOPPING': |
|
38 |
case 'PREDICTED': |
|
39 |
if(status.actualRelativeTime <= 0) |
|
40 |
return lang.boarding_sign; |
|
41 |
if(status.actualRelativeTime >= 60) |
|
42 |
return lang.time_minutes_prefix + Math.floor(status.actualRelativeTime / 60) + lang.time_minutes_suffix; |
|
43 |
return lang.time_seconds_prefix + status.actualRelativeTime + lang.time_seconds_suffix; |
|
44 |
case 'DEPARTED': |
|
45 |
return lang.time_minutes_ago_prefix + Math.floor(-status.actualRelativeTime / 60) + lang.time_minutes_ago_suffix; |
|
46 |
default: |
|
47 |
return status.mixedTime; |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
function parseTime(date, time) { |
|
52 |
var result = new Date(date.getFullYear(), date.getMonth(), date.getDay()); |
|
53 |
var time_split = time.split(':'); |
|
54 |
result.setHours(time_split[0]); |
|
55 |
result.setMinutes(time_split[1]); |
|
56 |
|
|
57 |
if(result.getTime() - date.getTime() > 72000000) { |
|
58 |
result.setTime(result.getTime() - 86400000); |
|
59 |
} |
|
60 |
|
|
61 |
if(date.getTime() - result.getTime() > 72000000) { |
|
62 |
result.setTime(result.getTime() + 86400000); |
|
63 |
} |
|
64 |
|
|
65 |
return result; |
|
66 |
} |
|
67 |
|
|
68 |
function parseDelay(status) { |
|
69 |
if(!status.actualTime) return lang.unknown_sign; |
|
70 |
if(!status.plannedTime) return lang.unknown_sign; |
|
71 |
|
|
72 |
var now = new Date(); |
|
73 |
var actual = parseTime(now, status.actualTime); |
|
74 |
var planned = parseTime(now, status.plannedTime); |
|
75 |
|
|
76 |
return lang.time_minutes_prefix + ((actual.getTime() - planned.getTime()) / 1000 / 60) + lang.time_minutes_suffix; |
|
77 |
} |
|
78 |
|
68aeb4
|
79 |
// Webservice-related functions |
JK |
80 |
function parseVehicle(vehicleId) { |
765604
|
81 |
if(!vehicleId) return false; |
68aeb4
|
82 |
if(vehicleId.substr(0, 15) != '635218529567218') { |
JK |
83 |
console.log('Unknown vehicle, vehicleId=' + vehicleId); |
765604
|
84 |
return false; |
68aeb4
|
85 |
} |
JK |
86 |
|
|
87 |
var id = parseInt(vehicleId.substr(15)) - 736; |
|
88 |
var prefix; |
|
89 |
var type; |
|
90 |
var low; // low floor: 0 = no, 1 - semi, 2 - full |
|
91 |
|
|
92 |
// Single exception - old id used in one case |
|
93 |
if(id == 831) { |
|
94 |
id = 216; |
22ceb4
|
95 |
} else if(id == 311) { |
T |
96 |
id = 899 |
68aeb4
|
97 |
} |
JK |
98 |
|
ca0664
|
99 |
if(101 <= id && id <= 174) { |
68aeb4
|
100 |
prefix = 'HW'; |
JK |
101 |
type = 'E1'; |
|
102 |
low = 0; |
|
103 |
|
ca0664
|
104 |
if((108 <= id && id <= 113) || id == 127 || id == 131 || id == 132 || id == 134 || (137 <= id && id <= 139) || (148 <= id && id <= 150) || (153 <= id && id <= 155)) { |
68aeb4
|
105 |
prefix = 'RW'; |
JK |
106 |
} |
|
107 |
} else if(201 <= id && id <= 293) { |
|
108 |
prefix = 'RZ'; |
|
109 |
type = '105Na'; |
|
110 |
low = 0; |
|
111 |
|
|
112 |
if(246 <= id) { |
|
113 |
prefix = 'HZ'; |
|
114 |
} |
|
115 |
if(id == 290) { |
|
116 |
type = '105Nb'; |
|
117 |
} |
|
118 |
} else if(301 <= id && id <= 328) { |
|
119 |
prefix = 'RF'; |
|
120 |
type = 'GT8S'; |
|
121 |
low = 0; |
|
122 |
|
901546
|
123 |
if(id == 313) { |
68aeb4
|
124 |
type = 'GT8C' |
JK |
125 |
low = 1; |
22ceb4
|
126 |
} else if(id == 323 || id >= 325) { |
T |
127 |
type = 'GT8N' |
901546
|
128 |
low = 1; |
68aeb4
|
129 |
} |
JK |
130 |
} else if(401 <= id && id <= 440) { |
|
131 |
prefix = 'HL'; |
|
132 |
type = 'EU8N'; |
|
133 |
low = 1; |
|
134 |
} else if(451 <= id && id <= 462) { |
|
135 |
prefix = 'HK'; |
|
136 |
type = 'N8S-NF'; |
9fb99d
|
137 |
low = 1; |
68aeb4
|
138 |
|
9fb99d
|
139 |
if((451 <= id && id <= 456) || id == 462) { |
68aeb4
|
140 |
type = 'N8C-NF'; |
JK |
141 |
} |
|
142 |
} else if(601 <= id && id <= 650) { |
|
143 |
prefix = 'RP'; |
|
144 |
type = 'NGT6 (3)'; |
|
145 |
low = 2; |
|
146 |
|
|
147 |
if(id <= 613) { |
|
148 |
type = 'NGT6 (1)'; |
|
149 |
} else if (id <= 626) { |
|
150 |
type = 'NGT6 (2)'; |
|
151 |
} |
|
152 |
} else if(801 <= id && id <= 824) { |
|
153 |
prefix = 'RY'; |
|
154 |
type = 'NGT8'; |
|
155 |
low = 2; |
|
156 |
} else if(id == 899) { |
|
157 |
prefix = 'RY'; |
|
158 |
type = '126N'; |
|
159 |
low = 2; |
|
160 |
} else if(901 <= id && id <= 936) { |
|
161 |
prefix = 'RG'; |
|
162 |
type = '2014N'; |
|
163 |
low = 2; |
|
164 |
|
|
165 |
if(915 <= id) { |
|
166 |
prefix = 'HG'; |
|
167 |
} |
|
168 |
} else if(id === 999) { |
ca0664
|
169 |
prefix = 'HG'; |
68aeb4
|
170 |
type = '405N-Kr'; |
JK |
171 |
low = 1; |
|
172 |
} else { |
|
173 |
console.log('Unknown vehicle, vehicleId=' + vehicleId + ', id=' + id); |
765604
|
174 |
return false; |
68aeb4
|
175 |
} |
JK |
176 |
|
|
177 |
return { |
|
178 |
vehicleId: vehicleId, |
|
179 |
prefix: prefix, |
|
180 |
id: id, |
|
181 |
num: prefix + id, |
|
182 |
type: type, |
|
183 |
low: low |
|
184 |
}; |
|
185 |
} |
|
186 |
|
7ca6a1
|
187 |
function tramIdToVehicleId(tramId) { |
JK |
188 |
if(0 <= tramId && tramId <= 999) { |
|
189 |
var vehicleId = '0000' + (tramId + 736); |
|
190 |
vehicleId = vehicleId.substr(vehicleId.length - 4) |
|
191 |
return '635218529567218' + vehicleId; |
|
192 |
} |
|
193 |
} |
|
194 |
|
07c714
|
195 |
function displayVehicle(vehicleInfo) { |
JK |
196 |
if(!vehicleInfo) return document.createTextNode(''); |
|
197 |
|
|
198 |
var span = document.createElement('span'); |
|
199 |
span.className = 'vehicleInfo'; |
|
200 |
|
|
201 |
var floor_type = ''; |
|
202 |
if(vehicleInfo.low == 0) { |
|
203 |
setText(span, lang.high_floor_sign); |
|
204 |
floor_type = lang.high_floor; |
|
205 |
} else if(vehicleInfo.low == 1) { |
|
206 |
setText(span, lang.partially_low_floor_sign); |
|
207 |
floor_type = lang.partially_low_floor; |
|
208 |
} else if(vehicleInfo.low == 2) { |
|
209 |
setText(span, lang.low_floor_sign); |
|
210 |
floor_type = lang.low_floor; |
|
211 |
} |
|
212 |
|
|
213 |
span.title = lang.tram_type_pattern |
|
214 |
.replace('$num', vehicleInfo.num) |
|
215 |
.replace('$type', vehicleInfo.type) |
|
216 |
.replace('$floor', floor_type); |
|
217 |
|
|
218 |
return span; |
|
219 |
} |
|
220 |
|
68aeb4
|
221 |
// Element mangling |
JK |
222 |
function deleteChildren(element) { |
|
223 |
while(element.lastChild) element.removeChild(element.lastChild); |
|
224 |
} |
|
225 |
|
|
226 |
function addElementWithText(parent, element, text) { |
|
227 |
var elem = document.createElement(element); |
|
228 |
elem.appendChild(document.createTextNode(text)); |
|
229 |
parent.appendChild(elem); |
|
230 |
return elem; |
|
231 |
} |
|
232 |
|
|
233 |
function addCellWithText(parent, text) { |
|
234 |
return addElementWithText(parent, 'td', text); |
|
235 |
} |
|
236 |
|
|
237 |
function addParaWithText(parent, text) { |
|
238 |
return addElementWithText(parent, 'p', text); |
|
239 |
} |
|
240 |
|
|
241 |
function setText(element, text) { |
|
242 |
deleteChildren(element); |
|
243 |
element.appendChild(document.createTextNode(text)); |
|
244 |
} |