.M3U8 HLS support for HTML5 video

Lets you play fragmented Apple-style adaptive videos in browsers like Firefox, by making use of Media Source Extensions. No Flash needed.

目前為 2016-07-30 提交的版本,檢視 最新版本

// ==UserScript==
// @name        .M3U8 HLS support for HTML5 video
// @namespace   swyter
// @description Lets you play fragmented Apple-style adaptive videos in browsers like Firefox, by making use of Media Source Extensions. No Flash needed.
// @include     *
// @version     1
// @require     https://cdn.jsdelivr.net/hls.js/latest/hls.min.js
// @grant       none
// @run-at      document-start
// ==/UserScript==

/* makes use of DailyMotion's MSE-based HLS client:
   https://github.com/dailymotion/hls.js */

/* wait until the page is ready for the code snipped to run */
document.addEventListener('DOMContentLoaded', function()
{
  var hls_elements = document.querySelectorAll(`video[src*='.m3u8'], video > source[src*='.m3u8']`)
  
  if (hls_elements.length === 0)
    return;
  
  if (!Hls || !Hls.isSupported())
   return;

  // document.head.appendChild(
  //  ((script = document.createElement("script")).src=`https://cdn.jsdelivr.net/hls.js/latest/hls.min.js`) && script
  // )
  
  console.log(`[i] enabling M3U8 HLS shim user script on this page.`);

  for(i of hls_elements)
  {
    console.log(i, i.src);
    
    /* if the element is not visible, in typical JS kludge syntax */
    if (i.offsetParent === null)
      return;

    var hls = new Hls();
    
    hls.loadSource(i.src);
    hls.attachMedia((i.localName.toLowerCase() == "source" && i.parentElement || i));
  }
}, false);