forked from Arnie97/moerail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
telecode.js
86 lines (81 loc) · 2.9 KB
/
telecode.js
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
function main() {
var ua = navigator.userAgent;
if (/Android/.test(ua)) {
$('#app,#client').removeClass('hidden');
} else if (/Windows NT|Macintosh|X11/.test(ua)) {
$('#ext,#client').removeClass('hidden');
}
$('#stations').text(stations.length);
$('header,footer').geopattern(Math.random().toString());
$('img#ribbon').on('click', function() {
$('input.search').focus();
});
$('input.search').on('change', function() {
location.hash = '#' + escape($('input.search').val());
});
$(window).on('hashchange', function() {
var inputText = unescape(location.hash.slice(1)).toUpperCase();
$('input.search').val(inputText);
return query(inputText);
});
$('table').tablesorter();
$(window).trigger('hashchange');
}
function query(s) {
if (s.match(/[GDC]\d{1,4}/i)) {
var url = '/img/{0}.png'.format([s]);
$('a#route>img').attr('src', url).on('error', function() {
$(this).unbind('error').attr('src', 'img/404.png');
});;
$('a#route').attr('href', url);
$('a#route').removeClass('hidden');
$('table').addClass('hidden');
return;
} else {
$('a#route').addClass('hidden');
$('table').removeClass('hidden');
}
var results = stations.findAll(cond(s));
var tableRows = results.map(function(i) {
i = i.slice(0); // clone the array
var pair = bureaus[i[2].slice(-1)] || ['', ''];
i.push('<span class="hidden-xs">{0}</span><span class="visible-xs-block">{1}</span>'.format(pair));
i.push(i[1].match(/[^(]+/));
if (i[2]) {
i[2] = '-' + i[2].slice(0, 3);
}
i.link(1, 'https://zh.wikipedia.org/zh-cn/{6}站');
i.link(4, 'https://www.amap.com/search?query={6}站');
i.link(2, 'https://jprailfan.com/tools/stat/?telecode={2}');
i.link(0, 'https://jprailfan.com/tools/stat/?pinyincode={0}');
i.link(3, 'http://hyfw.12306.cn/hyinfo/action/FwcszsAction_czcx?hzzm&tmism={3}');
return '<tr><td>{1}</td><td>{5}</td><td>{4}</td><td>{2}</td><td>{0}</td><td>{3}</td></tr>'.format(i);
});
$('table>tbody').html(tableRows.join());
$('table').trigger('update');
}
function cond(s) {
if (!s) {
s = cities.randomElement();
} else if (s.match(/^\d+$/)) {
$('table').trigger('sorton', [[[5, 0]]]);
return (function(i) {
return i[3].startsWith(s);
});
}
$('table').trigger('sorton', [[]]);
if (s.startsWith('-')) {
return (function(i) {
return i[2].slice(0, 3) === s.slice(1).toUpperCase();
});
} else if (s.charCodeAt(0) > 'z'.charCodeAt(0)) {
return (function(i) {
return i[1].startsWith(s);
});
} else {
return (function(i) {
return i[0] === s.toLowerCase() || i[2].slice(0, 3) === s;
});
}
}
$(main);