Skip to content

Instantly share code, notes, and snippets.

@eldorplus
Forked from tetrashine/main.js
Created July 14, 2021 11:02
Show Gist options
  • Save eldorplus/8350d98caa49b279f12af086a83ffdd6 to your computer and use it in GitHub Desktop.
Save eldorplus/8350d98caa49b279f12af086a83ffdd6 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