Spaces:
Running
Running
Upload index.html
Browse files- index.html +35 -10
index.html
CHANGED
|
@@ -407,19 +407,44 @@
|
|
| 407 |
chip.querySelector('.number').innerText = luckyNum;
|
| 408 |
|
| 409 |
try {
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
} else {
|
| 418 |
-
|
| 419 |
}
|
| 420 |
} catch (e) {
|
| 421 |
console.error("API Error", e);
|
| 422 |
-
finalOutput = "查詢失敗";
|
| 423 |
}
|
| 424 |
}
|
| 425 |
|
|
@@ -428,7 +453,7 @@
|
|
| 428 |
chip.classList.remove('searching');
|
| 429 |
resDiv.innerHTML = "";
|
| 430 |
|
| 431 |
-
if(typeof finalVal === 'number'){
|
| 432 |
chip.classList.add('done');
|
| 433 |
resDiv.innerText = finalOutput;
|
| 434 |
} else {
|
|
|
|
| 407 |
chip.querySelector('.number').innerText = luckyNum;
|
| 408 |
|
| 409 |
try {
|
| 410 |
+
// 目標 API 網址
|
| 411 |
+
const targetUrl = `https://www.angio.net/newpi/piquery?q=${luckyNum}`;
|
| 412 |
+
let data = null;
|
| 413 |
+
|
| 414 |
+
// 實作多層 Proxy 備援機制,防止單一 Proxy 被阻礙或學校網路擋住
|
| 415 |
+
try {
|
| 416 |
+
// 優先使用 corsproxy (最快)
|
| 417 |
+
const res = await fetch(`https://corsproxy.io/?${encodeURIComponent(targetUrl)}`);
|
| 418 |
+
if (!res.ok) throw new Error("Proxy 1 Fail");
|
| 419 |
+
data = await res.json();
|
| 420 |
+
} catch (e1) {
|
| 421 |
+
try {
|
| 422 |
+
// 備用 1: codetabs
|
| 423 |
+
const res = await fetch(`https://api.codetabs.com/v1/proxy/?quest=${targetUrl}`);
|
| 424 |
+
if (!res.ok) throw new Error("Proxy 2 Fail");
|
| 425 |
+
data = await res.json();
|
| 426 |
+
} catch (e2) {
|
| 427 |
+
// 備用 2: allorigins
|
| 428 |
+
const res = await fetch(`https://api.allorigins.win/raw?url=${encodeURIComponent(targetUrl)}`);
|
| 429 |
+
if (!res.ok) throw new Error("Proxy 3 Fail");
|
| 430 |
+
data = await res.json();
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
if (data && data.status === 'OK' && data.r && data.r.length > 0) {
|
| 435 |
+
const resultData = data.r[0];
|
| 436 |
+
if (resultData.status === 'found') {
|
| 437 |
+
finalVal = resultData.p;
|
| 438 |
+
finalOutput = `在第 ${finalVal} 位`;
|
| 439 |
+
} else {
|
| 440 |
+
finalOutput = "在圓周率中未找到";
|
| 441 |
+
}
|
| 442 |
} else {
|
| 443 |
+
throw new Error("Invalid API Response");
|
| 444 |
}
|
| 445 |
} catch (e) {
|
| 446 |
console.error("API Error", e);
|
| 447 |
+
finalOutput = "查詢失敗 (網路/CORS/無回應)";
|
| 448 |
}
|
| 449 |
}
|
| 450 |
|
|
|
|
| 453 |
chip.classList.remove('searching');
|
| 454 |
resDiv.innerHTML = "";
|
| 455 |
|
| 456 |
+
if (typeof finalVal === 'number') {
|
| 457 |
chip.classList.add('done');
|
| 458 |
resDiv.innerText = finalOutput;
|
| 459 |
} else {
|