Acfun-hls

Acfun跳转到M3U8地址,需配合Chrome浏览器的扩展HLS-Playback使用

目前為 2022-01-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Acfun-hls
// @namespace    https://greasyfork.org/zh-CN/users/135090
// @version      2.7.5
// @description  Acfun跳转到M3U8地址,需配合Chrome浏览器的扩展HLS-Playback使用
// @author       zwb83925462
// @match        https://www.acfun.cn/v/ac*
// @match        https://www.acfun.cn/player/*
// @match        https://live.acfun.cn/live/*
// @match        https://www.ixigua.com/1*
// @match        https://www.ixigua.com/2*
// @match        https://www.ixigua.com/3*
// @match        https://www.ixigua.com/4*
// @match        https://www.ixigua.com/5*
// @match        https://www.ixigua.com/6*
// @match        https://www.ixigua.com/7*
// @match        https://www.ixigua.com/8*
// @match        https://www.ixigua.com/9*
// @match        https://www.ixigua.com/pseries/*
// @grant        unsafeWindow
// @runat        document-body
// @license      CC
// @noframes
// ==/UserScript==
'use strict';
(function(){
    if (location.hostname == 'www.acfun.cn'){
        var acdata=JSON.parse(unsafeWindow.videoInfo.currentVideoInfo.ksPlayJson).adaptationSet[0].representation;
        if (location.pathname.indexOf("v")==1){document.querySelector("#movie-player").align="center";}
        acdata.forEach(function(item,r){
            var uhd =item.qualityLabel;
            var ddiv = document.createElement("a");
            ddiv.style.color="#11AA11";
            ddiv.style.font="caption";
            ddiv.style.margin="0 1em";
            ddiv.id="hls"+r;ddiv.href=item.url;
            ddiv.innerText="#"+uhd;ddiv.target="_blank";
            if (location.pathname.indexOf("v")==1){
                document.querySelector("#movie-player").appendChild(ddiv);
            }else{
                document.querySelector("#player").appendChild(ddiv);
            }
        });
    }

    if (location.hostname == 'live.acfun.cn') {
        var authorId=unsafeWindow.__INITIAL_STATE__.liveInfo.authorId;var name=unsafeWindow.__INITIAL_STATE__.liveInfo.user.name;
        var acPasstoken="ChVpbmZyYS5hY2Z1bi5wYXNzdG9rZW4SYPq6szbURMkl1rjYVWYoxN3SiGo3gs_5uv6KbOPbBdIgfRK0gFdliDWcsvpes4Yx5WqTQgXdexSAAUzvxvaDRKNFPoL-b9t00r9YbYQFxY5dxDmJiecrx9a-2WeI6IKq7xoSN2PwqgsJdiBuVus6b3PvnWKGIiDJgtT9QmC0fZmNFvvHleh4I43j8-tMX2UgdYVq83Lr7igFMAE";
        var xhr=new XMLHttpRequest();xhr.open("post", "https://api.kuaishouzt.com/rest/zt/live/web/startPlay?subBiz=mainApp&kpn=ACFUN_APP&kpf=OUTSIDE_IOS_H5&userId=18953298&"+document.cookie.split(";")[0]+"&acfun.midground.api_st="+acPasstoken);
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xhr.send("authorId="+authorId+"&pullStreamType=SINGLE_HLS");
        xhr.onreadystatechange=function(){if (xhr.readyState == 4 && xhr.status == 200) {
            var ajaxer=xhr.responseText;var datares=JSON.parse(ajaxer).data.videoPlayRes;
            var url=JSON.parse(datares).single_hls;
            var pp=document.createElement("a");
            pp.innerText=name;pp.title=url;
            pp.href=url;pp.target="_blank";pp.style.fontSize="2em";document.body.insertBefore(pp,document.body.firstChild);}};
    }
    if (location.hostname == 'www.ixigua.com'){
        var guid=unsafeWindow._SSR_HYDRATED_DATA.anyVideo.gidInformation.gid.length>0?unsafeWindow._SSR_HYDRATED_DATA.anyVideo.gidInformation.gid:(unsafeWindow._SSR_HYDRATED_DATA.anyVideo.gidInformation.episodeId.length>0?unsafeWindow._SSR_HYDRATED_DATA.anyVideo.gidInformation.episodeId:unsafeWindow._SSR_HYDRATED_DATA.anyVideo.gidInformation.packerData.episodeInfo.episodeId);
        var gidpath="/".concat(guid);
        if (gidpath.concat("/") == location.pathname ){location=gidpath;}
        if (gidpath !=location.pathname || location.search.length>0){location=gidpath;}else{
            setTimeout(function(){
                var pd=document.createElement("a");
                pd.innerText="嵌入式播放器";pd.href="/embed?group_id="+guid;
                pd.target="_self";pd.style.fontSize="1em";
                pd.style.margin="0 1em";
                if (document.querySelector(".videoTitle") != null){
                    document.querySelector(".videoTitle").appendChild(pd);
                }
                var pdata=unsafeWindow._SSR_HYDRATED_DATA.anyVideo.gidInformation.packerData;
                var video_url=null,vd="MP4";
                if (pdata.video == undefined){
                    vd=pdata.videoResource.normal.video_list.video_4==undefined?(pdata.videoResource.normal.video_list.video_3==undefined?(pdata.videoResource.normal.video_list.video_2==undefined?pdata.videoResource.normal.video_list.video_1.definition:pdata.videoResource.normal.video_list.video_2.definition):pdata.videoResource.normal.video_list.video_3.definition):pdata.videoResource.normal.video_list.video_4.definition;
                    video_url=pdata.videoResource.normal.video_list.video_4==undefined?(pdata.videoResource.normal.video_list.video_3==undefined?(pdata.videoResource.normal.video_list.video_2==undefined?pdata.videoResource.normal.video_list.video_1.main_url:pdata.videoResource.normal.video_list.video_2.main_url):pdata.videoResource.normal.video_list.video_3.main_url):pdata.videoResource.normal.video_list.video_4.main_url;
                }else{
                    vd=pdata.video.videoResource.normal.video_list.video_4==undefined?(pdata.video.videoResource.normal.video_list.video_3==undefined?(pdata.video.videoResource.normal.video_list.video_2==undefined?pdata.video.videoResource.normal.video_list.video_1.definition:pdata.video.videoResource.normal.video_list.video_2.definition):pdata.video.videoResource.normal.video_list.video_3.definition):pdata.video.videoResource.normal.video_list.video_4.definition;
                    video_url=pdata.video.videoResource.normal.video_list.video_4==undefined?(pdata.video.videoResource.normal.video_list.video_3==undefined?(pdata.video.videoResource.normal.video_list.video_2==undefined?pdata.video.videoResource.normal.video_list.video_1.main_url:pdata.video.videoResource.normal.video_list.video_2.main_url):pdata.video.videoResource.normal.video_list.video_3.main_url):pdata.video.videoResource.normal.video_list.video_4.main_url;
                }
                var videourl=(video_url==null)?"#":"https:"+video_url;
                var pp=document.createElement("a");
                pp.innerText=vd;pp.href=videourl;pp.target="_self";pp.style.fontSize="1em";pp.style.margin="0 2em";pp.style.color="#22AA11";
                if (document.querySelector(".videoTitle") != null){
                    document.querySelector(".videoTitle").appendChild(pp);
                } else if (document.querySelector(".teleplayPage__main") != null){
                    document.querySelector(".teleplayPage__main").appendChild(pp);
                } else {
                    document.querySelector(".siteHeader").appendChild(pp);
                }
            },2000);
        }
    }
})();