Skip to content

Commit 9906f6d

Browse files
authored
Merge pull request #13 from nuttylmao/revert-11-main
Revert "TikTok Like Events not updating properly"
2 parents b7fcf23 + 843d082 commit 9906f6d

File tree

1 file changed

+21
-41
lines changed

1 file changed

+21
-41
lines changed

multichat-overlay/script.js

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,62 +2725,42 @@ function TikTokLikes(data) {
27252725

27262726

27272727
// Get the total number of likes
2728-
let likeCount = parseInt(data.likeCount);
2728+
var likeCountTotal = parseInt(data.likeCount);
27292729

27302730
// Search for Previous Likes from the Same User
2731-
const previousLikeContainer = document.querySelector(`.likes[data-user-identifier="${data.userId}"]`);
2731+
const previousLikeContainer = document.querySelector(`li[data-user-id="${data.userId}"]`);
27322732

27332733
// If found, fetches the previous likes, deletes the element
27342734
// and then creates a new count with a sum of the like count
27352735
if (previousLikeContainer) {
27362736
const likeCountElem = previousLikeContainer.querySelector('#tiktok-gift-repeat-count');
27372737
if (likeCountElem) {
2738-
const liLikeContainer = previousLikeContainer.parentElement?.parentElement
2739-
if (liLikeContainer) {
2740-
2741-
let prevLikeCount = parseInt(likeCountElem.textContent.replace('x', ''), 10);
2742-
let likeCountUpdate = Math.floor(prevLikeCount + likeCount);
2743-
let likeCountDiv = previousLikeContainer.querySelector('#tiktok-gift-repeat-count');
2744-
2745-
likeCountDiv.innerText = `x${likeCountUpdate}`;
2746-
2747-
const parent = liLikeContainer.parentElement;
2748-
if (parent) { parent.appendChild(liLikeContainer); }
2749-
}
2738+
var likeCountPrev = parseInt(likeCountElem.textContent.replace('x', ''));
2739+
likeCountTotal = Math.floor(likeCountPrev + likeCountTotal);
2740+
previousLikeContainer.remove();
27502741
}
27512742
}
27522743

2753-
else {
2754-
// Get a reference to the template
2755-
const template = document.getElementById('tiktok-gift-template');
2756-
2757-
// Create a new instance of the template
2758-
const instance = template.content.cloneNode(true);
2759-
2760-
// gets the GiftElement
2761-
const giftElement = instance.querySelector('.tiktok-gift');
2762-
2763-
// adds the like class
2764-
giftElement.classList.add('likes');
2744+
// Get a reference to the template
2745+
const template = document.getElementById('tiktok-gift-template');
27652746

2766-
// and assigns the user id
2767-
giftElement.dataset.userIdentifier = data.userId;
2747+
// Create a new instance of the template
2748+
const instance = template.content.cloneNode(true);
27682749

2769-
// Get divs
2770-
const avatarImg = instance.querySelector('.tiktok-gift-avatar');
2771-
const usernameSpan = instance.querySelector('#tiktok-gift-username');
2772-
const giftNameSpan = instance.querySelector('#tiktok-gift-name');
2773-
const stickerImg = instance.querySelector('.tiktok-gift-sticker');
2774-
const repeatCountDiv = instance.querySelector('#tiktok-gift-repeat-count');
2750+
// Get divs
2751+
const avatarImg = instance.querySelector('.tiktok-gift-avatar');
2752+
const usernameSpan = instance.querySelector('#tiktok-gift-username');
2753+
const giftNameSpan = instance.querySelector('#tiktok-gift-name');
2754+
const stickerImg = instance.querySelector('.tiktok-gift-sticker');
2755+
const repeatCountDiv = instance.querySelector('#tiktok-gift-repeat-count');
27752756

2776-
avatarImg.src = data.profilePictureUrl;
2777-
usernameSpan.innerText = data.nickname;
2778-
giftNameSpan.innerText = 'Likes';
2779-
stickerImg.src = '';
2780-
repeatCountDiv.innerText = `x${likeCount}`;
2757+
avatarImg.src = data.profilePictureUrl;
2758+
usernameSpan.innerText = data.nickname;
2759+
giftNameSpan.innerText = 'Likes';
2760+
stickerImg.src = '';
2761+
repeatCountDiv.innerText = `x${likeCountTotal}`;
27812762

2782-
AddMessageItem(instance, data.msgId, 'tiktok', data.userId);
2783-
}
2763+
AddMessageItem(instance, data.msgId, 'tiktok', data.userId);
27842764
}
27852765

27862766
function TikTokGift(data) {

0 commit comments

Comments
 (0)