-
Notifications
You must be signed in to change notification settings - Fork 3
/
pohai.html
200 lines (200 loc) · 9.76 KB
/
pohai.html
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
<!DOCTYPE html>
<html lang = "zh-CN">
<head>
<title>迫害码生成器v2.1</title>
<meta charset = "utf-8">
<script src = "https://cdn.staticfile.net/brython/3.11.0/brython.min.js"></script>
<script src = "https://cdn.staticfile.net/brython/3.11.0/brython_stdlib.min.js"></script>
<script src = "https://cdn.staticfile.net/qrious/4.0.2/qrious.min.js"></script>
<style>
:root {
--landscape-scale: 1.85;
}
html, body {
margin: 0px;
display: flex;
flex-direction: column;
}
p {
font-family: Arial, sans-serif;
font-size: min(9dvw, calc(9dvh / var(--landscape-scale)));
margin: min(5dvw, calc(5dvh / var(--landscape-scale)));
display: inline;
}
h1 {
font-family: Arial, sans-serif;
font-size: min(14dvw, calc(14dvh / var(--landscape-scale)));
font-weight: bold;
margin: min(5dvw, calc(5dvh / var(--landscape-scale))) min(5dvw, calc(5dvh / var(--landscape-scale))) 0px;
}
input {
font-family: Arial, sans-serif;
font-size: min(9dvw, calc(9dvh / var(--landscape-scale)));
padding: min(1dvw, calc(1dvh / var(--landscape-scale)));
margin: min(5dvw, calc(5dvh / var(--landscape-scale)));
border-radius: 0px;
text-decoration: none;
font-weight: normal;
background-color: #f8f8f8;
color: black;
-webkit-appearance: none;
-webkit-box-shadow: 0 0 0px 1000px #f8f8f8 inset !important;
border: min(0.4dvw, calc(0.4dvh / var(--landscape-scale))) solid black;
}
input:disabled {
background-color: #fff0f0;
color: #ff0000;
}
::placeholder {
color: #a0a0a0;
opacity: 1;
}
::-ms-input-placeholder {
color: #a0a0a0;
}
.inline {
margin: min(2.5dvw, calc(2.5dvh / var(--landscape-scale)));
width: min(15dvw, calc(15dvh / var(--landscape-scale)));
}
#col {
width: min(7dvw, calc(7dvh / var(--landscape-scale)));
}
#emuid {
flex: 1;
max-width: calc(87.6dvh / var(--landscape-scale));
}
img {
border: 0px;
margin: min(5dvw, calc(5dvh / var(--landscape-scale)));
width: min(90dvw, calc(90dvh / var(--landscape-scale)));
}
div {
margin: 0px;
}
</style>
</head>
<body onload = "brython (0)">
<noscript>
<p style = "display: block; font-size: 5dvw;">使用该网站需要JavaScript。</p>
</noscript>
<script type = "text/python">
from browser import document, html, ajax, window
from datetime import *
global lastcol, regular_ids
lastcol, regular_ids = "A", []
def disable (ids, state, visible = None):
for i in ids:
document [i].disabled = state
document ["qr"].style.visibility = ("hidden", "visible") [state == "" if visible == None else visible]
def oninput (ev):
global lastcol
disable (("emuid", "car", "row", "col"), "", False)
if ev.target.id == "emuid":
if ev.type == "focus":
disable (("car", "row", "col"), "disabled")
emuid = ev.target.value
ev.target.value = ""
ev.target.value = emuid
if len (ev.target.value) < 2:
return None
elif ev.target.value [1] in "123456789":
disable (("emuid", "car", "row", "col"), "disabled")
cndate = (datetime.now (timezone.utc) + timedelta (hours = 8)).strftime ("%Y%m%d")
ajax.get (f"https://corsproxy.io/?https://mobile.12306.cn/wxxcx/openplatform-inner/miniprogram/wifiapps/appFrontEnd/v2/lounge/open-smooth-common/trainStyleBatch/getCarDetail?carCode=&trainCode={ev.target.value [0].upper () + ev.target.value [1 : ]}&runningDay={cndate}&reqType=form&", mode = "json", oncomplete = getchedi)
ev.target.value = "列车编号获取中..."
elif ev.type == "focus":
if ev.target.value [ : 2] in ("列车", "车厢"):
ev.target.value = ""
return None
elif ev.target.value [ : 2].upper () == "CR":
model = ev.target.value.replace ("-", "").upper ()
for i, j in (("CR400", 7), ("CR300", 7), ("CR200J", 7), ("CRH380", 0), ("CRH", 5), ("", 0)):
if model.startswith (i) and len (model) > j:
ev.target.value = "-".join ((i for i in (model [ : min (j, len (model) - 4)], model [min (j, len (model) - 4) : -4], model [-4 : ]) if i))
break
try:
(diff, ) = set (document ["col"].value).difference (lastcol)
if diff in "AaBbCcDdFf":
document ["col"].value = diff.upper ()
lastcol = document ["col"].value
else:
raise ValueError
except ValueError:
document ["col"].value = lastcol
for i in (document ["car"], document ["row"]):
i.value = ("00" + str (max (int ("00" + i.value [-2 : ]), int (ev.type == "blur")))) [-2 : ]
if ev.type == "blur":
i.value = min (i.value, "17" if i.id == "car" else "20")
if document ["emuid"].value [ : 2] == "CR":
genqr ()
def getchedi (req):
try:
document ["emuid"].value = req.json ["content"] ["data"] ["carCode"]
genqr ()
except Exception as e:
document ["emuid"].value = "列车编号获取失败"
disable (("emuid", "car", "row", "col"), "", False)
window.console.log (f"Error retrieving train code: {e}")
def genqr (qr_url = False):
global regular_ids
if document ["emuid"].value not in regular_ids:
disable (("emuid", "car", "row", "col"), "disabled")
if not qr_url:
ajax.get (f'https://corsproxy.io/?https://api.rail.re/emu/{document ["emuid"].value.replace ("-", "")}/qr', mode = "json", oncomplete = getqrform)
else:
disable (("emuid", "car", "row", "col"), "")
if not qr_url:
qr_url = f"https://p.12306.cn/tservice/qr/travel/v1?c={document ['emuid'].value}-{document ['car'].value}-{document ['row'].value}{document ['col'].value}&w=h"
document ["qr"].src = window.QRious.new ({"element": html.CANVAS (), "level": "M", "size": 814, "padding": 37, "value": qr_url}).toDataURL ()
def getqrform (req):
global regular_ids
if not req.json:
disable (("emuid", "car", "row", "col"), "", True)
return None
form = req.json ["url"]
form = form [form.find ("c=") + 2 : form.find ("&w")]
if not form.startswith ("CR"):
ajax.get ("https://corsproxy.io/?https://mobile.12306.cn/wxxcx/wechat/main/travelServiceDecodeQrcode", data = f"c={form}&w=h&eKey=zKT3tfG8H8MzIGMJ2%2FxbcUbhyU6lfkOJRPiZFqf2Z61y19QIs1TS5oL%2BL0OYKF%2FnFocNWnPt1105UkKKQnSIoanOHkFIkpnJzBE9pAPSHOSZ0oNhuWyHPb3xQPOehcoUwKh%2BV6jDV7K4jeVIPvKCvA%3D%3D", oncomplete = limited_qr)
document ["emuid"].value = "车厢和座位号受限"
genqr (f"https://p.12306.cn/tservice/qr/travel/v1?c={form}&w=h")
else:
regular_ids.append (document ["emuid"].value)
disable (("emuid", "car", "row", "col"), "")
def limited_qr (req):
try:
document ["car"].value = req.json ["data"] ["coachNo"]
document ["row"].value = req.json ["data"] ["seatNo"] [ : -1]
document ["col"].value = req.json ["data"] ["seatNo"] [-1]
disable (("emuid", "car", "row", "col"), "")
except Exception as e:
document ["emuid"].value = "列车编号不在数据库"
disable (("emuid", "car", "row", "col"), "", False)
window.console.log (f"Error retrieving databse QR Code: {e}")
def emublur (ev):
if getattr (ev, "key", False) == "Enter":
ev.target.blur ()
document.clear ()
document <= html.H1 ("迫害码生成器", style = "flex: 1;")
document <= html.INPUT (id = "emuid", placeholder = "列车编号或车次", autofocus = "autofocus")
document <= html.DIV (id = "params")
document ["params"] <= html.P ("车厢号:")
document ["params"] <= html.INPUT (Class = "inline", type = "number", id = "car", value = "01", min = 1, max = 17)
document ["params"] <= html.BR ()
document ["params"] <= html.P ("座位号:")
document ["params"] <= html.INPUT (Class = "inline", type = "number", id = "row", value = "01", min = 1, max = 20)
document ["params"] <= html.INPUT (Class = "inline", id = "col", value = "A")
document <= html.IMG (id = "qr")
document ["emuid"].bind ("blur", oninput)
document ["emuid"].bind ("focus", oninput)
document ["emuid"].bind ("keydown", emublur)
document ["car"].bind ("input", oninput)
document ["row"].bind ("input", oninput)
document ["car"].bind ("blur", oninput)
document ["row"].bind ("blur", oninput)
document ["col"].bind ("input", oninput)
</script>
<script>
document.body.insertAdjacentHTML ("beforeend", '<p style = "display: block;">加载中...</p></div>')
</script>
</body>
</html>