Skip to content

Commit c87d328

Browse files
committed
Handle delayed video thumbnail loading
Nebula has started to only render the thumbnail when it is visible. Due to that, the "watch later" button was not correctly added to all videos, as this was only done immediately on loading of the videos. Using a different selector allows to handle this gracefully
1 parent 59ae961 commit c87d328

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/scripts/content/nebula/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ const setStyles = () => {
112112
};
113113

114114
const doVideoActions = debounce(() => {
115+
console.dev.debug('Video actions');
115116
// add links on mobile to substitute hover
116117
if (isMobile())
117-
Array.from(document.querySelectorAll<HTMLImageElement>(`${videoselector} img`)).forEach(createLink);
118+
Array.from(document.querySelectorAll<HTMLTimeElement>(`${videoselector} time`)).forEach(createLink);
118119
// hide creators
119120
if (isVideoListPage())
120121
Array.from(document.querySelectorAll<HTMLElement>(videoselector)).forEach(el =>
@@ -136,7 +137,7 @@ const hover = (e: MouseEvent) => {
136137
return;
137138
createLink(link.querySelector('img'));
138139
};
139-
const createLink = (img: HTMLImageElement): void => {
140+
const createLink = (img: HTMLImageElement | HTMLTimeElement): void => {
140141
if (!img || queueBottonLocation(img).querySelector('.enhancer-queueButton') !== null)
141142
return; // queue button exists
142143
// create queue button

src/scripts/helpers/locations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { isVideoListPage } from './shared';
22

3-
export const queueBottonLocation = (img: HTMLImageElement) => img.parentElement.parentElement;
4-
export const durationLocation = (img: HTMLImageElement) => queueBottonLocation(img).querySelector('time').parentElement;
5-
export const watchLaterLocation = (img: HTMLImageElement) => queueBottonLocation(img).querySelector('[data-icon-itself]');
3+
export const queueBottonLocation = (img: HTMLImageElement | HTMLTimeElement) => img.parentElement.parentElement;
4+
export const durationLocation = (img: HTMLImageElement | HTMLTimeElement) => queueBottonLocation(img).querySelector('time').parentElement;
5+
export const watchLaterLocation = (img: HTMLImageElement | HTMLTimeElement) => queueBottonLocation(img).querySelector('[data-icon-itself]');
66
export const titleLocation = (link: HTMLElement) => link.nextElementSibling ? link.nextElementSibling.querySelector('h3') : link.parentElement.nextElementSibling.querySelector('a[href^="/videos/"] span:last-child');
77
export const creatorLocation = (link: HTMLElement) => isVideoListPage() && link.nextElementSibling ? titleLocation(link).nextElementSibling.firstElementChild : document.querySelector('h1, meta[property="og:title"]');
88
export const watchProgressLocation = (link: HTMLElement) => link.querySelector('picture')?.parentElement?.lastElementChild as HTMLDivElement;

0 commit comments

Comments
 (0)