Untitled
unknown
plain_text
9 months ago
3.0 kB
12
Indexable
let fieldData = {};
let hideTimeout;
function getSoundURL(field) {
if (!field) return "";
if (typeof field === "string") return field;
if (field.sound) return field.sound;
if (field.value?.sound) return field.value.sound;
if (field.value && typeof field.value === "string") return field.value;
return "";
}
function getSoundVolume(field) {
if (!field) return 1.0;
if (field.volume !== undefined) return parseFloat(field.volume) || 1.0;
if (field.value?.volume !== undefined) return parseFloat(field.value.volume) || 1.0;
return 1.0;
}
function playSound(field) {
const url = getSoundURL(field);
const volume = getSoundVolume(field);
if (!url) return;
try {
const audio = new Audio(url);
audio.volume = volume;
audio.play().catch(err => console.warn("Autoplay blocked:", err));
} catch (err) {
console.warn("Failed to play sound:", err);
}
}
function showAlert(username, message, color, soundField) {
clearTimeout(hideTimeout);
username = username?.toUpperCase() || "VIEWER";
document.getElementById("username").textContent = username;
document.querySelector(".event-tag-text").textContent = message.toUpperCase();
document.documentElement.style.setProperty("--event-color", color || "var(--color-default)");
document.getElementById("hud-alert").classList.add("active");
playSound(soundField);
hideTimeout = setTimeout(() => {
document.getElementById("hud-alert").classList.remove("active");
}, 7000);
}
window.addEventListener("onWidgetLoad", (obj) => {
fieldData = obj.detail.fieldData;
const logo = getSoundURL(fieldData.logo);
if (logo) document.getElementById("logo").src = logo;
});
window.addEventListener("onEventReceived", (obj) => {
const listener = obj.detail.listener;
const e = obj.detail.event;
if (!e) return;
const username = e.name || e.displayName || "VIEWER";
const months =
e.amount ||
e.cumulativeMonths ||
e.months ||
e.message?.months ||
1;
if (listener === "follower-latest" && fieldData.enableFollow)
showAlert(username, "NEW FOLLOW", fieldData.followColor, fieldData.followSound);
if (listener === "subscriber-latest") {
if (months > 1 && fieldData.enableResub) {
showAlert(username, `RE-SUB X${months}`, fieldData.resubColor, fieldData.resubSound);
} else if (fieldData.enableSub) {
showAlert(username, "NEW SUBSCRIPTION", fieldData.subColor, fieldData.subSound);
}
}
if (listener === "subscriber-gifted-latest" && fieldData.enableGift)
showAlert(username, "GIFTED SUB", fieldData.giftColor, fieldData.giftSound);
if (listener === "raid-latest" && fieldData.enableRaid)
showAlert(username, "RAID INCOMING", fieldData.raidColor, fieldData.raidSound);
if ((listener === "cheer-latest" || listener === "tip-latest") && fieldData.enableTip)
showAlert(username, "NEW TIP", fieldData.tipColor, fieldData.tipSound);
});
Editor is loading...
Leave a Comment