Skip to content

Commit 8a1feac

Browse files
committed
Ad detection logic
1 parent de9f22b commit 8a1feac

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

injected/src/features/duckplayer-native/get-current-timestamp.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
* @returns {number}
33
*/
44
export function getCurrentTimestamp() {
5-
const video = document.querySelector('video');
5+
const video = document.querySelector('video'); // TODO: Move to remote config
66
return video?.currentTime || 0;
77
}
88

9+
/**
10+
* @returns {boolean}
11+
*/
12+
function isShowingAd() {
13+
return !!document.querySelector('.html5-video-player.ad-showing'); // TODO: Move to remote config
14+
}
15+
916
/**
1017
* Sends the timestamp to the browser every 300ms
1118
* TODO: Can we not brute force this?
@@ -23,7 +30,12 @@ export function pollTimestamp(interval = 300, callback) {
2330
}
2431

2532
const timestampPolling = setInterval(() => {
33+
if (isShowingAd()) {
34+
console.log('Ad showing. Not polling timestamp');
35+
return;
36+
}
2637
const timestamp = getCurrentTimestamp();
38+
console.log('Polling timestamp', timestamp);
2739
callback(timestamp);
2840
}, interval);
2941

0 commit comments

Comments
 (0)