HTML5 embedded youtube videos

Changes the way of embedding youtube videos from old 'object' to new 'iframe'

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name           HTML5 embedded youtube videos
// @namespace      html5
// @description    Changes the way of embedding youtube videos from old 'object' to new 'iframe' 
// @include        *
// @author         original script by Mikhail Khvoinitsky in (2010 https://userscripts-mirror.org/scripts/show/82749 updated in 2020 to add https to remove mixed content error.
// @version        0.3
// ==/UserScript==  


var insertLink = 1;



var n = 0;
while (document.getElementsByTagName("object")[n] != undefined)
{
  
    var currentElement = document.getElementsByTagName("object")[n];
  
      if (currentElement.getElementsByTagName("embed")[0] == undefined){
      }

  
      if (currentElement.getElementsByTagName("embed")[0] != undefined)
      {  
      		if ((currentElement.getElementsByTagName("embed")[0].src.indexOf("http://youtube.com/") == 0) 
          || (currentElement.getElementsByTagName("embed")[0].src.indexOf("http://www.youtube-nocookie.com/") == 0))
    			{
            
              var newElement = document.createElement('iframe');
              newElement.setAttribute('class', 'youtube-player');
              newElement.setAttribute('width', currentElement.width);
              newElement.setAttribute('height', currentElement.height);
              
              var src = currentElement.getElementsByTagName("embed")[0].src;
              newElement.setAttribute('frameborder', '0');
              src = src.replace('.com/v/', '.com/embed/');
            	src = src.replace('http:', 'https:');
              src = src.split('&')[0];
              newElement.setAttribute('src', src);
              currentElement.parentNode.insertBefore(newElement, currentElement);
              if (insertLink == 1)
              {
                  var link = document.createElement('a');
                  link.setAttribute('href', 'https://www.youtube.com/watch?v=' + src.substring(src.lastIndexOf('/') + 1, src.length));
                  link.innerHTML = 'Watch this video on Youtube';
                  var br = document.createElement('br');
                  currentElement.parentNode.insertBefore(br, currentElement);
                  currentElement.parentNode.insertBefore(link, currentElement);
              }
              currentElement.parentNode.removeChild(currentElement);
              n--;
         }
         n++;
      }
}