-
Notifications
You must be signed in to change notification settings - Fork 0
/
rstop.htm
218 lines (201 loc) · 13.8 KB
/
rstop.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<html>
<head>
<meta name="mobileoptimized" content="0">
<meta name="referrer" content="no-referrer">
<link href="//backend-unified.mylirr.org" rel="dns-prefetch">
<link href="//backend-unified.mylirr.org" rel="preconnect" crossorigin>
<script async defer src="/fav.js"></script>
<style>:root{color-scheme:light dark}a.t:link{color:initial;text-decoration:initial}.b{text-decoration:underline}</style>
</head>
<body>No javascript</body>
<script>
mangleIndex={name:"mangleIndex"};
/* note sta codes 0NY (MNRR) GCT (LIRR) and _GC (Both) are all GCT,
todo, make choice if show Both for both RRs*/
/*html-minifier will remove spaces and extra "s, DONT change tags, this station list is injected*/
/*STARTINSERT*/
var s={"0AR":"Ardsley-on-Hudson","0BC":"Beacon","0BK":"Breakneck Ridge","0CS":"Cold Spring","0CT":"Cortlandt","0DF":"Dobbs Ferry","0DV":"Spuyten Duyvil","0GA":"Garrison","0GD":"Glenwood","0GY":"Greystone","0HB":"Highbridge-Employees","0HL":"Harlem-125 St","0HM":"Croton-Harmon","0HS":"Hastings-on-Hudson","0IV":"Irvington","0LU":"Ludlow","0MB":"Marble Hill","0MH":"Morris Heights","0MN":"Manitou","0NM":"New Hamburg","0NY":"Grand Central","0OS":"Ossining","0PE":"Peekskill","0PM":"Philipse Manor","0PO":"Poughkeepsie","0RV":"Riverdale","0SB":"Scarborough","0TT":"Tarrytown","0UH":"University Heights","0YK":"Yonkers","0YS":"Yankees-E 153 St","1AT":"Appalachian Trail","1BG":"Botanical Garden","1BH":"Bedford Hills","1BR":"Southeast","1BW":"Brewster","1BX":"Bronxville","1CF":"Croton Falls","1CQ":"Chappaqua","1CW":"Crestwood","1DO":"Dover Plains","1FO":"Fordham","1FW":"Fleetwood","1GO":"Goldens Bridge","1HA":"Hartsdale","1HN":"Hawthorne","1KA":"Katonah","1MK":"Mt Kisco","1ML":"Melrose","1MP":"Mt Pleasant","1MW":"Mt Vernon West","1NW":"North White Plains","1PA":"Patterson","1PV":"Pleasantville","1PW":"Pawling","1PY":"Purdy's","1SC":"Scarsdale","1TK":"Tuckahoe","1TM":"Tenmile River","1TR":"Tremont","1VA":"Valhalla","1WA":"Wassaic","1WF":"Wakefield","1WG":"Williams Bridge","1WI":"Harlem Valley-Wingdale","1WN":"Woodlawn","1WP":"White Plains","2BP":"Bridgeport","2CC":"Cos Cob","2DA":"Darien","2EN":"East Norwalk","2FF":"Fairfield","2FM":"Fairfield Metro","2GF":"Green's Farms","2GN":"Greenwich","2HS":"Harrison","2LA":"Larchmont","2MA":"Mamaroneck","2ME":"Mt Vernon East","2MI":"Milford","2NH":"New Haven","2NO":"Noroton Heights","2NR":"New Rochelle","2OG":"Old Greenwich","2PC":"Port Chester","2PH":"Pelham","2RO":"Rowayton","2RS":"Riverside","2RY":"Rye","2SM":"Stamford","2SN":"South Norwalk","2SP":"Southport","2SR":"Stratford","2SS":"New Haven-State St","2WH":"West Haven","2WP":"Westport","3GB":"Glenbrook","3NC":"New Canaan","3SD":"Springdale","3TH":"Talmadge Hill","4BE":"Bethel","4BV":"Branchville","4CA":"Cannondale","4DN":"Danbury","4M7":"Merritt 7","4RD":"Redding","4WI":"Wilton","5AN":"Ansonia","5BF":"Beacon Falls","5DB":"Derby-Shelton","5NG":"Naugatuck","5SY":"Seymour","5WB":"Waterbury","ABT":"Albertson","ADL":"Auburndale","AGT":"Amagansett","ATL":"Atlantic Terminal","AVL":"Amityville","BDY":"Broadway","BHN":"Bridgehampton","BK":"Stony Brook","BMR":"Bellmore","BOL":"Bolands-Employees","BPG":"Bethpage","BPT":"Bellport","BRS":"Bellerose","BRT":"Belmont Park","BSD":"Bayside","BSR":"Bay Shore","BTA":"Babylon","BWD":"Brentwood","BWN":"Baldwin","CAV":"Centre Av","CHT":"Cedarhurst","CI":"Central Islip","CLP":"Country Life Press","CPG":"Copiague","CPL":"Carle Place","CSH":"Cold Spring Harbor","DGL":"Douglaston","DPK":"Deer Park","EHN":"East Hampton","EMT":"Elmont-UBS Arena","ENY":"East New York","ERY":"East Rockaway","EWN":"East Williston","FHL":"Forest Hills","FLS":"Flushing Main Street","FMD":"Farmingdale","FPK":"Floral Park","FPT":"Freeport","FRY":"Far Rockaway","GBN":"Gibson","GCT":"Grand Central","GCV":"Glen Cove","GCY":"Garden City","GHD":"Glen Head","GNK":"Great Neck","GPT":"Greenport","GRV":"Great River","GST":"Glen Street","GVL":"Greenvale","GWN":"Greenlawn","HBY":"Hampton Bays","HEM":"Hempstead","HGN":"Hempstead Gardens","HIL":"Hillside-Employees","HOL":"Hollis","HPA":"Hunterspoint Av","HUN":"Huntington","HVL":"Hicksville","HWT":"Hewlett","IPK":"Island Park","ISP":"Islip","IWD":"Inwood","JAM":"Jamaica","KGN":"Kew Gardens","KPK":"Kings Park","LBH":"Long Beach","LCE":"Lawrence","LHT":"Lindenhurst","LIC":"Long Island City","LMR":"Locust Manor","LNK":"Little Neck","LTN":"Laurelton","LVL":"Locust Valley","LVW":"Lakeview","LYN":"Lynbrook","MAK":"Mattituck","MAV":"Merillon Av","MFD":"Medford","MHL":"Murray Hill","MHT":"Manhasset","MIN":"Mineola","MPK":"Massapequa Park","MQA":"Massapequa","MRK":"Merrick","MSY":"Mastic-Shirley","MTK":"Montauk","MVN":"Malverne","NAV":"Nostrand Av","NBD":"Nassau Blvd","NHP":"New Hyde Park","NPT":"Northport","NYK":"Penn Station","OBY":"Oyster Bay","ODE":"Oceanside","ODL":"Oakdale","PDM":"Plandome","PGE":"Patchogue","PJN":"Port Jefferson","PLN":"Pinelawn","PWS":"Port Washington","QVG":"Queens Village","RHD":"Riverhead","RON":"Ronkonkoma","ROS":"Rosedale","RSN":"Roslyn","RVC":"Rockville Centre","SAB":"St. Albans","SCF":"Sea Cliff","SFD":"Seaford","SHD":"Southold","SHN":"Southampton","SJM":"St. James","SMR":"Stewart Manor","SPK":"Speonk","SSM":"Mets-Willets Point","STN":"Smithtown","SVL":"Sayville","SYT":"Syosset","VSM":"Valley Stream","WBY":"Westbury","WDD":"Woodside","WGH":"Wantagh","WHD":"West Hempstead","WHN":"Westhampton","WMR":"Woodmere","WWD":"Westwood","WYD":"Wyandanch","YPK":"Yaphank","_GC":"Grand Central"};
/*ENDINSERT*/
/*STARTRAILCOLOR*/
var colorStrsRAIL = ["ee0034","4d5357","006ec7"];
var colorRoutesRAIL = {/*"NC":0,*//*"WB":0,*//*"DN":0,*//*"NH":0,*/"12":1,"CI":1,"HH":2,"PJ":2,"BY":"00985f","HU":"009b3a","WH":"00a1de","OB":"00af3f","MK":"00b2a9","HA":"066afe","11":"60269e","S":"6d6e71","FR":"6e3219","RK":"a626aa","PW":"c60c30","HM":"ce8e00","LB":"ff6319"};
/*ENDRAILCOLOR*/
var lirr_headers = {headers: {'accept-version': '3.0'}};
/* var t is "top" as in top of body (header) */
var t;
var stacode;
if(!this.onpopstate) {
this.onpopstate = function (evt) {evt.state !== null && location.reload()};
}
function onNewURL(){
/* on Chrome, refresh does a 200 or 304 on stop.htm on GH Pages plus MTA call
even though if I do a "back" then navigate back to stop.htm, no TCPIP traffic
related to stop.htm because stop.htm is fetched from browser cache, sadly there
seems to be no way to do a refresh or a replace without triggering network traffic
so just implement a "Fast" path that does the AJAX call alone, kindda important
for latency reasons on 2G networks, 200 always if .reload(1),
304 typ if .reload(0)
*/
stacode = location.hash;
if(stacode.length > 1) {
/* https://traintime.lirr.org/api/Departure?loc=CPL is one API from old MTA official LIRR Train Time app, no CORS headers, no cleartext
https://backend.mylirr.org/arrivals/CPL is from https://www.mylirr.org/main?
with cors accept-version: 1.5 header is mandatory (plus preflight) or server
throws an error, cleartext http works
new mta OTP planner site (2021) uses
dev: "https://traintimeqa.lirr.org/api",
staging: "https://traintimeqa.lirr.org/api",
prod: "https://traintime.lirr.org/api"
^^^dead in 2022
new mta OTP planner site (2022) uses
https://otp-mta-prod.camsys-apps.com/otp/routers/default/nearby?stops=LI%3A31&timeRange=21600&apikey=Z276E3rCeTzOQEoBPPN4JCEc6GfvdnYE
but 2022 https://traintime.mta.info/ (replacing www.mylirr.org) uses
https://backend-unified.mylirr.org/arrivals/CLS with
with cors accept-version: 3.0 header is mandatory (plus preflight) or server
throws an error, cleartext http works, note
"This is wrong version of the API. Acceptable versions: [1.5, 1.6, 2.0, 3.0]"
I see no JSON diff with 1.5 vs 3.0
*/
stacode = stacode.slice(1);
/* generate body top string once, its later used for fast refresh */
t = '<a href=javascript:history.back()>Back</a> Refresh[<a href=javascript:y()>Fast</a> <a href=\"javascript:location.replace(\''
+
/*STARTINSERTPATH*/
(/rstop\.htm$/.test(location.pathname) ? "rstop_.htm#" : "rstop.htm#")
/*ENDINSERTPATH*/
+stacode+'\')">Slow</a>] <a href=//backend-unified.mylirr.org/arrivals/'+stacode+'>Raw</a><br>';
}
if (t) {
if (this.fetch) {
y/*getStop*/();
} else {
//IE 5.5 and 6.0 don't have document.head
document.documentElement.firstChild.appendChild(document.createElement("script")).src = 'f.js';
}
}
else
document.body.innerHTML = 'No station specified in url anchor.';
}//end onNewURL
this.y = y;
onhashchange = onNewURL;
location.pathname == '/rstop.htm' && onNewURL();
function noPTag(str) {
if(typeof str == 'string') {
if (str.indexOf('<p>') === 0 && str.indexOf('</p>', str.length - 4) !== -1) {
return str.slice(3, -4);
}
}
return str;
}
/*y=getStop, must be var "y" for f.js polyfill to find and call on f.js load/exec */
function y() {
document.body.innerHTML = t; /*t=top*/
var ls;
var fCB = function (r) {
r.status != 200 ? //put != first for r.status gzip reasons
alert("error http status " + r.status)
:
r.json().then(gotJson)};
/*ra = rail arrivals*/
//CODE REMOVED NOTES
//FF 3.5 has W3C/modern SS, FF 3.0 getItem returns strange objects with
//value: secure: only 2 keys, value: contains a string of our json
//https://humanwhocodes.com/blog/2009/07/21/introduction-to-sessionstorage/
//(ls = JSON.parse(typeof ls === 'object' ? ls.value : ls)))
//window.name has latency problems, very fast physical clicks (mousedown/mouseup)
//will cause window.name to be empty string in new page/double network I/O
//stick to sessionStorage, Opera 10, oh well, its too old to need perf
//console.log(' read '+window.name.slice(0, 5)+' read ');
//if((ls = window.name) && (window.name='',ls = JSON.parse(ls))
if ((ls = window.S) && ((window.S = 0),ls.s === stacode)
&& (Date.now()-ls.t < 3000)
) {
ls.f(fCB);
} else { // start new XHR I/O call, freshness or stacode
fetch('//backend-unified.mylirr.org/arrivals/'+stacode, lirr_headers).then(fCB);
}
function gotJson(r, /*r=resp*/ jsonp) {
console.log('f'+Date.now());
var i, n = 0, branch, w = "West<br>",
l, curTime = new Date(), h = curTime.toLocaleTimeString('en-US')+(jsonp ? ' via JSONP' : ' via CORS')
+'<br>Cur Sta: ' + s[stacode] + "<br>East<br>"; /*w=west, t=train, l=lineofhtml, h=html*/
/* DO NOT convert to for( in ) {}, because Array.prototype. PFs show up
in the loop, and object.defineProperty unavail IE <= 8 */
for (curTime = curTime.getTime()/1000; n < r.arrivals.length; n++) {
i = r.arrivals[n];
//note to self, ceil is round up, |0 is round down
//console.log('x'+Math.ceil((t.time - curTime) / 60)+' '+(((t.time - curTime) / 60)|0));
l = '<a class=t href=rtrain.htm#'+i.railroad+'_'+i.train_num+'>'+new Date((l=i.time) * 1000).toLocaleTimeString().replace(':00 ', ' ')
+ '-Min ' + Math.ceil((l-curTime) / 60)
/*
} else if (!_.isUndefined(train.status.otp)) {
const otpMin = Math.trunc(train.status.otp / 60)
const otpMinAbs = Math.abs(otpMin)
otpStr = 'On time'
if (otpMinAbs !== 0) {
const otpClass = otpMin < 0 ? 'late' : 'early'
const otpTerm = otpMinAbs === 1 ? 'minute' : 'minutes'
otpStr = `${otpMinAbs} ${otpTerm} ${otpClass}`
}
}
*/
+ ((l=i.status.otp) && (l=(l/60)|0) ? (l > 0 ? '-E'+l : '-L'+-l):'')
+ '-Tk' + (i.track || '?')
+ "-<font class=b color=" + (
typeof (l = colorRoutesRAIL[branch = i.branch]) === 'string' ? l : (colorRoutesRAIL[branch] = colorStrsRAIL[l|0])
)+ ">" + s[(l=i.stops)[l.length - 1]]
+ "</font>"+(i.peak_code == 'O'?'':'-Pk')+"</a><br>"; //A or P are peak
i.direction == 'E' ? h += l : w += l;
}
/* test code
r.banners = [
{
"title": "Grand Central Madison is Open",
"text": "Special LIRR Grand Central Direct service runs between Jamaica Station and Grand Central. Plan your trip in the TrainTime Trips tab and learn more here: https://new.mta.info/grandcentralmadison",
"railroad": "LIRR",
"type": "ALERT"
}
];
"alerts": [
{
"status": "Extra Service",
"header": "<p>Special Grand Central Direct trains run between Jamaica and Grand Central</p>",
"text": "<p>Regular LIRR schedules will not change for at least three weeks. In the meantime, come explore our new East Side terminal and share this historic moment with us!</p><p>Check out the special schedule and plan your trip on our TrainTime app.</p>",
"priority": 9,
"start_time": 1674661500,
"human_duration": "6:15 AM to 8:15 PM weekdays and 7 AM to 11 PM weekends, starting Jan 25 10:45 AM",
"status_level": 1,
"station_alternatives": [],
"language": "en"
}
],
*/
/* add west trains to mega html string and reuse west var */
h += w;
w = '<br>';
for (n=0; n < r.banners.length; n++) {
i = r.banners[n];
//always show banners, they aren't attached to all stations at once
//l = Number(stacode.slice(0,1));
// if LIRR && is not numeric aka is LIRR sta code then draw, not in MTA UI code
// IDK abbrevation for MNRR in API but other railroad && numeric will draw
//if((i.railroad == 'LIRR') == (l !== +l)) {
w += i.title+'<br>'+i.text+'<br><br>';
//}
}
r = r.alerts;
//time sort alerts in the array
r.sort(function(a, b) {
return a.start_time < b.start_time ? -1 :
a.start_time > b.start_time ? 1 :
0;
});
for (n=0; n < r.length; n++) {
i = r[n];
w += i.status+'<br>'+noPTag(i.header)+'<br>'+(i.human_duration?i.human_duration+'<br>':'')+noPTag(i.text)+'<br><br>';
}
document.body.innerHTML += h+w;
(window.rF = window.rF || []).push(s[stacode], "r"+stacode);
}
} //end y aka getStop
</script></html>