Skip to content

Commit

Permalink
Links and Tooltips
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Fiszh committed Nov 14, 2024
1 parent 5ca4856 commit 29c0b82
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
39 changes: 19 additions & 20 deletions src/channel/SevenTVCosmetics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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") {
Expand All @@ -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)
}
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
37 changes: 27 additions & 10 deletions src/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 `<a href="${url}" target="_blank" style="color: white;">${url}</a>`;
});
let hrefURL = message;

if (!/^https?:\/\//i.test(message)) {
hrefURL = 'http://' + message;
}

const regex = /^(?!.*\.$)(?!^\.).*\..*/;

if (regex.test(message)) {
return `<a href="${hrefURL}" target="_blank" style="color: white;">${message}</a>`;
} else {
return message
}
}

async function updateAllEmoteData() {
Expand Down Expand Up @@ -576,7 +590,9 @@ async function replaceWithEmotes(inputString, TTVMessageEmoteData, userstate, ch
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')

part = await makeLinksClickable(part);
if (userstate && !userstate["no-link"]) {
part = await makeLinksClickable(part);
}

lastEmote = false;

Expand All @@ -586,6 +602,7 @@ async function replaceWithEmotes(inputString, TTVMessageEmoteData, userstate, ch
ext: '.svg',
className: 'twemoji'
});

replacedParts.push(twemojiHTML);
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 29c0b82

Please sign in to comment.