From 29c0b824ff402a702b590ec49faef42390396dd6 Mon Sep 17 00:00:00 2001
From: Killa Fish <61081555+Fiszh@users.noreply.github.com>
Date: Thu, 14 Nov 2024 13:51:04 +0100
Subject: [PATCH] Links and Tooltips
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
1. Links now display even if they’re formatted as "x.y" without needing "http://" or "https://"
2. Hovering over an animated emote no longer starts it over
---
src/channel/SevenTVCosmetics.js | 39 ++++++++++++++++-----------------
src/channel/index.js | 37 ++++++++++++++++++++++---------
src/tooltip.js | 4 ++--
3 files changed, 48 insertions(+), 32 deletions(-)
diff --git a/src/channel/SevenTVCosmetics.js b/src/channel/SevenTVCosmetics.js
index 1d78903..9026384 100644
--- a/src/channel/SevenTVCosmetics.js
+++ b/src/channel/SevenTVCosmetics.js
@@ -31,7 +31,7 @@ async function updateCosmetics(body) {
const object = body.object
if (!object.user) {
- const data = object.data
+ const data = object.data
const foundPaint = cosmetics.paints.find(paint =>
paint &&
@@ -92,21 +92,21 @@ async function updateCosmetics(body) {
// SHADOWS
let shadow = null;
-
+
if (data.shadows.length > 0) {
const shadows = data.shadows;
-
+
shadow = await shadows.map(shadow => {
let rgbaColor = argbToRgba(shadow.color);
-
+
rgbaColor = rgbaColor.replace(/rgba\((\d+), (\d+), (\d+), (\d+(\.\d+)?)\)/, `rgba($1, $2, $3)`);
-
+
return `drop-shadow(${rgbaColor} ${shadow.x_offset}px ${shadow.y_offset}px ${shadow.radius}px)`;
}).join(' ');
-
+
push["shadows"] = shadow
}
-
+
cosmetics.paints.push(push)
}
} else if (body.object.name == "Personal Emotes" || body.object.user || body.object.id === "00000000000000000000000000") {
@@ -124,19 +124,19 @@ async function updateCosmetics(body) {
const foundUser = cosmetics.user_info.find(user => user["personal_set_id"] === userId);
if (foundUser && body["pushed"]) {
- foundUser.personal_emotes = await mapPersonalEmotes(body.pushed);
+ const mappedEmotes = await mapPersonalEmotes(body.pushed);
+ foundUser.personal_emotes = mappedEmotes
+
+ console.log(mappedEmotes)
+ console.log(foundUser)
// UPDATE USER INFO
if (foundUser["ttv_user_id"]) {
- if (Array.isArray(TTVUsersData)) {
- const foundTwitchUser = TTVUsersData.find(user => user.userId === foundUser["ttv_user_id"]);
-
- if (foundTwitchUser) {
- if (foundTwitchUser.cosmetics) {
- Object.assign(foundTwitchUser.cosmetics, foundUser);
- } else {
- foundTwitchUser.cosmetics = foundUser;
- }
+ const foundTwitchUser = TTVUsersData.find(user => user.userId === foundUser["ttv_user_id"]);
+
+ if (foundTwitchUser) {
+ if (foundTwitchUser.cosmetics) {
+ //foundTwitchUser.cosmetics = Object.keys(foundUser)
}
}
}
@@ -160,8 +160,7 @@ async function createCosmetic7TVProfile(body) {
"paint_id": null,
"badge_id": null,
"avatar_url": null,
- "personal_set_id": null,
- "personal_emotes": null,
+ "personal_emotes": [],
}
if (owner.connections) {
@@ -189,7 +188,7 @@ async function createCosmetic7TVProfile(body) {
}
if (body.object.flags === 4) {
- infoTable["personal_set_id"] = body.object.id
+ infoTable["personal_set_id"] = String(body.object.id);
}
// AVOID DUPLICATION
diff --git a/src/channel/index.js b/src/channel/index.js
index 8d8eb56..76d13f0 100644
--- a/src/channel/index.js
+++ b/src/channel/index.js
@@ -150,26 +150,31 @@ const custom_userstate = {
Server: { // ServerUserstate
"username": 'SERVER',
"badges-raw": 'Server/1',
+ "no-link": true,
"color": "#FFFFFF"
},
SevenTV: { // SevenTVServerUserstate
"username": '7TV',
"badges-raw": '7TVServer/1',
+ "no-link": true,
"color": "#28aba1"
},
BTTV: { // BTTVServerUserstate
"username": 'BTTV',
"badges-raw": 'BTTVServer/1',
+ "no-link": true,
"color": "#d50014"
},
FFZ: { // FFZServerUserstate
"username": 'FFZ',
"badges-raw": 'FFZServer/1',
+ "no-link": true,
"color": "#08bc8c"
},
TTVAnnouncement: { // TTVAnnouncementUserstate
"username": '',
"badges-raw": 'NONE/1',
+ "no-link": true,
"color": "#FFFFFF"
}
}
@@ -189,7 +194,7 @@ async function handleChat(channel, userstate, message, self) {
userstate.username = `(BLOCKED) ${userstate.username}`
}
- if ((!blockedUser0 && !blockedUser1) || canHandleMessage) {
+ if ((!blockedUser0 && !blockedUser1) || canHandleMessage) {
if (userstate.color !== null && userstate.color !== undefined && userstate.color) {
userstate.color = lightenColor(userstate.color)
}
@@ -259,12 +264,21 @@ function convertSeconds(seconds) {
}
async function makeLinksClickable(message) {
- if (!message) return '';
- const urlRegex = /\b(https?:\/\/[^\s]+)/g;
+ if (!message) { return; }
- return message.replace(urlRegex, function (url) {
- return `${url}`;
- });
+ let hrefURL = message;
+
+ if (!/^https?:\/\//i.test(message)) {
+ hrefURL = 'http://' + message;
+ }
+
+ const regex = /^(?!.*\.$)(?!^\.).*\..*/;
+
+ if (regex.test(message)) {
+ return `${message}`;
+ } else {
+ return message
+ }
}
async function updateAllEmoteData() {
@@ -576,7 +590,9 @@ async function replaceWithEmotes(inputString, TTVMessageEmoteData, userstate, ch
.replace(//g, '>')
- part = await makeLinksClickable(part);
+ if (userstate && !userstate["no-link"]) {
+ part = await makeLinksClickable(part);
+ }
lastEmote = false;
@@ -586,6 +602,7 @@ async function replaceWithEmotes(inputString, TTVMessageEmoteData, userstate, ch
ext: '.svg',
className: 'twemoji'
});
+
replacedParts.push(twemojiHTML);
}
}
@@ -2285,14 +2302,14 @@ async function detect7TVEmoteSetChange() {
condition: { platform: 'TWITCH', ctx: 'channel', id: channelTwitchID }
}
}
-
+
if (SevenTVID) {
await SevenTVWebsocket.send(JSON.stringify(subscribeEmoteSetMessage));
await SevenTVWebsocket.send(JSON.stringify(subscribeEmoteMessage));
}
await SevenTVWebsocket.send(JSON.stringify(subscribeEntitlementCreateMessage));
-
+
await chat_alert(custom_userstate.SevenTV, 'SUBSCRIBED TO ALL OF THE EVENTS')
debugChange("7TV", "websocket", true);
@@ -2766,7 +2783,7 @@ async function fetchFFZUserData() {
};
});
- // BADGES
+ // BADGES
if (data.room) {
if (data.room["vip_badge"] && Object.keys(data.room["vip_badge"]).length > 0) {
diff --git a/src/tooltip.js b/src/tooltip.js
index d0c75f0..a4f8460 100644
--- a/src/tooltip.js
+++ b/src/tooltip.js
@@ -36,8 +36,8 @@ function updateFramePosition(mouseX, mouseY) {
}
function showFrame(tooltipData) {
- frameImg.src = tooltipData.imgSrc;
-
+ frameImg.src = tooltipData.imgSrc + '?t=' + new Date().getTime();
+
if (tooltipData.imgSrc) {
frameImg.style.display = "block";
} else {