YT pause video on comment

Youtube video is paused if you have opened the url with link to comment

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name          YT pause video on comment
// @description   Youtube video is paused if you have opened the url with link to comment
// @author        MK
// @namespace     max44
// @homepage      https://greasyfork.org/en/users/309172-max44
// @match         *://*.youtube.com/*
// @match         *://*.youtu.be/*
// @icon          https://cdn.icon-icons.com/icons2/1488/PNG/512/5295-youtube-i_102568.png
// @version       1.0
// @license       MIT
// @require       https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @run-at        document-end
// ==/UserScript==

(function() {
  'use strict';

  var urlAtLastCheck = "";
  var divVideo0 = null;
  var divVideo1 = null;
  var waitVideo;

  //Check URL changes
  const rootCallback = function (mutationsList, observer) {
    if (urlAtLastCheck != document.location.href) {
      urlAtLastCheck = document.location.href;
      clearInterval(waitVideo);
      if (urlAtLastCheck.search("/watch?") > 0 && urlAtLastCheck.search("&lc=") > 0) {
        pauseVideo();
      }
    }
  }

  const rootNode = document.querySelector("body");
  if (rootNode != null) {
    const rootObserver = new MutationObserver(rootCallback);
    rootObserver.observe(rootNode, {childList: true, subtree: true, attributes: true, characterData: false});
  }

  function pauseVideo() {
    waitVideo = setInterval(function() {
      var vCount0 = 0;
      var vCount1 = 0;
      var i;

      divVideo0 = document.querySelectorAll("div.playing-mode video:not([paused-by-script])");
      if (divVideo0 != null) {
        for (i = 0; i < divVideo0.length; i++) {
          divVideo0[i].pause();
          divVideo0[i].setAttribute("paused-by-script", "i1");
          vCount0++;
        }
      }

      divVideo1 = document.querySelectorAll("div.playing-mode video[paused-by-script='i1']");
      if (divVideo1 != null) {
        for (i = 0; i < divVideo1.length; i++) {
          divVideo1[i].pause();
          vCount1++;
        }
      }

      if (vCount0 == 0 && vCount1 > 0) clearInterval(waitVideo);

    }, 100);
  }

})();