Ignore "Video Paused, continue watching?" using XPath

This script will click on "YES" button

  1. // ==UserScript==
  2. // @name Ignore "Video Paused, continue watching?" using XPath
  3. // @version 24.10.27
  4. // @description This script will click on "YES" button
  5. // @author 8TM (https://github.com/8tm/youtube_video_paused_continue_watching)
  6. // @match https://youtube.com/*
  7. // @match https://www.youtube.com/*
  8. // @match http://youtube.com/*
  9. // @match http://www.youtube.com/*
  10. // @compatible firefox Works with Firefox and Tampermonkey
  11. // @grant none
  12. // @namespace https://greasyfork.org/users/1386567
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. setInterval(() => {
  17. // Find "YES" button using XPath
  18. let xpath = "//div[@id='main']//div[contains(@class, 'buttons')]//yt-button-renderer[@id='confirm-button']//button";
  19. let result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  20. let confirmButton = result.singleNodeValue;
  21.  
  22. if (confirmButton && confirmButton.offsetParent !== null && !confirmButton.disabled) {
  23. confirmButton.click();
  24.  
  25. // Debug:
  26. // let currentDateTime = new Date();
  27. // let formattedDateTime = currentDateTime.toLocaleString();
  28. // console.log(`[${formattedDateTime}] Pushed 'YES' button.`);
  29. // alert(`[${formattedDateTime}] Pushed 'YES' button.`);
  30.  
  31. }
  32. },500);
  33. })();