Skip to content

Commit 4bc8d47

Browse files
committed
Ad detection behing remote config
1 parent 7185bab commit 4bc8d47

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

injected/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"devDependencies": {
3333
"@canvas/image-data": "^1.0.0",
34-
"@duckduckgo/privacy-configuration": "github:duckduckgo/privacy-configuration#ca6101bb972756a87a8960ffb3029f603052ea9d",
34+
"@duckduckgo/privacy-configuration": "github:duckduckgo/privacy-configuration#6e5774603200f453a9451870606f3921b76249f4",
3535
"@fingerprintjs/fingerprintjs": "^4.6.2",
3636
"@types/chrome": "^0.0.315",
3737
"@types/jasmine": "^5.1.7",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export function setupDuckPlayerForYouTube(selectors, playbackPaused, environment
143143
messages.notifyCurrentTimestamp(timestamp.toFixed(0));
144144
};
145145

146-
return pollTimestamp(300, handler);
146+
return pollTimestamp(300, handler, selectors);
147147
});
148148

149149
if (playbackPaused) {
@@ -190,7 +190,7 @@ export function setupDuckPlayerForNoCookie(selectors, environment, messages) {
190190
messages.notifyCurrentTimestamp(timestamp.toFixed(0));
191191
};
192192

193-
return pollTimestamp(300, handler);
193+
return pollTimestamp(300, handler, selectors);
194194
});
195195

196196
logger.log('Setting up error detection');

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1+
/** @import { DuckPlayerNativeSelectors } from './duckplayer-native.js'; */
2+
13
/**
4+
* @param {string} selector - Selector for the video element
25
* @returns {number}
36
*/
4-
export function getCurrentTimestamp() {
5-
const video = document.querySelector('video'); // TODO: Move to remote config
7+
export function getCurrentTimestamp(selector) {
8+
const video = /** @type {HTMLVideoElement|null} */ (document.querySelector(selector));
69
return video?.currentTime || 0;
710
}
811

9-
/**
10-
* @returns {boolean}
11-
*/
12-
function isShowingAd() {
13-
return !!document.querySelector('.html5-video-player.ad-showing'); // TODO: Move to remote config
14-
}
15-
1612
/**
1713
* Sends the timestamp to the browser every 300ms
1814
* TODO: Can we not brute force this?
@@ -22,19 +18,24 @@ function isShowingAd() {
2218
* TODO: Can we not brute force this?
2319
* @param {number} interval - Polling interval
2420
* @param {(number) => void} callback - Callback handler for polling event
21+
* @param {DuckPlayerNativeSelectors} selectors - Selectors for the player
2522
* @returns
2623
*/
27-
export function pollTimestamp(interval = 300, callback) {
28-
if (!callback) {
29-
console.error('Timestamp polling failed. No callback defined');
24+
export function pollTimestamp(interval = 300, callback, selectors) {
25+
if (!callback || !selectors) {
26+
console.error('Timestamp polling failed. No callback or selectors defined');
3027
}
3128

29+
const isShowingAd = () => {
30+
return selectors.adShowing && !!document.querySelector(selectors.adShowing);
31+
};
32+
3233
const timestampPolling = setInterval(() => {
3334
if (isShowingAd()) {
3435
console.log('Ad showing. Not polling timestamp');
3536
return;
3637
}
37-
const timestamp = getCurrentTimestamp();
38+
const timestamp = getCurrentTimestamp(selectors.videoElement);
3839
console.log('Polling timestamp', timestamp);
3940
callback(timestamp);
4041
}, interval);

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)