Skip to content

Commit

Permalink
More robust way to detect if video has no description
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Sep 5, 2024
1 parent a336b9f commit 42577fb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/render/DesciptionPortPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,27 @@ export class DescriptionPortPill {
// make request to get the port video first, while waiting for the page to load
await this.getPortVideo(videoId);

this.hasDescription = true;
const referenceNode = await waitFor(() => document.querySelector(".basic-desc-info") as HTMLElement);
if (!referenceNode) {
console.error("Description element not found");
}

// wait for the sibling span to load, only when there is a description
await waitFor(getPageLoaded, 20000, 10);

// if the desc from window object is empty, and the description container is hidden,
// the video has no description
const desc = await getVideoDescriptionFromWindow();
this.hasDescription = desc && desc !== "";
if (!desc || desc == "") {
const container = (await waitFor(() =>
document.querySelector("div.video-desc-container")
)) as HTMLDivElement;
if (container.style.display == "none") {
this.hasDescription = false;
}
}

if (this.hasDescription) {
await waitFor(() => referenceNode.querySelector(".desc-info-text")?.textContent, 20000, 50).catch(() => {
console.error("Failed to find description text element");
Expand Down

0 comments on commit 42577fb

Please sign in to comment.