Replace old Flash Player-based YouTube embeds by their new HTML5 counterparts

Ideal if you don't have Flash Player installed in your device. I know I don't.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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        Replace old Flash Player-based YouTube embeds by their new HTML5 counterparts
// @description Ideal if you don't have Flash Player installed in your device. I know I don't.
// @namespace   greasyfork.org/users/4813-swyter
// @include     *
// @version     2016.01.03
// @noframes
// @grant       none
// @run-at      document-start
// @icon        https://i.imgur.com/L2y0zMj.png
// ==/UserScript==

/* wait until the page is ready for the code snipped to run */
document.addEventListener('DOMContentLoaded', function()
{
  /* iterate over all the existing SWF Youtube players in the page */
  for (var cur in (vids=document.querySelectorAll('object > embed[src*="youtube"]')))
  {
    console.log(vids[cur], typeof vids[cur]);

    /* create the HTML5 player element */
    iframe = document.createElement('iframe');
    iframe.src = 'https://www.youtube.com/embed/' + vids[cur].src.split('?')[0].split('/')[4];

    /* keep their same size */
    iframe.width = vids[cur].width;
    iframe.height = vids[cur].height;

    /* no borders plz, thanks! */
    iframe.setAttribute("frameborder", 0);

    /* replace the old SWF Flash object with it, voilà */
    vids[cur].parentNode.parentNode.replaceChild(iframe, vids[cur].parentNode);
  }
}, false);