HTML5 embedded youtube videos

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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++;
      }
}