Greasy Fork

halihali便携按钮

快速上一集下一集,快速跳到指定位,窗口化全屏功能,切源功能。

当前为 2021-12-21 提交的版本,查看 最新版本

// ==UserScript==
// @license      MIT
// @name         halihali便携按钮
// @namespace    哈哩哈哩快速操作按钮
// @description  快速上一集下一集,快速跳到指定位,窗口化全屏功能,切源功能。
// @version      1.1
// @author       You
// @match        http://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        unsafeWindow
// @grant        GM_setValue
// @grant        GM_addValueChangeListener


// ==/UserScript==

(function () {
    'use strict';

    //层key关键id
    // key: C1
    // key: C2
    // key: C3

    /*
       全自动流程 1.进入C2表示切换集数,自动全屏,自动跳片头,自动跳片尾

       1.层1-层2切换源 C1-C2.VideoResNext
       2.层1-层3跳片头 C1-C3.VdoProgressSet
       3.层3-层1自动下一集 C3-C1.NextVideo
       4.

    */




    console.log("0.标签↓.");

    let url = location.hostname;

    if(url.indexOf("hali") != -1){
        //------------------------------------C1-----------------------------------------------------------------------------
        if(document.querySelector("#player")){
            //主站外部框架
            console.log("1.哈哩哈哩播放器页面进入");

            let style = document.createElement("style");
            style.type = "text/css";
            let str = ``;
            //样式收缩
            if(true){
                str = `
            .MyFullscreen {
                position:fixed;
                top:0px;
                left:0px;
                z-index:9999;
                width:100%;
                height:100%;
            }
            .PlayerSettings{
                position:fixed;
                left:0;
                z-index:999999;
                top:50vh;
                transform: translate(0,-50%);
                background:rgba(0,0,0,0.8);
                width:72px;
                min-width:58px;
                min-height:260px;
                float:left;
                padding:14px;
                border-radius:10px;
                margin:2px;
                transition: all 0.2s;
            }
            .PlayerSettings>*{
                min-width:70px;
                min-height:30px;
                float:left;
            }
            .PlayerSettings>*+*{
                margin-left:0px;
            }
            .EditView{
                text-align:center;
                width:60px;
            }
            .Hide{
                opacity:0;
            }
            `;
            }

            style.innerHTML = str.split("\n").map(o => o.trim()).filter(o => o).join("");
            //console.log(style.innerHTML);
            document.head.appendChild(style);

            let layout = document.createElement("div");
            layout.className = "PlayerSettings";
            layout.classList.add("PlayerSettings", "Hide");
            document.body.appendChild(layout);
            layout.onmouseover = function () {
                layout.classList.remove("Hide");
            };
            layout.onmouseout = function () {
                layout.classList.add("Hide");
            };
            //上一集下一集
            let episodes = (add) => {
                localStorage.setItem("ifNextFullscreen", "true");

                let url = location.href;
                let index = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
                index = Number.parseInt(index) + add;
                url = url.substring(0, url.lastIndexOf("/") + 1) + index + url.substring(url.lastIndexOf("."));
                location.href = url;
            }
            //全屏按钮
            let fullscreens = () =>{
                localStorage.setItem("ifNextFullscreen", "false");
                let player = document.getElementById("player");
                player.classList.toggle("MyFullscreen", !player.classList.contains("MyFullscreen"));
            }
            //切换视频源
            let nextResVideo = () =>{
                GM_setValue("C1-C2.VideoResNext", URL.createObjectURL(new Blob()));//C1-C2.VideoResNext
            }
            //跳进度
            let progressVideo = (timme) =>{
                GM_setValue("C1-C3.VdoProgressSet", -1);//C1-C3.VdoProgressSet
                GM_setValue("C1-C3.VdoProgressSet", timme);//C1-C3.VdoProgressSet
            }


            //按钮界面收缩
            if(true){
                let items = [
                    {
                        label: "全屏",
                        click: () => {
                            fullscreens();
                        }
                    },
                    {
                        label: "上一集",
                        click: () => {
                            episodes(-1);
                        }
                    },
                    {
                        label: "下一集",
                        click: () => {
                            episodes(1);
                        }
                    },
                    {
                        label:"换源",
                        click:() => {
                            nextResVideo();
                        }
                    },
                    {
                        label:"progress"
                    },
                    {
                        label:"跳片头",
                        click:()=>{
                            let et = document.querySelector("#et_time").value;
                            let saveTime = (localStorage.getItem("headTime") == null) ? 100 : localStorage.getItem("headTime");
                            if(et != saveTime){
                                localStorage.setItem("headTime", et)
                            }
                            progressVideo(et);
                        }
                    },
                    {
                        label:"checkInput"
                    }
                ]

                items.forEach(item => {
                    if(item.label == "progress"){
                        let elEt = document.createElement("input");
                        elEt.className = "EditView";
                        elEt.id = "et_time";
                        elEt.value = (localStorage.getItem("headTime") == null) ? 100 : localStorage.getItem("headTime");
                        layout.appendChild(elEt);
                    }else if(item.label == "checkInput"){
                        let elCk = document.createElement("input");
                        elCk.type = "checkbox";
                        //elCk.textcontent = "全自动";
                        layout.appendChild(elCk);
                    }
                    else{
                        let el = document.createElement("button");
                        el.innerText = item.label;
                        el.addEventListener("click", item.click);
                        layout.appendChild(el);
                    }
                })
            }

            //下一集触发自动全屏
            if(localStorage.getItem("ifNextFullscreen") == "true"){
                fullscreens();
            }

            //自动切换下一集
            GM_addValueChangeListener("C3-C1.NextVideo", (name, oldValue, newValue, remote)=>{
                episodes(1);
            });

            return;
        }
        //End---------------------------------C1-----------------------------------------------------------------------------

    }
    else{;
         if(document.querySelector("#divplay")){
             //----------------------------------------------C2---------------------------------------------------------------
             document.querySelector("#playiframe").style.height = "100%";
             //二级播放器容器中间件
             console.log("2.播放器中间件");

             //视频源列表
             let playroad = document.querySelector("#playroad");
             if(playroad){
                 playroad.style.position = "absolute";
                 playroad.style.left = "0px";
                 playroad.style.top = "0px";
                 playroad.style.width = "100%";
                 playroad.style.opacity = "0";
                 playroad.onmouseover = function () {
                     this.style.opacity = "1";
                 };
                 playroad.onmouseout = function () {
                     this.style.opacity = "0";
                 };
             }else{
                 return;
             }

             //切换视频源
             GM_addValueChangeListener("C1-C2.VideoResNext", (name, oldValue, newValue, remote)=>{
                 console.log("换源按钮触发");
                 let resLists = document.getElementById("playroad");
                 //优先备用线2(判断是否优先使用)
                 let beiTag = false;
                 let useBei = true;//暂时先true
                 if(useBei){
                     resLists.childNodes.forEach(item => {
                         if(item.innerText == "备用线2" && item.style.color != "rgb(47, 179, 255)"){//未选中
                             item.click();
                             beiTag = true;
                         }
                     });
                     if(beiTag){
                         return;
                     }
                 }
                 //下一个源
                 resLists.childNodes.forEach(item => {
                     if(item.tagName == 'A'){
                         if(item.style.color == "rgb(47, 179, 255)"){//选中 蓝色
                             beiTag = true;
                         }else if(item.style.color == "rgb(170, 170, 170)" && beiTag){//灰色
                             beiTag = false;
                             item.click();
                         }else if(item.style.color == "rgb(255, 0, 0)" && beiTag){//红色
                             beiTag = false;
                             item.click();
                         }
                     }
                 });
             });
             return;
             //End-------------------------------------------C2---------------------------------------------------------------
         }

         //--------------------------------------------------------------C3---------------------------------------------------
         //a1:线1,2 video:线3,4  player1:备线1,2,线10
         if(document.querySelector('#a1') || document.querySelector("#player1") || document.querySelector("#video")){
             //播放器内层
             console.log("3.播放器层");

             //视频结束监听
             setTimeout(()=>{
                 document.querySelector('video').addEventListener("ended", ()=>{
                     //console.log("播放结束");
                     GM_setValue("C3-C1.NextVideo", URL.createObjectURL(new Blob()));
                 });
             },(document.querySelector('video')?"0":"8000"));//如果搜索不到,延迟搜索

             //视频快进
             GM_addValueChangeListener("C1-C3.VdoProgressSet", (name, oldValue, newValue, remote)=>{
                 //快进
                 let vdo = document.querySelector('video');
                 if(oldValue == "-1" && vdo){
                     vdo.muted = true;
                     vdo.play();
                     vdo.currentTime += +newValue;

                     //静音后处理
                     if(vdo.muted){
                         //添加解除静音按钮
                         let bd = document.querySelector('body');
                         let btnSound = document.querySelector('#soundBtn');
                         if(!btnSound){
                             let el = document.createElement("button");
                             el.id = "soundBtn";
                             el.style.position = "absolute";
                             el.style.width = "100%";
                             el.style.height = "100%";
                             el.style.bottom = "0px";
                             el.style.top = "0px";
                             el.style.left = "0px";
                             el.style.right = "0px";
                             el.style.color = "rgb(255,255,255)";
                             el.style.background = "rgba(0,0,0,0.5)";
                             el.innerText = "音量点击";
                             el.addEventListener("click", ()=>{
                                 document.querySelector('#soundBtn').remove();
                                 document.querySelector('video').muted = false;
                             });
                             bd.appendChild(el);
                         }
                     }
                 }
             });
             return;
         }
         //--------------------------------------------------------------C3---------------------------------------------------

         console.log("4.其他:" + url);
        }
})();