Greasy Fork

Greasy Fork is available in English.

.M3U8 HLS Player

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

当前为 2018-04-17 提交的版本,查看 最新版本

// ==UserScript==
// @name        .M3U8 HLS Player
// @namespace   http://greasyfork.icu/zh-CN/users/7232-andy-wong
// @description Lets you play fragmented Apple-style adaptive videos in browsers like Firefox, by making use of Media Source Extensions. No Flash needed.
// @include     http://*.chimeiju.com*
// @version     1
// @require     https://cdn.jsdelivr.net/npm/hls.js@latest
// @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 */
window.addEventListener('load', function()
{
  var hls_elements = document.querySelectorAll(`video[src*='.m3u8'], video > source[src*='.m3u8'],div[name='playurl']`);

  if (hls_elements.length === 0 || !Hls || !Hls.isSupported())
   return;

  console.log(`enabling M3U8 HLS shim user script on this page.`);

  for(let ele of hls_elements)
  {
    var video_elem = ele.localName.toLowerCase() == "source" && ele.parentElement || ele;

    /* if the element is not visible, in typical JS kludge syntax */
    var url;
    if (`offsetParent` in video_elem && video_elem.offsetParent === null){
      url=ele.getAttribute("value");
        //continue;
    }else{
      url=ele.src;
    }
    //获取
    if(url) {
        var hostname = window.location.hostname
		var port = window.location.port || '80';
		var m3u8Url = 'http://' + hostname + ':' + port + url.substring(25);
        document.getElementById('a1').innerHTML='<video id="video1" controls="controls" style="width:100%; height:100%"></video>';
        var video1 = document.getElementById('video1');
        m3u8Url = decodeURIComponent(m3u8Url);
      console.log(url,m3u8Url,video1);
      var hls = new Hls();
      hls.loadSource(m3u8Url);
      hls.attachMedia(video1);
      hls.on(Hls.Events.MANIFEST_PARSED,function() {
          video1.play();
      });
    }
  }
}, false);