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 |
|
68aeb4
|
34 |
// Webservice-related functions |
JK |
35 |
function parseVehicle(vehicleId) { |
765604
|
36 |
if(!vehicleId) return false; |
68aeb4
|
37 |
if(vehicleId.substr(0, 15) != '635218529567218') { |
JK |
38 |
console.log('Unknown vehicle, vehicleId=' + vehicleId); |
765604
|
39 |
return false; |
68aeb4
|
40 |
} |
JK |
41 |
|
|
42 |
var id = parseInt(vehicleId.substr(15)) - 736; |
|
43 |
var prefix; |
|
44 |
var type; |
|
45 |
var low; // low floor: 0 = no, 1 - semi, 2 - full |
|
46 |
|
|
47 |
// Single exception - old id used in one case |
|
48 |
if(id == 831) { |
|
49 |
id = 216; |
|
50 |
} |
|
51 |
|
ca0664
|
52 |
if(101 <= id && id <= 174) { |
68aeb4
|
53 |
prefix = 'HW'; |
JK |
54 |
type = 'E1'; |
|
55 |
low = 0; |
|
56 |
|
ca0664
|
57 |
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
|
58 |
prefix = 'RW'; |
JK |
59 |
} |
|
60 |
} else if(201 <= id && id <= 293) { |
|
61 |
prefix = 'RZ'; |
|
62 |
type = '105Na'; |
|
63 |
low = 0; |
|
64 |
|
|
65 |
if(246 <= id) { |
|
66 |
prefix = 'HZ'; |
|
67 |
} |
|
68 |
if(id == 290) { |
|
69 |
type = '105Nb'; |
|
70 |
} |
|
71 |
} else if(301 <= id && id <= 328) { |
|
72 |
prefix = 'RF'; |
|
73 |
type = 'GT8S'; |
|
74 |
low = 0; |
|
75 |
|
901546
|
76 |
if(id == 313) { |
68aeb4
|
77 |
type = 'GT8C' |
JK |
78 |
low = 1; |
901546
|
79 |
} else if(id == 323) { |
JK |
80 |
low = 1; |
68aeb4
|
81 |
} |
JK |
82 |
} else if(401 <= id && id <= 440) { |
|
83 |
prefix = 'HL'; |
|
84 |
type = 'EU8N'; |
|
85 |
low = 1; |
|
86 |
} else if(451 <= id && id <= 462) { |
|
87 |
prefix = 'HK'; |
|
88 |
type = 'N8S-NF'; |
9fb99d
|
89 |
low = 1; |
68aeb4
|
90 |
|
9fb99d
|
91 |
if((451 <= id && id <= 456) || id == 462) { |
68aeb4
|
92 |
type = 'N8C-NF'; |
JK |
93 |
} |
|
94 |
} else if(601 <= id && id <= 650) { |
|
95 |
prefix = 'RP'; |
|
96 |
type = 'NGT6 (3)'; |
|
97 |
low = 2; |
|
98 |
|
|
99 |
if(id <= 613) { |
|
100 |
type = 'NGT6 (1)'; |
|
101 |
} else if (id <= 626) { |
|
102 |
type = 'NGT6 (2)'; |
|
103 |
} |
|
104 |
} else if(801 <= id && id <= 824) { |
|
105 |
prefix = 'RY'; |
|
106 |
type = 'NGT8'; |
|
107 |
low = 2; |
|
108 |
} else if(id == 899) { |
|
109 |
prefix = 'RY'; |
|
110 |
type = '126N'; |
|
111 |
low = 2; |
|
112 |
} else if(901 <= id && id <= 936) { |
|
113 |
prefix = 'RG'; |
|
114 |
type = '2014N'; |
|
115 |
low = 2; |
|
116 |
|
|
117 |
if(915 <= id) { |
|
118 |
prefix = 'HG'; |
|
119 |
} |
|
120 |
} else if(id === 999) { |
ca0664
|
121 |
prefix = 'HG'; |
68aeb4
|
122 |
type = '405N-Kr'; |
JK |
123 |
low = 1; |
|
124 |
} else { |
|
125 |
console.log('Unknown vehicle, vehicleId=' + vehicleId + ', id=' + id); |
765604
|
126 |
return false; |
68aeb4
|
127 |
} |
JK |
128 |
|
|
129 |
return { |
|
130 |
vehicleId: vehicleId, |
|
131 |
prefix: prefix, |
|
132 |
id: id, |
|
133 |
num: prefix + id, |
|
134 |
type: type, |
|
135 |
low: low |
|
136 |
}; |
|
137 |
} |
|
138 |
|
7ca6a1
|
139 |
function tramIdToVehicleId(tramId) { |
JK |
140 |
if(0 <= tramId && tramId <= 999) { |
|
141 |
var vehicleId = '0000' + (tramId + 736); |
|
142 |
vehicleId = vehicleId.substr(vehicleId.length - 4) |
|
143 |
return '635218529567218' + vehicleId; |
|
144 |
} |
|
145 |
} |
|
146 |
|
68aeb4
|
147 |
// Element mangling |
JK |
148 |
function deleteChildren(element) { |
|
149 |
while(element.lastChild) element.removeChild(element.lastChild); |
|
150 |
} |
|
151 |
|
|
152 |
function addElementWithText(parent, element, text) { |
|
153 |
var elem = document.createElement(element); |
|
154 |
elem.appendChild(document.createTextNode(text)); |
|
155 |
parent.appendChild(elem); |
|
156 |
return elem; |
|
157 |
} |
|
158 |
|
|
159 |
function addCellWithText(parent, text) { |
|
160 |
return addElementWithText(parent, 'td', text); |
|
161 |
} |
|
162 |
|
|
163 |
function addParaWithText(parent, text) { |
|
164 |
return addElementWithText(parent, 'p', text); |
|
165 |
} |
|
166 |
|
|
167 |
function setText(element, text) { |
|
168 |
deleteChildren(element); |
|
169 |
element.appendChild(document.createTextNode(text)); |
|
170 |
} |