mirror of
https://github.com/nuttylmao/nutty.gg.git
synced 2026-09-19 04:00:59 -04:00
Move a tonne of reused functions to helpers.js
This commit is contained in:
@@ -7,7 +7,6 @@ const urlParams = new URLSearchParams(queryString);
|
||||
|
||||
const sbServerAddress = urlParams.get("address") || "127.0.0.1";
|
||||
const sbServerPort = urlParams.get("port") || "8080";
|
||||
const avatarMap = new Map();
|
||||
|
||||
const mainContainer = document.getElementById('mainContainer');
|
||||
const alertBox = document.getElementById('alertBox');
|
||||
@@ -70,7 +69,7 @@ const showTwitchRaids = GetBooleanParam("showTwitchRaids", true);
|
||||
const twitchRaidAction = urlParams.get("twitchRaidAction") || "";
|
||||
|
||||
// Which Kick alerts do you want to see?
|
||||
let kickUsername = urlParams.get("kickUsername") || "";
|
||||
const kickUsername = urlParams.get("kickUsername") || "";
|
||||
const showKickSubs = GetBooleanParam("showKickSubs", true);
|
||||
const kickSubAction = urlParams.get("kickSubAction") || "";
|
||||
const showKickChannelPointRedemptions = GetBooleanParam("showKickChannelPointRedemptions", true);
|
||||
@@ -109,9 +108,6 @@ const tipeeestreamDonationAction = urlParams.get("tipeeestreamDonationAction") |
|
||||
const showFourthwallAlerts = GetBooleanParam("showFourthwallAlerts", false);
|
||||
const fourthwallAlertAction = urlParams.get("fourthwallAlertAction") || "";
|
||||
|
||||
// Kick is stupid and turns underscores into dashes which fuck everything up, therefore do a find/replace to make it work good
|
||||
kickUsername = kickUsername.replace(/_/g, "-");
|
||||
|
||||
// Set avatar visibility
|
||||
if (!showAvatar) {
|
||||
avatarElement.style.display = 'none';
|
||||
@@ -1384,7 +1380,6 @@ async function KickKicksGifted(data) {
|
||||
const kickKicksIcon = `<img src=icons/badges/kick-kicks.svg style="height: 0.8em"/>`;
|
||||
|
||||
// Render avatars
|
||||
// const avatarURL = await GetAvatar(data.sender.username.replace('_', '-'), 'kick');
|
||||
const avatarURL = `https://files.kick.com/kicks/gifts/${data.gift.gift_id.replace('_', '-')}.webp`;
|
||||
|
||||
UpdateAlertBox(
|
||||
@@ -1464,83 +1459,6 @@ async function TikTokSubscribe(data) {
|
||||
// HELPER FUNCTIONS //
|
||||
//////////////////////
|
||||
|
||||
function GetBooleanParam(paramName, defaultValue) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const paramValue = urlParams.get(paramName);
|
||||
|
||||
if (paramValue === null) {
|
||||
return defaultValue; // Parameter not found
|
||||
}
|
||||
|
||||
const lowercaseValue = paramValue.toLowerCase(); // Handle case-insensitivity
|
||||
|
||||
if (lowercaseValue === 'true') {
|
||||
return true;
|
||||
} else if (lowercaseValue === 'false') {
|
||||
return false;
|
||||
} else {
|
||||
return paramValue; // Return original string if not 'true' or 'false'
|
||||
}
|
||||
}
|
||||
|
||||
function GetIntParam(paramName, defaultValue) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const paramValue = urlParams.get(paramName);
|
||||
|
||||
if (paramValue === null) {
|
||||
return defaultValue; // or undefined, or a default value, depending on your needs
|
||||
}
|
||||
|
||||
console.log(paramValue);
|
||||
|
||||
const intValue = parseInt(paramValue, 10); // Parse as base 10 integer
|
||||
|
||||
if (isNaN(intValue)) {
|
||||
return null; // or handle the error in another way, e.g., throw an error
|
||||
}
|
||||
|
||||
return intValue;
|
||||
}
|
||||
|
||||
async function GetAvatar(username, platform) {
|
||||
|
||||
// First, check if the username is hashed already
|
||||
if (avatarMap.has(`${username}-${platform}`)) {
|
||||
console.debug(`Avatar found for ${username} (${platform}). Retrieving from hash map.`)
|
||||
return avatarMap.get(`${username}-${platform}`);
|
||||
}
|
||||
|
||||
// If code reaches this point, the username hasn't been hashed, so retrieve avatar
|
||||
switch (platform) {
|
||||
case 'twitch':
|
||||
{
|
||||
console.debug(`No avatar found for ${username} (${platform}). Retrieving from Decapi.`)
|
||||
let response = await fetch('https://decapi.me/twitch/avatar/' + username);
|
||||
let data = await response.text();
|
||||
avatarMap.set(`${username}-${platform}`, data);
|
||||
return data;
|
||||
}
|
||||
case 'kick':
|
||||
{
|
||||
console.debug(`No avatar found for ${username} (${platform}). Retrieving from Kick.`)
|
||||
let response = await fetch('https://kick.com/api/v2/channels/' + username);
|
||||
console.log('https://kick.com/api/v2/channels/' + username)
|
||||
let data = await response.json();
|
||||
let avatarURL = data.user.profile_pic;
|
||||
if (!avatarURL)
|
||||
avatarURL = 'https://kick.com/img/default-profile-pictures/default2.jpeg';
|
||||
avatarMap.set(`${username}-${platform}`, avatarURL);
|
||||
return avatarURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function DecodeHTMLString(html) {
|
||||
var txt = document.createElement("textarea");
|
||||
txt.innerHTML = html;
|
||||
return txt.value;
|
||||
}
|
||||
|
||||
// I used Gemini for this shit so if it doesn't work, blame Google
|
||||
function FindFirstImageUrl(jsonObject) {
|
||||
if (typeof jsonObject !== 'object' || jsonObject === null) {
|
||||
@@ -1745,43 +1663,6 @@ function UpdateAlertBox(platform, avatarURL, headerText, descriptionText, attrib
|
||||
|
||||
}
|
||||
|
||||
async function GetKickIds(username) {
|
||||
const url = `https://kick.com/api/v2/channels/${username}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
if (data.chatroom && data.chatroom.id) {
|
||||
return { chatroomId: data.chatroom.id, channelId: data.chatroom.channel_id };
|
||||
} else {
|
||||
throw new Error("Chatroom ID not found in response.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch chatroom ID:", error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function GetKickSubBadges(username) {
|
||||
const response = await fetch(`https://kick.com/api/v2/channels/${username}`);
|
||||
const data = await response.json();
|
||||
|
||||
return data.subscriber_badges || [];
|
||||
}
|
||||
|
||||
function GetKickBadgeURL(data) {
|
||||
switch (data.type) {
|
||||
case 'subscriber':
|
||||
return CalculateKickSubBadge(data.count);
|
||||
default:
|
||||
return `icons/badges/kick-${data.type}.svg`;
|
||||
}
|
||||
}
|
||||
|
||||
function CalculateKickSubBadge(months) {
|
||||
if (!Array.isArray(kickSubBadges)) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user