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<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8">
|
5 |
+
<title>My static Space</title>
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
8 |
+
<link rel="preconnect" href="https://rsms.me/">
|
9 |
+
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
|
10 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
11 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
12 |
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@100;200;300;400;500;600;700;800;900&display=swap">
|
13 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.5.0/github-markdown.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
14 |
+
<style>
|
15 |
+
/* :root { font-family: 'Inter', sans-serif; }
|
16 |
+
@supports (font-variation-settings: normal) {
|
17 |
+
:root { font-family: 'Inter var', sans-serif; }
|
18 |
+
} */
|
19 |
+
body {
|
20 |
+
margin: 0;
|
21 |
+
background-color: #ffffff;
|
22 |
+
width: 100%;
|
23 |
+
}
|
24 |
+
@media (prefers-color-scheme: dark) {
|
25 |
+
body {
|
26 |
+
background-color: #0d1117;
|
27 |
+
}
|
28 |
+
}
|
29 |
+
body, .markdown-body, button {
|
30 |
+
font-family: 'Inter', 'Noto Sans JP', sans-serif !important;
|
31 |
+
}
|
32 |
+
.markdown-body {
|
33 |
+
box-sizing: border-box;
|
34 |
+
width: 100%;
|
35 |
+
max-width: 960px;
|
36 |
+
margin-right: auto;
|
37 |
+
margin-left: auto;
|
38 |
+
padding: 1rem;
|
39 |
+
}
|
40 |
+
.markdown-body table {
|
41 |
+
max-width: 100%;
|
42 |
+
}
|
43 |
+
</style>
|
44 |
+
</head>
|
45 |
+
<body>
|
46 |
+
<div class="markdown-body">
|
47 |
+
<h1>MiHoMo API Test</h1>
|
48 |
+
<div class="parsedAPI_input">
|
49 |
+
<p><span>Input UID: </span><input type="text" id="uidInputBox" name="uid" required minlength="9" maxlength="9" size="9" value="802415000"/> <button type="button" name="runBtn1" id="runBtn1" onclick="runBtn1Click()">Run</button></p>
|
50 |
+
<p class="connectingLabelRoot" id="connectingLabelRoot" style="display: none;"><span class="connectingLabelChild" id="connectingLabelNowProgress" style="display: none;">Connecting... </span><span class="connectingLabelChild" id="connectingLabelOk" style="display: none;"></span></p>
|
51 |
+
</div>
|
52 |
+
<div id="responseDataPlaceholder">
|
53 |
+
<h2>player (truncated)</h2>
|
54 |
+
<table>
|
55 |
+
<thead>
|
56 |
+
<tr>
|
57 |
+
<th>key</th>
|
58 |
+
<th>value</th>
|
59 |
+
</tr>
|
60 |
+
</thead>
|
61 |
+
<tbody id="responseDataPlaceholderPlayer">
|
62 |
+
</tbody>
|
63 |
+
</table>
|
64 |
+
<h2>characters (truncated)</h2>
|
65 |
+
<table>
|
66 |
+
<thead>
|
67 |
+
<tr>
|
68 |
+
<th>key</th>
|
69 |
+
<th>value</th>
|
70 |
+
</tr>
|
71 |
+
</thead>
|
72 |
+
<tbody id="responseDataPlaceholderCharacters">
|
73 |
+
</tbody>
|
74 |
+
</table>
|
75 |
+
</div>
|
76 |
+
</div>
|
77 |
+
<script>
|
78 |
+
const StarRailResBaseUrl = 'https://raw.githubusercontent.com/Mar-7th/StarRailRes/master/';
|
79 |
+
const apiConnectTimeout = 15000;
|
80 |
+
const apiConnectUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
81 |
+
const apiConnectDefaultHeader = {
|
82 |
+
'Cache-Control': apiConnectUserAgent,
|
83 |
+
'Access-Control-Allow-Origin': '*',
|
84 |
+
};
|
85 |
+
window.addEventListener('load', async function(){
|
86 |
+
// some process
|
87 |
+
});
|
88 |
+
async function runBtn1Click () {
|
89 |
+
const uidInputValue = document.querySelector('#uidInputBox').value;
|
90 |
+
document.querySelector('#connectingLabelRoot').style.display = 'block';
|
91 |
+
document.querySelector('#connectingLabelNowProgress').style.display = 'inline';
|
92 |
+
document.querySelector('#connectingLabelOk').style.display = 'inline';
|
93 |
+
const apiResponseData = await apiConnect({
|
94 |
+
'method': 'get',
|
95 |
+
'url': `https://corsproxy.io/?${encodeURIComponent(`https://api.mihomo.me/sr_info_parsed/${uidInputValue}?lang=jp&version=v2`)}`,
|
96 |
+
'headers': apiConnectDefaultHeader,
|
97 |
+
'timeout': apiConnectTimeout
|
98 |
+
});
|
99 |
+
console.log(apiResponseData);
|
100 |
+
if (apiResponseData) {
|
101 |
+
document.querySelector('#connectingLabelOk').innerHTML = `OK (Time: ${Math.ceil(apiResponseData.apiConnectionTime)} ms)`;
|
102 |
+
htmlBuildFromApiData(apiResponseData);
|
103 |
+
} else {
|
104 |
+
document.querySelector('#connectingLabelOk').innerHTML = `Failed`;
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
async function apiConnect (axiosObj) {
|
109 |
+
let connectionTimerStart = performance.now();
|
110 |
+
try {
|
111 |
+
const response = await axios(axiosObj);
|
112 |
+
let connectionTimerEnd = performance.now();
|
113 |
+
return {
|
114 |
+
'apiConnectionTime': connectionTimerEnd - connectionTimerStart,
|
115 |
+
'response': response.data
|
116 |
+
};
|
117 |
+
} catch (error) {
|
118 |
+
let connectionTimerEnd = performance.now();
|
119 |
+
console.error(`API request failed: ${error.code}`);
|
120 |
+
alert(`API request failed: ${error.code}`);
|
121 |
+
// console.error(error);
|
122 |
+
throw error;
|
123 |
+
return null;
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
function htmlBuildFromApiData (apiResponseData) {
|
128 |
+
const fakeClone01 = document.querySelector('#responseDataPlaceholderPlayer').cloneNode(false);
|
129 |
+
const fakeClone02 = document.querySelector('#responseDataPlaceholderCharacters').cloneNode(false);
|
130 |
+
document.querySelector('#responseDataPlaceholderPlayer').parentNode.replaceChild(fakeClone01, document.querySelector('#responseDataPlaceholderPlayer'));
|
131 |
+
document.querySelector('#responseDataPlaceholderCharacters').parentNode.replaceChild(fakeClone02, document.querySelector('#responseDataPlaceholderCharacters'));
|
132 |
+
let inputDataKeyList = [
|
133 |
+
'player.uid',
|
134 |
+
'player.nickname',
|
135 |
+
'player.signature',
|
136 |
+
'player.level',
|
137 |
+
'player.world_level',
|
138 |
+
'player.friend_count',
|
139 |
+
'player.avatar.icon',
|
140 |
+
'player.is_display',
|
141 |
+
'player.space_info.memory_data.level',
|
142 |
+
'player.space_info.memory_data.chaos_level',
|
143 |
+
'player.space_info.universe_level',
|
144 |
+
'player.space_info.challenge_data.maze_group_index',
|
145 |
+
'player.space_info.challenge_data.pre_maze_group_index',
|
146 |
+
'player.space_info.pass_area_progress',
|
147 |
+
'player.space_info.light_cone_count',
|
148 |
+
'player.space_info.avatar_count',
|
149 |
+
'player.space_info.achievement_count',
|
150 |
+
];
|
151 |
+
for (let i = 0; i < inputDataKeyList.length; i++) {
|
152 |
+
document.querySelector('#responseDataPlaceholderPlayer').appendChild(trElAddReturn(apiResponseData.response, inputDataKeyList[i]));
|
153 |
+
}
|
154 |
+
for (let i = 0; i < apiResponseData.response.characters.length; i++) {
|
155 |
+
let inputDataKeyList2 = [
|
156 |
+
`characters.${i}.name`,
|
157 |
+
`characters.${i}.rarity`,
|
158 |
+
`characters.${i}.rank`,
|
159 |
+
`characters.${i}.level`,
|
160 |
+
`characters.${i}.promotion`,
|
161 |
+
`characters.${i}.icon`,
|
162 |
+
`characters.${i}.preview`,
|
163 |
+
`characters.${i}.portrait`,
|
164 |
+
`characters.${i}.path.name`,
|
165 |
+
`characters.${i}.path.icon`,
|
166 |
+
`characters.${i}.element.name`,
|
167 |
+
`characters.${i}.element.icon`,
|
168 |
+
`characters.${i}.light_cone.name`,
|
169 |
+
`characters.${i}.light_cone.rarity`,
|
170 |
+
`characters.${i}.light_cone.rank`,
|
171 |
+
`characters.${i}.light_cone.level`,
|
172 |
+
`characters.${i}.light_cone.promotion`,
|
173 |
+
`characters.${i}.light_cone.icon`,
|
174 |
+
`characters.${i}.light_cone.preview`,
|
175 |
+
`characters.${i}.light_cone.portrait`,
|
176 |
+
`characters.${i}.light_cone.path.name`,
|
177 |
+
`characters.${i}.light_cone.path.icon`,
|
178 |
+
];
|
179 |
+
for (let j = 0; j < inputDataKeyList2.length; j++) {
|
180 |
+
document.querySelector('#responseDataPlaceholderCharacters').appendChild(trElAddReturn(apiResponseData.response, inputDataKeyList2[j]));
|
181 |
+
}
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
function trElAddReturn (inputData, objKey) {
|
186 |
+
const imageDetectRegex = /\.(png|jpg|jpeg|webp|gif|bmp)$/i;
|
187 |
+
const tr = document.createElement('tr');
|
188 |
+
const tdKey = document.createElement('td');
|
189 |
+
const tdValue = document.createElement('td');
|
190 |
+
tdKey.innerHTML = objKey;
|
191 |
+
// objKeyを分割して各部分を使用してオブジェクトのプロパティにアクセスします。
|
192 |
+
let keyParts = objKey.split('.');
|
193 |
+
let value = inputData;
|
194 |
+
for (let i = 0; i < keyParts.length; i++) {
|
195 |
+
// 配列のインデックスを表す文字列を数値に変換します。
|
196 |
+
if (!isNaN(keyParts[i])) {
|
197 |
+
keyParts[i] = parseInt(keyParts[i], 10);
|
198 |
+
}
|
199 |
+
value = value[keyParts[i]];
|
200 |
+
}
|
201 |
+
if (imageDetectRegex.test(value)) {
|
202 |
+
const imageEl = document.createElement('img');
|
203 |
+
imageEl.src = StarRailResBaseUrl + value;
|
204 |
+
tdValue.appendChild(imageEl);
|
205 |
+
} else {
|
206 |
+
tdValue.innerHTML = value;
|
207 |
+
}
|
208 |
+
tr.appendChild(tdKey);
|
209 |
+
tr.appendChild(tdValue);
|
210 |
+
return tr;
|
211 |
+
}
|
212 |
+
</script>
|
213 |
+
</body>
|
214 |
+
</html>
|
style.css
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
body {
|
2 |
-
padding: 2rem;
|
3 |
-
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
4 |
-
}
|
5 |
-
|
6 |
-
h1 {
|
7 |
-
font-size: 16px;
|
8 |
-
margin-top: 0;
|
9 |
-
}
|
10 |
-
|
11 |
-
p {
|
12 |
-
color: rgb(107, 114, 128);
|
13 |
-
font-size: 15px;
|
14 |
-
margin-bottom: 10px;
|
15 |
-
margin-top: 5px;
|
16 |
-
}
|
17 |
-
|
18 |
-
.card {
|
19 |
-
max-width: 620px;
|
20 |
-
margin: 0 auto;
|
21 |
-
padding: 16px;
|
22 |
-
border: 1px solid lightgray;
|
23 |
-
border-radius: 16px;
|
24 |
-
}
|
25 |
-
|
26 |
-
.card p:last-child {
|
27 |
-
margin-bottom: 0;
|
28 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|