Skip to content

Commit 6c46cf7

Browse files
committed
Dismiss on click
1 parent 17d3bac commit 6c46cf7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

injected/src/features/duckplayer-native/duckplayer-native.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ export function setupDuckPlayerForYouTube(selectors, playbackPaused, environment
123123
if (pause) {
124124
sideEffects.add('stopping video from playing', () => stopVideoFromPlaying(videoElement));
125125
sideEffects.add('appending thumbnail', () =>
126-
appendThumbnailOverlay(/** @type {HTMLElement} */ (targetElement), environment),
126+
appendThumbnailOverlay(/** @type {HTMLElement} */ (targetElement), environment, () => {
127+
sideEffects.destroy('stopping video from playing');
128+
sideEffects.destroy('appending thumbnail');
129+
}),
127130
);
128131
} else {
129132
sideEffects.destroy('stopping video from playing');

injected/src/features/duckplayer-native/overlays/thumbnail-overlay.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { VideoParams, appendImageAsBackground, Logger } from '../util';
99
*/
1010
export class DDGVideoThumbnailOverlay extends HTMLElement {
1111
static CUSTOM_TAG_NAME = 'ddg-video-thumbnail-overlay-mobile';
12+
static OVERLAY_CLICKED = 'overlay-clicked';
1213

1314
policy = createPolicy();
1415
/** @type {Logger} */
@@ -43,6 +44,14 @@ export class DDGVideoThumbnailOverlay extends HTMLElement {
4344
shadow.append(style, container);
4445
this.container = container;
4546

47+
// Add click event listener to the overlay
48+
const overlay = container.querySelector('.ddg-video-player-overlay');
49+
if (overlay) {
50+
overlay.addEventListener('click', () => {
51+
this.dispatchEvent(new Event(DDGVideoThumbnailOverlay.OVERLAY_CLICKED));
52+
});
53+
}
54+
4655
this.logger?.log('Created', DDGVideoThumbnailOverlay.CUSTOM_TAG_NAME, 'with container', container);
4756
this.appendThumbnail();
4857
}
@@ -79,8 +88,9 @@ export class DDGVideoThumbnailOverlay extends HTMLElement {
7988
*
8089
* @param {HTMLElement} targetElement
8190
* @param {import('../environment').Environment} environment
91+
* @param {() => void} [onClick] Optional callback to be called when the overlay is clicked
8292
*/
83-
export function appendThumbnailOverlay(targetElement, environment) {
93+
export function appendThumbnailOverlay(targetElement, environment, onClick) {
8494
const logger = new Logger({
8595
id: 'THUMBNAIL_OVERLAY',
8696
shouldLog: () => environment.isTestMode(),
@@ -93,6 +103,10 @@ export function appendThumbnailOverlay(targetElement, environment) {
93103
overlay.testMode = environment.isTestMode();
94104
overlay.href = environment.getPlayerPageHref();
95105

106+
if (onClick) {
107+
overlay.addEventListener(DDGVideoThumbnailOverlay.OVERLAY_CLICKED, onClick);
108+
}
109+
96110
targetElement.appendChild(overlay);
97111

98112
return () => {

0 commit comments

Comments
 (0)