-
-
Save eldorplus/8350d98caa49b279f12af086a83ffdd6 to your computer and use it in GitHub Desktop.
onVideoComplete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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