mirror of
https://github.com/nuttylmao/nutty.gg.git
synced 2026-09-19 04:00:59 -04:00
Merge pull request #11 from vortisrd/main
TikTok Like Events not updating properly
This commit is contained in:
@@ -2725,28 +2725,47 @@ function TikTokLikes(data) {
|
|||||||
|
|
||||||
|
|
||||||
// Get the total number of likes
|
// Get the total number of likes
|
||||||
var likeCountTotal = parseInt(data.likeCount);
|
let likeCount = parseInt(data.likeCount);
|
||||||
|
|
||||||
// Search for Previous Likes from the Same User
|
// Search for Previous Likes from the Same User
|
||||||
const previousLikeContainer = document.querySelector(`li[data-user-id="${data.userId}"]`);
|
const previousLikeContainer = document.querySelector(`.likes[data-user-identifier="${data.userId}"]`);
|
||||||
|
|
||||||
// If found, fetches the previous likes, deletes the element
|
// If found, fetches the previous likes, deletes the element
|
||||||
// and then creates a new count with a sum of the like count
|
// and then creates a new count with a sum of the like count
|
||||||
if (previousLikeContainer) {
|
if (previousLikeContainer) {
|
||||||
const likeCountElem = previousLikeContainer.querySelector('#tiktok-gift-repeat-count');
|
const likeCountElem = previousLikeContainer.querySelector('#tiktok-gift-repeat-count');
|
||||||
if (likeCountElem) {
|
if (likeCountElem) {
|
||||||
var likeCountPrev = parseInt(likeCountElem.textContent.replace('x', ''));
|
const liLikeContainer = previousLikeContainer.parentElement?.parentElement
|
||||||
likeCountTotal = Math.floor(likeCountPrev + likeCountTotal);
|
if (liLikeContainer) {
|
||||||
previousLikeContainer.remove();
|
|
||||||
|
let prevLikeCount = parseInt(likeCountElem.textContent.replace('x', ''), 10);
|
||||||
|
let likeCountUpdate = Math.floor(prevLikeCount + likeCount);
|
||||||
|
let likeCountDiv = previousLikeContainer.querySelector('#tiktok-gift-repeat-count');
|
||||||
|
|
||||||
|
likeCountDiv.innerText = `x${likeCountUpdate}`;
|
||||||
|
|
||||||
|
const parent = liLikeContainer.parentElement;
|
||||||
|
if (parent) { parent.appendChild(liLikeContainer); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
// Get a reference to the template
|
// Get a reference to the template
|
||||||
const template = document.getElementById('tiktok-gift-template');
|
const template = document.getElementById('tiktok-gift-template');
|
||||||
|
|
||||||
// Create a new instance of the template
|
// Create a new instance of the template
|
||||||
const instance = template.content.cloneNode(true);
|
const instance = template.content.cloneNode(true);
|
||||||
|
|
||||||
|
// gets the GiftElement
|
||||||
|
const giftElement = instance.querySelector('.tiktok-gift');
|
||||||
|
|
||||||
|
// adds the like class
|
||||||
|
giftElement.classList.add('likes');
|
||||||
|
|
||||||
|
// and assigns the user id
|
||||||
|
giftElement.dataset.userIdentifier = data.userId;
|
||||||
|
|
||||||
// Get divs
|
// Get divs
|
||||||
const avatarImg = instance.querySelector('.tiktok-gift-avatar');
|
const avatarImg = instance.querySelector('.tiktok-gift-avatar');
|
||||||
const usernameSpan = instance.querySelector('#tiktok-gift-username');
|
const usernameSpan = instance.querySelector('#tiktok-gift-username');
|
||||||
@@ -2758,10 +2777,11 @@ function TikTokLikes(data) {
|
|||||||
usernameSpan.innerText = data.nickname;
|
usernameSpan.innerText = data.nickname;
|
||||||
giftNameSpan.innerText = 'Likes';
|
giftNameSpan.innerText = 'Likes';
|
||||||
stickerImg.src = '';
|
stickerImg.src = '';
|
||||||
repeatCountDiv.innerText = `x${likeCountTotal}`;
|
repeatCountDiv.innerText = `x${likeCount}`;
|
||||||
|
|
||||||
AddMessageItem(instance, data.msgId, 'tiktok', data.userId);
|
AddMessageItem(instance, data.msgId, 'tiktok', data.userId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function TikTokGift(data) {
|
function TikTokGift(data) {
|
||||||
if (!showTikTokGifts)
|
if (!showTikTokGifts)
|
||||||
|
|||||||
Reference in New Issue
Block a user