Fix empty description box showing for the Invidious API (#2614)

* Fix empty description box showing for the Invidious API

* Add comment about HTML parsing
This commit is contained in:
absidue 2022-09-26 22:36:41 +02:00 committed by GitHub
parent 9de1a5e4dc
commit 6d1b0a63b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View File

@ -2,7 +2,6 @@ import Vue from 'vue'
import FtCard from '../ft-card/ft-card.vue' import FtCard from '../ft-card/ft-card.vue'
import FtTimestampCatcher from '../ft-timestamp-catcher/ft-timestamp-catcher.vue' import FtTimestampCatcher from '../ft-timestamp-catcher/ft-timestamp-catcher.vue'
import autolinker from 'autolinker' import autolinker from 'autolinker'
import $ from 'jquery'
export default Vue.extend({ export default Vue.extend({
name: 'WatchVideoDescription', name: 'WatchVideoDescription',
@ -31,13 +30,22 @@ export default Vue.extend({
}, },
mounted: function () { mounted: function () {
if (this.descriptionHtml !== '') { if (this.descriptionHtml !== '') {
this.shownDescription = this.parseDescriptionHtml(this.descriptionHtml) const parsed = this.parseDescriptionHtml(this.descriptionHtml)
// the invidious API returns emtpy html elements when the description is empty
// so we need to parse it to see if there is any meaningful text in the html
// or if it's just empty html elements e.g. `<p></p>`
const testDiv = document.createElement('div')
testDiv.innerHTML = parsed
if (!/^\s*$/.test(testDiv.innerText)) {
this.shownDescription = parsed
}
} else { } else {
if (!/^\s*$/.test(this.description)) {
this.shownDescription = autolinker.link(this.description) this.shownDescription = autolinker.link(this.description)
} }
if (/^\s*$/.test(this.shownDescription)) {
$('.videoDescription')[0].style.display = 'none'
} }
}, },
methods: { methods: {

View File

@ -1,5 +1,8 @@
<template> <template>
<ft-card class="videoDescription"> <ft-card
v-if="shownDescription.length > 0"
class="videoDescription"
>
<ft-timestamp-catcher <ft-timestamp-catcher
class="description" class="description"
:input-html="shownDescription" :input-html="shownDescription"