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.

目前为 2015-10-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Replace old Flash Player-based YouTube embeds by their new HTML5 counterparts
  3. // @description Ideal if you don't have Flash Player installed in your device. I know I don't.
  4. // @namespace greasyfork.org/users/4813-swyter
  5. // @include *
  6. // @version 2015.10.18
  7. // @noframes
  8. // @grant none
  9. // @run-at document-start
  10. // @icon https://i.imgur.com/L2y0zMj.png
  11. // ==/UserScript==
  12.  
  13. /* wait until the page is ready for the code snipped to run */
  14. document.addEventListener('DOMContentLoaded', function()
  15. {
  16. /* iterate over all the existing SWF Youtube players in the page */
  17. for (var cur in (vids=document.querySelectorAll('object > embed[src*="youtube.com"]')))
  18. {
  19. console.log(vids[cur], typeof vids[cur]);
  20.  
  21. /* create the HTML5 player element */
  22. iframe = document.createElement('iframe');
  23. iframe.src = 'https://www.youtube.com/embed/' + vids[cur].src.split('?')[0].split('/')[4];
  24.  
  25. /* keep their same size */
  26. iframe.width = vids[cur].width;
  27. iframe.height = vids[cur].height;
  28.  
  29. /* no borders plz, thanks! */
  30. iframe.setAttribute("frameborder", 0);
  31.  
  32. /* replace the old SWF Flash object with it, voilà */
  33. vids[cur].parentNode.parentNode.replaceChild(iframe, vids[cur].parentNode);
  34. }
  35. }, false);