diff options
author | Ajay Ramachandran <[email protected]> | 2020-05-11 20:45:48 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2020-05-11 20:45:48 -0400 |
commit | c68aabaa4080a7c6ccb79126b30e874a08fdca1a (patch) | |
tree | 10c8229cddabec1cabe051addaf70a142b24cdc5 | |
parent | 70239bc04583a1e10e23c0c99469cf46ac7d3c56 (diff) | |
download | SponsorBlock-c68aabaa4080a7c6ccb79126b30e874a08fdca1a.tar.gz SponsorBlock-c68aabaa4080a7c6ccb79126b30e874a08fdca1a.zip |
Added null coalescence checks to video info
-rw-r--r-- | src/components/SubmissionNoticeComponent.tsx | 2 | ||||
-rw-r--r-- | src/content.ts | 11 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/components/SubmissionNoticeComponent.tsx b/src/components/SubmissionNoticeComponent.tsx index de7d4df9..a380fd73 100644 --- a/src/components/SubmissionNoticeComponent.tsx +++ b/src/components/SubmissionNoticeComponent.tsx @@ -161,7 +161,7 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S } // Check if any non music categories are being used on a music video - if (this.contentContainer().videoInfo.microformat.playerMicroformatRenderer.category === "Music") { + if (this.contentContainer().videoInfo?.microformat?.playerMicroformatRenderer?.category === "Music") { let sponsorTimesSubmitting = this.props.contentContainer().sponsorTimesSubmitting; for (const sponsorTime of sponsorTimesSubmitting) { if (!sponsorTime.category.startsWith("music_")) { diff --git a/src/content.ts b/src/content.ts index 6d234a9a..f348da51 100644 --- a/src/content.ts +++ b/src/content.ts @@ -660,7 +660,7 @@ function sponsorsLookup(id: string) { //check if this video was uploaded recently utils.wait(() => !!videoInfo).then(() => { - let dateUploaded = videoInfo.microformat.playerMicroformatRenderer.uploadDate; + let dateUploaded = videoInfo?.microformat?.playerMicroformatRenderer?.uploadDate; //if less than 3 days old if (Date.now() - new Date(dateUploaded).getTime() < 259200000) { @@ -812,7 +812,12 @@ function updatePreviewBar() { //checks if this channel is whitelisted, should be done only after the channelID has been loaded function whitelistCheck() { - channelID = videoInfo.videoDetails.channelId; + channelID = videoInfo?.videoDetails?.channelId; + if (!channelID) { + channelID = null; + + return; + } //see if this is a whitelisted channel let whitelistedChannels = Config.config.whitelistedChannels; @@ -1545,7 +1550,7 @@ function getSegmentsMessage(segments: number[][]): string { * Assumes that the the privacy info is available. */ function isUnlisted(): boolean { - return videoInfo.microformat.playerMicroformatRenderer.isUnlisted || videoInfo.videoDetails.isPrivate; + return videoInfo?.microformat?.playerMicroformatRenderer?.isUnlisted || videoInfo?.videoDetails?.isPrivate; } /** |