Skip to content

Commit d7d638a

Browse files
author
Shane Osbourne
committed
use initial title if available
1 parent e6582d8 commit d7d638a

File tree

1 file changed

+8
-5
lines changed
  • packages/special-pages/pages/duckplayer/src/js

1 file changed

+8
-5
lines changed

packages/special-pages/pages/duckplayer/src/js/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,26 @@ const VideoPlayer = {
128128
/**
129129
* Fires whenever the video player iframe <title> changes (the video doesn't have the <title> set to
130130
* the video title until after the video has loaded...)
131-
* @param {Function} callback(title)
131+
* @param {(title: string) => void} callback
132132
*/
133133
onIframeTitleChange: (callback) => {
134134
const iframe = VideoPlayer.iframe()
135135

136+
if (iframe?.contentDocument?.title) {
137+
// eslint-disable-next-line n/no-callback-literal
138+
callback(iframe?.contentDocument?.title)
139+
}
136140
if (iframe?.contentWindow && iframe?.contentDocument) {
137-
const title = iframe.contentDocument.querySelector('title')
141+
const titleElem = iframe.contentDocument.querySelector('title')
138142

139-
if (title) {
143+
if (titleElem) {
140144
// @ts-expect-error - typescript known about MutationObserver in this context
141145
const observer = new iframe.contentWindow.MutationObserver(function (mutations) {
142146
mutations.forEach(function (mutation) {
143147
callback(mutation.target.textContent)
144148
})
145149
})
146-
observer.observe(title, { childList: true })
150+
observer.observe(titleElem, { childList: true })
147151
} else {
148152
// console.warn('could not access title in iframe')
149153
}
@@ -555,7 +559,6 @@ const PlayOnYouTube = {
555559
init: (opts) => {
556560
const validVideoId = Comms.getValidVideoId()
557561
const timestamp = Comms.getSanitizedTimestamp()
558-
console.log({ validVideoId })
559562

560563
if (validVideoId) {
561564
const url = new URL(opts.base)

0 commit comments

Comments
 (0)