// ==UserScript==
// @name         Remove Facebook Play Next Popup
// @description  Removes the annoying UP NEXT popup from Facebook videos and cancels the next video play automatically.
// @version      0.1.1
// @author       Ariel Jannai
// @namespace    https://github.com/arieljannai/tampermonkey-scripts
// @supportURL   https://github.com/arieljannai/tampermonkey-scripts/issues
// @updateURL    https://github.com/arieljannai/tampermonkey-scripts/raw/master/facebook/remove-upnext-popup-cancel-next.user.js
// @downloadURL  https://github.com/arieljannai/tampermonkey-scripts/raw/master/facebook/remove-upnext-popup-cancel-next.user.js
// @match        https://www.facebook.com/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @grant        none
// @license      MIT
// ==/UserScript==

'use strict';

var videoPageIntervalID = 0;
var waitingForPopup = false;
var currLocation = '';

(function() {
    videoPageIntervalID = window.setInterval(onVideoPage, 1000);
})();

function waitForUpNextToDisaply() {
    var selector = $("div:contains('UP NEXT')").eq(-8)
    if(selector.length === 1) {
        // remove the popup and cancel the play next
        selector.remove();
        console.log('popup removed!');
        waitingForPopup = false;
        return;
    }
    else {
        setTimeout(function() {
            // console.log('waiting..');
            waitingForPopup = true;
            if (location.href.contains("/videos/")) {
                waitForUpNextToDisaply();
            } else {
                waitingForPopup = false;
            }
        }, 500);
    }
}

function onVideoPage() {
    if (location.href.contains("/videos/") && !waitingForPopup && location.href != currLocation ) {
        console.log('arrived to video page: ', location.href);
        currLocation = location.href;
        waitForUpNextToDisaply();
    }
}

@@ -201,17 +201,17 @@
     0.1.
-1
+5
 %0A// @aut

version bump 0.1.5