TAIN 大亂鬥快速登錄賽事成績腳本

Suifeng0214 Lv3

前言

新北某球館常舉辦大亂鬥賽,會放置一台筆電讓選手們自行新增對戰賽程,
規定贏的人填在左邊,輸的在右邊,這樣可以方便主辦方後續將每場賽事成績登錄為大筆數 2:0 。
為了方便主辦方快速登錄,我就熱心的提供協助了 :D

不多說直接上腳本吧 w

使用方法就是到 第三步:成績上傳 的頁面打開開發者工具(F12),選擇 Console 後貼上下面指令~

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
async function scoreUpdate() {
const buttons = document.querySelectorAll('[data-mdb-target="#scoreInputModal"]');
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');

// 模擬真實滑鼠點擊
const simulateHumanClick = (element) => {
element.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true }));
element.dispatchEvent(new MouseEvent('mouseup', { bubbles: true, cancelable: true }));
element.click();
};

// 1. 從網址中擷取賽事 ID
const urlMatch = window.location.pathname.match(/\/(\d+)\//);
const tournamentId = urlMatch ? urlMatch[1] : null;

if (!tournamentId) {
console.warn("⚠️ 無法從網址中找到賽事 ID。");
return;
}

console.log(`🏆 賽事 ID: ${tournamentId || '未知'} | 總共找到 ${buttons.length} 場比賽!`);

for (let i = 0; i < buttons.length; i++) {
// 移開游標焦點避免 aria-hidden 報錯
if (document.activeElement) document.activeElement.blur();
simulateHumanClick(buttons[i]);

await new Promise(resolve => setTimeout(resolve, 500));

const form = document.querySelector('#scoreInputModal form');
if (!form) continue;

const payload = new FormData(form);

// 刪除標準模式的多餘欄位,偽裝成簡易模式
payload.delete("game_win[0]");
payload.delete("game_win[1]");
payload.delete("game_point[0][]");
payload.delete("game_point[1][]");

// 設定比分與狀態
payload.set("match_point[0]", "2");
payload.set("match_point[1]", "0");
payload.set("status[0]", "7");
payload.set("status[1]", "7");

let apiTargetUrl = form.action;
if (!apiTargetUrl || apiTargetUrl === window.location.href) {
apiTargetUrl = `https://www.tain.tw/api/matches/${tournamentId}/storeAll`;
}

try {
const response = await fetch(apiTargetUrl, {
method: "POST",
credentials: "include",
headers: {
"accept": "application/json, text/javascript, */*; q=0.01",
"x-requested-with": "XMLHttpRequest",
"X-CSRF-TOKEN": csrfToken
},
body: payload
});

if (response.ok) {
console.log(`✅ 第 ${i + 1} 場 2:0 更新成功!`);
} else {
console.error(`❌ 第 ${i + 1} 場失敗,狀態碼:${response.status}`);
}
} catch (err) {
console.error(`❌ 第 ${i + 1} 場連線錯誤:`, err);
}

const closeBtn = document.querySelector('#scoreInputModal .btn-close');
if (closeBtn) simulateHumanClick(closeBtn);
await new Promise(resolve => setTimeout(resolve, 500));
}

console.log("🎉 完成!請按 F5 重新整理網頁看看成果!");
}

scoreUpdate();
On this page
TAIN 大亂鬥快速登錄賽事成績腳本