Replace jquery in live chat and improve the message styling (#2666)

* Replace jquery in live chat and improve the message styling

* Fix the automatic scrolling
This commit is contained in:
absidue 2022-10-04 19:55:13 +02:00 committed by GitHub
parent 39af7bbf0b
commit f87014aedc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 20 deletions

View File

@ -19,6 +19,11 @@
margin: 0; margin: 0;
} }
:deep(.liveChatEmoji) {
vertical-align: middle;
margin: 0 2px;
}
.errorIcon { .errorIcon {
width: 100%; width: 100%;
color: var(--tertiary-text-color); color: var(--tertiary-text-color);
@ -47,6 +52,7 @@
margin-right: 2px; margin-right: 2px;
height: 30px; height: 30px;
cursor: pointer; cursor: pointer;
background-color: var(--primary-color);
border-radius: 200px 200px 200px 200px; border-radius: 200px 200px 200px 200px;
-webkit-border-radius: 200px 200px 200px 200px; -webkit-border-radius: 200px 200px 200px 200px;
} }
@ -54,6 +60,7 @@
.superChatContent { .superChatContent {
margin-left: 32px; margin-left: 32px;
margin-top: 6px; margin-top: 6px;
color: var(--text-with-main-color);
} }
.superChat .channelThumbnail { .superChat .channelThumbnail {
@ -142,17 +149,18 @@
width: 100%; width: 100%;
padding-top: 5px; padding-top: 5px;
padding-bottom: 7px; padding-bottom: 7px;
display: grid;
grid-template-columns: min-content auto;
gap: 5px;
} }
.channelThumbnail { .channelThumbnail {
width: 25px; width: 25px;
float: left; border-radius: 200px;
border-radius: 200px 200px 200px 200px; -webkit-border-radius: 200px;
-webkit-border-radius: 200px 200px 200px 200px;
} }
.chatContent { .chatContent {
margin-left: 30px;
margin-top: 5px; margin-top: 5px;
margin-bottom: 2px; margin-bottom: 2px;
font-size: 12px; font-size: 12px;
@ -162,7 +170,6 @@
.channelName { .channelName {
color: var(--tertiary-text-color); color: var(--tertiary-text-color);
font-weight: bold; font-weight: bold;
padding-left: 5px;
padding-right: 5px; padding-right: 5px;
} }

View File

@ -5,7 +5,6 @@ import FtCard from '../ft-card/ft-card.vue'
import FtButton from '../ft-button/ft-button.vue' import FtButton from '../ft-button/ft-button.vue'
import FtListVideo from '../ft-list-video/ft-list-video.vue' import FtListVideo from '../ft-list-video/ft-list-video.vue'
import $ from 'jquery'
import autolinker from 'autolinker' import autolinker from 'autolinker'
import { LiveChat } from '@freetube/youtube-chat' import { LiveChat } from '@freetube/youtube-chat'
@ -74,8 +73,13 @@ export default Vue.extend({
return '445px' return '445px'
} }
}, },
hideLiveChat: function () { hideLiveChat: function () {
return this.$store.getters.getHideLiveChat return this.$store.getters.getHideLiveChat
},
scrollingBehaviour: function () {
return this.$store.getters.getDisableSmoothScrolling ? 'auto' : 'smooth'
} }
}, },
created: function () { created: function () {
@ -146,6 +150,8 @@ export default Vue.extend({
comment.messageHtml = '' comment.messageHtml = ''
comment.message.forEach((text) => { comment.message.forEach((text) => {
if (typeof text === 'undefined') return
if (typeof (text.navigationEndpoint) !== 'undefined') { if (typeof (text.navigationEndpoint) !== 'undefined') {
if (typeof (text.navigationEndpoint.watchEndpoint) !== 'undefined') { if (typeof (text.navigationEndpoint.watchEndpoint) !== 'undefined') {
const htmlRef = `<a href="https://www.youtube.com/watch?v=${text.navigationEndpoint.watchEndpoint.videoId}">${text.text}</a>` const htmlRef = `<a href="https://www.youtube.com/watch?v=${text.navigationEndpoint.watchEndpoint.videoId}">${text.text}</a>`
@ -154,7 +160,7 @@ export default Vue.extend({
comment.messageHtml = (comment.messageHtml + text.text).replace(/(<([^>]+)>)/ig, '') comment.messageHtml = (comment.messageHtml + text.text).replace(/(<([^>]+)>)/ig, '')
} }
} else if (typeof (text.alt) !== 'undefined') { } else if (typeof (text.alt) !== 'undefined') {
const htmlImg = `<img src="${text.url}" alt="${text.alt}" height="24" width="24" />` const htmlImg = `<img src="${text.url}" alt="${text.alt}" class="liveChatEmoji" height="24" width="24" />`
comment.messageHtml = comment.messageHtml.replace(/(<([^>]+)>)/ig, '') + htmlImg comment.messageHtml = comment.messageHtml.replace(/(<([^>]+)>)/ig, '') + htmlImg
} else { } else {
comment.messageHtml = (comment.messageHtml + text.text).replace(/(<([^>]+)>)/ig, '') comment.messageHtml = (comment.messageHtml + text.text).replace(/(<([^>]+)>)/ig, '')
@ -163,10 +169,7 @@ export default Vue.extend({
comment.messageHtml = autolinker.link(comment.messageHtml) comment.messageHtml = autolinker.link(comment.messageHtml)
const liveChatComments = $('.liveChatComments') if (typeof this.$refs.liveChatComments === 'undefined' && typeof this.$refs.liveChatMessage === 'undefined') {
const liveChatMessage = $('.liveChatMessage')
if (typeof (liveChatComments.get(0)) === 'undefined' && typeof (liveChatMessage.get(0)) === 'undefined') {
console.error("Can't find chat object. Stopping chat connection") console.error("Can't find chat object. Stopping chat connection")
this.liveChat.stop() this.liveChat.stop()
return return
@ -202,7 +205,12 @@ export default Vue.extend({
} }
if (this.stayAtBottom) { if (this.stayAtBottom) {
liveChatComments.animate({ scrollTop: liveChatComments.prop('scrollHeight') }) setTimeout(() => {
this.$refs.liveChatComments?.scrollTo({
top: this.$refs.liveChatComments.scrollHeight,
behavior: this.scrollingBehaviour
})
})
} }
if (this.comments.length > 150 && this.stayAtBottom) { if (this.comments.length > 150 && this.stayAtBottom) {
@ -226,9 +234,8 @@ export default Vue.extend({
}, },
onScroll: function (event) { onScroll: function (event) {
const liveChatComments = $('.liveChatComments').get(0) const liveChatComments = this.$refs.liveChatComments
if (event.wheelDelta >= 0 && this.stayAtBottom) { if (event.wheelDelta >= 0 && this.stayAtBottom) {
$('.liveChatComments').data('animating', 0)
this.stayAtBottom = false this.stayAtBottom = false
if (liveChatComments.scrollHeight > liveChatComments.clientHeight) { if (liveChatComments.scrollHeight > liveChatComments.clientHeight) {
@ -242,8 +249,10 @@ export default Vue.extend({
}, },
scrollToBottom: function () { scrollToBottom: function () {
const liveChatComments = $('.liveChatComments') this.$refs.liveChatComments.scrollTo({
liveChatComments.animate({ scrollTop: liveChatComments.prop('scrollHeight') }) top: this.$refs.liveChatComments.scrollHeight,
behavior: this.scrollingBehaviour
})
this.stayAtBottom = true this.stayAtBottom = true
this.showScrollToBottom = false this.showScrollToBottom = false
}, },

View File

@ -28,6 +28,7 @@
</div> </div>
<div <div
v-else-if="comments.length === 0" v-else-if="comments.length === 0"
ref="liveChatMessage"
class="messageContainer liveChatMessage" class="messageContainer liveChatMessage"
> >
<p <p
@ -48,7 +49,6 @@
<div <div
v-for="(comment, index) in superChatComments" v-for="(comment, index) in superChatComments"
:key="index" :key="index"
:style="{ backgroundColor: 'var(--primary-color)' }"
class="superChat" class="superChat"
:class="comment.superchat.colorClass" :class="comment.superchat.colorClass"
@click="showSuperChatComment(comment)" @click="showSuperChatComment(comment)"
@ -59,7 +59,6 @@
> >
<p <p
class="superChatContent" class="superChatContent"
:style="{ color: 'var(--text-with-main-color)' }"
> >
<span <span
class="donationAmount" class="donationAmount"
@ -105,6 +104,7 @@
</div> </div>
</div> </div>
<div <div
ref="liveChatComments"
class="liveChatComments" class="liveChatComments"
:style="{ height: chatHeight }" :style="{ height: chatHeight }"
@mousewheel="e => onScroll(e)" @mousewheel="e => onScroll(e)"
@ -143,7 +143,7 @@
v-html="comment.messageHtml" v-html="comment.messageHtml"
/> />
</div> </div>
<div <template
v-else v-else
> >
<img <img
@ -180,7 +180,7 @@
v-html="comment.messageHtml" v-html="comment.messageHtml"
/> />
</p> </p>
</div> </template>
</div> </div>
</div> </div>
<div <div