фикс 9

This commit is contained in:
2026-04-23 15:43:45 +03:00
parent 946e461fc0
commit f9e6c31b33

View File

@@ -1303,103 +1303,101 @@ data-role="{{ p.position or '' }}"
})();
</script>
<script>
(function () {
const matchId = window.MATCH_DATA?.matchId;
const sessionToken = window.MATCH_DATA?.sessionToken;
const teamLogos = window.MATCH_DATA?.teamLogos || {};
const vmixTeamLogos = window.MATCH_DATA?.vmixTeamLogos || {};
(function () {
const matchId = window.MATCH_DATA?.matchId;
const sessionToken = window.MATCH_DATA?.sessionToken;
const teamLogos = window.MATCH_DATA?.teamLogos || {};
const vmixTeamLogos = window.MATCH_DATA?.vmixTeamLogos || {};
const currentUserLogin = window.MATCH_DATA?.currentUser?.username || null;
if (!matchId || !sessionToken) {
return;
if (!matchId || !sessionToken) {
return;
}
function formatCoachName(rawName) {
const parts = String(rawName || "").trim().split(/\s+/).filter(Boolean);
if (parts.length >= 2) {
return `${parts[1]} ${parts[0]}`;
}
return String(rawName || "").trim();
}
function formatCoachName(rawName) {
const parts = String(rawName || "").trim().split(/\s+/).filter(Boolean);
if (parts.length >= 2) {
return `${parts[1]} ${parts[0]}`;
function formatPlayerName(firstName, lastName, fallbackName) {
const result = `${String(firstName || "").trim()} ${String(lastName || "").trim()}`.trim();
return result || String(fallbackName || "").trim();
}
async function sendNeutralPersonTitle(name, role, side) {
const inputName = "ИГРОК - НЕЙТРАЛЬНЫЙ";
const teamName = TEAM_NAMES?.[side] || "";
const logoPath = getVmixTeamLogo(teamName);
const commands = [
`/api/?Function=SetText&Input=${encodeURIComponent(inputName)}&SelectedName=${encodeURIComponent("Тренер.Text")}&Value=${encodeURIComponent(name || "")}`,
`/api/?Function=SetText&Input=${encodeURIComponent(inputName)}&SelectedName=${encodeURIComponent("Должность.Text")}&Value=${encodeURIComponent(role || "")}`,
`/api/?Function=SetImage&Input=${encodeURIComponent(inputName)}&SelectedName=${encodeURIComponent("Лого.Source")}&Value=${encodeURIComponent(logoPath || "")}`,
`/api/?Function=PreviewInput&Input=${encodeURIComponent(inputName)}`
];
try {
const response = await fetch("/api/vmix/publish-command", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
credentials: "same-origin",
body: JSON.stringify({
match_id: matchId,
commands,
target_login: currentUserLogin,
meta: {
source: "person_click",
title_input: inputName,
person_name: name,
person_role: role,
side,
team_name: teamName,
logo_path: logoPath
}
})
});
if (!response.ok) {
console.error("Ошибка отправки титра в vMix:", response.status);
}
return String(rawName || "").trim();
} catch (error) {
console.error("Не удалось отправить титр в vMix:", error);
}
}
document.addEventListener("click", function (event) {
const trigger = event.target.closest(".vmix-person-trigger");
if (!trigger) return;
const personType = String(trigger.dataset.vmixPersonType || "").trim();
const side = String(trigger.dataset.side || "").trim();
const rawName = String(trigger.dataset.name || "").trim();
const firstName = String(trigger.dataset.firstName || "").trim();
const lastName = String(trigger.dataset.lastName || "").trim();
const role = String(trigger.dataset.role || "").trim();
let formattedName = "";
if (personType === "coach") {
formattedName = formatCoachName(rawName);
} else {
formattedName = formatPlayerName(firstName, lastName, rawName);
}
function formatPlayerName(firstName, lastName, fallbackName) {
const result = `${String(firstName || "").trim()} ${String(lastName || "").trim()}`.trim();
return result || String(fallbackName || "").trim();
}
if (!formattedName) return;
async function sendNeutralPersonTitle(name, role, side) {
const inputName = "ИГРОК - НЕЙТРАЛЬНЫЙ";
sendNeutralPersonTitle(formattedName, role, side);
});
})();
const teamName = TEAM_NAMES?.[side] || "";
const logoPath = getVmixTeamLogo(teamName);
const commands = [
`/api/?Function=SetText&Input=${encodeURIComponent(inputName)}&SelectedName=${encodeURIComponent("Тренер.Text")}&Value=${encodeURIComponent(name || "")}`,
`/api/?Function=SetText&Input=${encodeURIComponent(inputName)}&SelectedName=${encodeURIComponent("Должность.Text")}&Value=${encodeURIComponent(role || "")}`,
`/api/?Function=SetImage&Input=${encodeURIComponent(inputName)}&SelectedName=${encodeURIComponent("Лого.Source")}&Value=${encodeURIComponent(logoPath || "")}`,
`/api/?Function=PreviewInput&Input=${encodeURIComponent(inputName)}`
];
try {
const response = await fetch("/api/vmix/publish-command", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
credentials: "same-origin",
body: JSON.stringify({
match_id: MATCH_ID,
commands,
target_login: CURRENT_USER_LOGIN,
meta: {
source: "person_click",
title_input: inputName,
person_name: name,
person_role: role,
side,
team_name: teamName,
logo_path: logoPath
}
})
});
if (!response.ok) {
console.error("Ошибка отправки титра в vMix:", response.status);
}
} catch (error) {
console.error("Не удалось отправить титр в vMix:", error);
}
}
document.addEventListener("click", function (event) {
const trigger = event.target.closest(".vmix-person-trigger");
if (!trigger) return;
const personType = String(trigger.dataset.vmixPersonType || "").trim();
const side = String(trigger.dataset.side || "").trim();
const rawName = String(trigger.dataset.name || "").trim();
const firstName = String(trigger.dataset.firstName || "").trim();
const lastName = String(trigger.dataset.lastName || "").trim();
const role = String(trigger.dataset.role || "").trim();
const logoUrl = side === "away"
? (vmixTeamLogos.away || teamLogos.away)
: (vmixTeamLogos.home || teamLogos.home);
let formattedName = "";
if (personType === "coach") {
formattedName = formatCoachName(rawName);
} else {
formattedName = formatPlayerName(firstName, lastName, rawName);
}
if (!formattedName) return;
sendNeutralPersonTitle(formattedName, role, side);
});
})();
</script>