Fixed issue where Mass Gifted subs were showing "0 x Gifted Subs)

This commit is contained in:
nuttylmao
2025-07-29 02:14:49 +10:00
parent 20a0e59c4a
commit 38929ba471
+45 -33
View File
@@ -298,50 +298,62 @@ async function CustomEvent(data) {
break; break;
case ('KickMassGiftSubscription'): case ('KickMassGiftSubscription'):
{ {
avatarEl.src = ConvertWEBPToPNG(await GetAvatar(data.user, 'kick')); // There is only one sub, so use the same template for a single gifted sub
if ('recipient.userName' in data) {
avatarEl.src = ConvertWEBPToPNG(data["recipient.profilePicture"]);
titleEl.innerText = `Gifted Sub`;
// Calculate how many subs were gived const messageEl = document.createElement('div');
let maxIndex = -1; messageEl.innerHTML = `<b>${data["recipient.userName"]}</b><br>received a sub from<br><b>${data.user}</b>!`;
for (const key in data) {
const match = key.match(/^recipient\.(\d+)\./); contentEl.appendChild(messageEl);
if (match) { }
const index = parseInt(match[1], 10); else {
if (index > maxIndex) { avatarEl.src = ConvertWEBPToPNG(await GetAvatar(data.user, 'kick'));
maxIndex = index;
// Calculate how many subs were gived
let maxIndex = -1;
for (const key in data) {
const match = key.match(/^recipient\.(\d+)\./);
if (match) {
const index = parseInt(match[1], 10);
if (index > maxIndex) {
maxIndex = index;
}
} }
} }
} const totalGifts = maxIndex + 1;
const totalGifts = maxIndex + 1;
titleEl.innerHTML = `${totalGifts} × Gifted Subs`; titleEl.innerHTML = `${totalGifts} × Gifted Subs`;
subtitleEl.innerText = `${data.user}`; subtitleEl.innerText = `${data.user}`;
const messageEl = document.createElement('div'); const messageEl = document.createElement('div');
// Loop through each recipient and include it in the receipt // Loop through each recipient and include it in the receipt
const recipients = {}; const recipients = {};
// Reconstruct recipient objects // Reconstruct recipient objects
for (const key in data) { for (const key in data) {
const match = key.match(/^recipient\.(\d+)\.(.+)$/); const match = key.match(/^recipient\.(\d+)\.(.+)$/);
if (match) { if (match) {
const index = match[1]; const index = match[1];
const field = match[2]; const field = match[2];
if (!recipients[index]) { if (!recipients[index]) {
recipients[index] = {}; recipients[index] = {};
}
recipients[index][field] = data[key];
} }
recipients[index][field] = data[key];
} }
}
// Loop through and print userName // Loop through and print userName
for (const index in recipients) { for (const index in recipients) {
messageEl.innerHTML += `${recipients[index].userName}<br>`; messageEl.innerHTML += `${recipients[index].userName}<br>`;
} }
contentEl.appendChild(messageEl); contentEl.appendChild(messageEl);
}
} }
break; break;
@@ -661,7 +673,7 @@ function IsValidUrl(string) {
} }
function EscapeRegExp(string) { function EscapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
} }