congdantoancau

FACEBOOK STOP UPNEXT VIDEO AUTOPLAY

Aug 15th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.62 KB | None | 0 0
  1. /* FACEBOOK STOP UPNEXT VIDEO AUTOPLAY */
  2. // https://webapps.stackexchange.com/questions/116656/disable-facebook-up-next-popup-and-next-video-play
  3. 'use strict';
  4.  
  5. var videoPageIntervalID = 0;
  6. var waitingForPopup = false;
  7. var currLocation = '';
  8.  
  9. (function() {
  10.     videoPageIntervalID = window.setInterval(onVideoPage, 1000);
  11. })();
  12.  
  13. function waitForUpNextToDisaply() {
  14.     var selector = $("div:contains('UP NEXT')").eq(-8)
  15.     if(selector.length === 1) {
  16.         // remove the popup and cancel the play next
  17.         //selector.remove();
  18.         $("span:contains('Cancel')").click();
  19.         console.log('popup removed!');
  20.         waitingForPopup = false;
  21.         return;
  22.     }
  23.     else {
  24.         setTimeout(function() {
  25.             // console.log('waiting..');
  26.             waitingForPopup = true;
  27.             if (location.href.indexOf("/videos/") != -1) {
  28.                 waitForUpNextToDisaply();
  29.             } else {
  30.                 waitingForPopup = false;
  31.             }
  32.         }, 500);
  33.     }
  34. }
  35.  
  36. function onVideoPage() {
  37.     if (location.href.indexOf("/videos/") != -1 && !waitingForPopup && location.href != currLocation ) {
  38.         console.log('arrived to video page: ', location.href);
  39.         currLocation = location.href;
  40.         waitForUpNextToDisaply();
  41.     }
  42. }
  43.  
  44. /* Jquery video end event
  45. * Source: https://stackoverflow.com/questions/14517639/executing-function-at-end-of-html5-video
  46. */
  47. setTimeout(setEndVideo, 5000);
  48.  
  49. function setEndVideo() {
  50.  
  51.     var vid = document.getElementById('u_1_6');
  52.     //console.log(vid);
  53.     if (vid) {
  54.         vid.onended = function(event) {
  55.             this.currentTime = 0;
  56.         };
  57.     }
  58. }
  59.  
  60.  
Add Comment
Please, Sign In to add comment