dilidili flash to html5

把dilidili的Flash播放器替换为HTML5播放器

目前為 2019-01-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         dilidili flash to html5
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  把dilidili的Flash播放器替换为HTML5播放器
// @author       Hugo16
// @match        http://www.dilidili.wang/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // 引用js和css
    let jsSrc = document.createElement("script");
    jsSrc.src = "https://vjs.zencdn.net/7.4.1/video.js";
    document.head.appendChild(jsSrc);
    let jsSrc1 = document.createElement("script");
    jsSrc1.src = "https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js";
    document.head.appendChild(jsSrc1);
    let cssSrc = document.createElement("link");
    cssSrc.rel = "stylesheet";
    cssSrc.href = 'https://vjs.zencdn.net/7.0.0/video-js.css';
    document.head.appendChild(cssSrc);
    // 稍微改下样式
    let newStyle = document.createElement("style");
    newStyle.innerText = ".video-js .vjs-big-play-button {top: 50%;left: 50%;transform: translate(-50%,-50%);}";
    document.head.appendChild(newStyle);

    // 找到原播放器
    let originalVideoWrap = document.getElementsByClassName("player_main");

    if (originalVideoWrap) {

        // 获取视频地址
        let videoSrc = originalVideoWrap[0].children[0].attributes["src"].value;
        videoSrc = videoSrc.split("=")[1];

        // 不是m3u8的就不改
        if (videoSrc.slice(-4) != "m3u8") {
            return;
        }

        // 新的video
        let newVideo = document.createElement("video");
        newVideo.setAttribute("id", "newVideo");
        newVideo.width = originalVideoWrap[0].clientWidth;
        newVideo.height = originalVideoWrap[0].clientHeight;
        newVideo.className = "video-js vjs-default-skin";
        newVideo.setAttribute("controls", true);

        let newSource = document.createElement("source");
        newSource.src = videoSrc
        newSource.setAttribute("type", "application/x-mpegURL");
        newVideo.appendChild(newSource);

        // 替换播放器
        originalVideoWrap[0].replaceChild(newVideo, originalVideoWrap[0].children[0]);

        // js加载完毕后运行播放器
        jsSrc.onload = function () {
            let player = videojs('newVideo');
            player.play();
        }
    }
})();