Skip to content

Instantly share code, notes, and snippets.

@tetrashine
Last active July 14, 2021 11:02
Show Gist options
  • Save tetrashine/b86a3bb078582fbf730462b579fb6380 to your computer and use it in GitHub Desktop.
Save tetrashine/b86a3bb078582fbf730462b579fb6380 to your computer and use it in GitHub Desktop.
onVideoComplete
await this._page.evaluateOnNewDocument(() => {
let checkWatchTimeFunc = () => {
let currElem = document.getElementsByClassName('ytp-time-current'); //grab the element showing current play time
let maxElem = document.getElementsByClassName('ytp-time-duration'); //grab the element showing total play time
if (
currElem.length > 0 && maxElem.length > 0 //check if there are any such element
&& currElem[0].innerText === maxElem[0].innerText //compare the value between the 2 elements
) {
window.videoEnded(); //video ended, trigger event
} else {
setTimeout(checkWatchTimeFunc, 5000); //perform the same check 5 seconds later
}
};
checkWatchTimeFunc();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment