哔哩哔哩bilibili辅助脚本解析大会员

解析大会员视频,播放页去广告,自动最高画质(根据是否为大会员,然后选择对应的最高画质),默认1.5倍速(可选),自动发送弹幕(可选),自定义弹幕内容,自动展开简介,自动开启弹幕,移除顶部的下载app选项等。

// ==UserScript==
// @name         哔哩哔哩bilibili辅助脚本解析大会员
// @namespace    zzy,q82664730
// @version      7.5
// @description  解析大会员视频,播放页去广告,自动最高画质(根据是否为大会员,然后选择对应的最高画质),默认1.5倍速(可选),自动发送弹幕(可选),自定义弹幕内容,自动展开简介,自动开启弹幕,移除顶部的下载app选项等。
// @author       zzy
// @match        https://www.bilibili.com/video/*
// @match        https://www.bilibili.com/bangumi/*
// @match        https://vip.parwix.com:4433/*
// @match        https://z1.m1907.cn/*
// @match        https://api.yueliangjx.com/*
// @match        https://showxi.xyz/*
// @match        https://okjx.cc/*
// @match        https://www.cuan.la/*
// @match        https://www.mtosz.com/*
// @icon         https://www.google.com/s2/favicons?domain=baidu.com
// @grant        none
// ==/UserScript==
 
(function() {
  //'use strict';
  window.onload = function(){
      document.body.insertAdjacentHTML("afterEnd",`  <div id="fcd" style="z-index:9999999;padding-left:15px;position: fixed; top: 5px; right: 5px;background-color:rgba(0,182,239,1);width: 400px; height: 330px;">
        <span style="line-height:30px;">是否为大会员:<input type="checkbox" id="isVip" /></span><br>
        <span style="line-height:30px;">是否去广告及其它:<input type="checkbox" id="isAd" /></span><br>
        <span style="line-height:30px;">是否自动开启弹幕:<input type="checkbox" id="isDm" /></span><br>
        <span style="line-height:30px;">是否自动展开详情:<input type="checkbox" id="isXq" /></span><br>
        <span style="line-height:30px;">是否开启最高画质:<input type="checkbox" id="isZg" /></span><br>
        <span style="line-height:30px;">
          播放速度:
          <input type="radio" name="speed" class="sprd" value="2.0"/>2.0
          <input type="radio" name="speed" class="sprd" value="1.5"/>1.5
          <input type="radio" name="speed" class="sprd" value="1.25"/>1.25
          <input type="radio" name="speed" class="sprd" value="1.0"/>1.0
          <input type="radio" name="speed" class="sprd" value="0.75"/>0.75
          <input type="radio" name="speed" class="sprd" value="0.5"/>0.5
        </span><br>
        <span style="line-height:30px;">是否自动发送弹幕:<input type="checkbox" id="isAutoSend" /></span><br>
        <span style="line-height:30px;">弹幕内容:<input type="text" id="dmNr" placeholder="不填默认发送:‘打卡’" /></span><br>
        <span style="line-height:30px;">自动发送弹幕间隔:<input type="number" id="asjg" style="width:45px;" />&nbsp;秒</span><br>
        <div style="text-align: center; margin-top:10px;">
          <button style="height: 30px; width: 50px; border-radius:5px;" id="save">保存</button>
          <button style="height: 30px; width: 50px; margin-left:40px; border-radius:5px;" id="close">关闭</button>
          <button style="height: 30px; width: 50px; margin-left:40px; border-radius:5px;" id="narrow">缩小</button>
          <button style="height: 30px; width: 100px; margin-left:40px; border-radius:5px;" id="longclose">以后不再显示</button>
        </div>
        <div style="text-align:right;">
            <span style="color:red;font-size:1.0em">@zzy</span>
        </div>
      </div>
      <div id="cd" style="z-index:9999999;position: fixed; top: 5px; right: 5px; color: white;text-align: center;cursor: pointer; border-radius: 50%;width: 22px;height: 22px; background-color:rgb(252, 157, 154);font-weight: bolder;">
        <span style="line-height:22px;">B</span></div>
      `);
  function loadF(){
    if(localStorage.getItem("isAd") == null){
      alert("初次使用请先配置脚本,配置好后点击保存即可!")
    }else{
      if(localStorage.getItem("isZg") == "true"){
        document.getElementById("isZg").checked = true;
      }else{
        document.getElementById("isZg").checked = false;
      }
      if(localStorage.getItem("speedIndex")){
        document.getElementsByClassName("sprd")[parseInt(localStorage.getItem("speedIndex"))].checked = true;
      }
      if(localStorage.getItem("isAd") == "true"){
        document.getElementById("isAd").checked = true;
      }else{
        document.getElementById("isAd").checked = false;
      }
      if(localStorage.getItem("isDm") == "true"){
        document.getElementById("isDm").checked = true;
      }else{
        document.getElementById("isDm").checked = false;
      }
      if(localStorage.getItem("isXq") == "true"){
        document.getElementById("isXq").checked = true;
      }else{
        document.getElementById("isXq").checked = false;
      }
      if(localStorage.getItem("isAutoSend") == "true"){
        document.getElementById("isAutoSend").checked = true;
      }else{
        document.getElementById("isAutoSend").checked = false;
      }
      if(localStorage.getItem("jtime")){
        document.getElementById("asjg").value = parseInt(localStorage.getItem("jtime") / 1000);
      }
      function firstS(){
        document.getElementById("save").click();
      }
      setTimeout(firstS,3000);
    }
    if(localStorage.getItem("isShow") == "haha"){
      document.getElementById("fcd").style.display = "none";
    }
    document.getElementById("save").onmouseover = function(){
      this.style.background = "rgb(0,182,239)"
      this.style.border = "1px solid red"
    }
    document.getElementById("save").onmouseout = function(){
      this.style.background = ""
      this.style.border = ""
    }
    document.getElementById("close").onmouseover = function(){
      this.style.background = "rgb(0,182,239)"
      this.style.border = "1px solid red"
    }
    document.getElementById("close").onmouseout = function(){
      this.style.background = ""
      this.style.border = ""
    }
    document.getElementById("longclose").onmouseover = function(){
      this.style.background = "rgb(0,182,239)"
      this.style.border = "1px solid red"
    }
    document.getElementById("longclose").onmouseout = function(){
      this.style.background = ""
      this.style.border = ""
    }
    document.getElementById("narrow").onmouseover = function(){
      this.style.background = "rgb(0,182,239)"
      this.style.border = "1px solid red"
    }
    document.getElementById("narrow").onmouseout = function(){
      this.style.background = ""
      this.style.border = ""
    }
    if(localStorage.getItem("isSx") == "yes"){
      document.getElementById("fcd").style.display = "none";
      document.getElementById("cd").style.display = "block";
    }
    document.getElementById("save").onclick = function(){
      if(document.getElementById("asjg").value < 10 || !document.getElementById("asjg").value){
        alert("自动发送弹幕间隔必须大于10!")
      }else{
        //开启最高画质
        localStorage.setItem("asjg",document.getElementById("asjg").value);
        if(document.getElementById("isZg").checked){
          localStorage.setItem("isZg",document.getElementById("isZg").checked);
          var isVip = document.getElementById("isVip").checked;
          var hz = document.getElementsByClassName("bui-select-item");
          if(isVip){
            hz[0].click();
          }else{
            for(let i=0;i<hz.length;i++){
              if(hz[i].innerHTML.indexOf("大会员") == -1){
                hz[i].click();
                break;
              }
            }
          }
        }else{
          localStorage.setItem("isZg",document.getElementById("iszg").checked);
        }
        //播放速度
        var spradio=document.getElementsByClassName("sprd");
        var speed=null;   
        for(var i=0;i<spradio.length;i++){
          if(spradio[i].checked==true) {
            localStorage.setItem("speedIndex",i);
            if(document.getElementsByClassName("bilibili-player-video-btn-speed-menu-list").length>0){
              document.getElementsByClassName("bilibili-player-video-btn-speed-menu-list")[i].click();
            }else if(document.getElementsByClassName("squirtle-select-item").length>0){
              document.getElementsByClassName("squirtle-select-item")[i].click();
            }
          }
        }
        //去广告
        function quAd(){
          isAd = document.getElementById("isAd").checked;
          localStorage.setItem("isAd",isAd);
          if(isAd){
            if(document.getElementById("bannerAd")){
              document.getElementById("bannerAd").remove();
            }
            if(document.getElementById("activity_vote")){
                document.getElementById("activity_vote").remove();
            }
            if(document.getElementsByClassName("ad-report")){
              document.getElementsByClassName("ad-report").forEach(function(item){
                item.remove();
              });
            }
            if(document.getElementsByClassName("video-page-special-card")){
              document.getElementsByClassName("video-page-special-card").forEach(function(item){
                item.remove();
              });
            }
            function deAd(){
              if(document.getElementById("slide_ad")){
                document.getElementById("slide_ad").remove();
              }
            }
            setTimeout(deAd,3000);
          }
        }
        setTimeout(quAd,4000);
        //自动开启弹幕
        function auDm(){
          var isDm = document.getElementById("isDm").checked;
          localStorage.setItem("isDm",isDm);
          var ev = new Event('mouseover', {
              bubbles: false, // 默认值false, 事件是否冒泡
              cancelable: false,  // 默认值false, 事件能否被取消
              composed: false  // 默认值false, 事件是否会在影子DOM根节点之外触发侦听器。
          });
          if(document.getElementsByClassName("bilibili-player-video-danmaku-switch").length>0){
            document.getElementsByClassName("bilibili-player-video-danmaku-switch")[0].dispatchEvent(ev);
          }else{
            document.getElementsByClassName("bpx-player-dm-switch")[0].dispatchEvent(ev);
          }
          
          if(isDm){
            document.getElementsByClassName("nav-link-item")[document.getElementsByClassName("nav-link-item").length-1].remove();
            if(document.querySelector("span.choose_danmaku").innerText == "开启弹幕"){
              document.getElementsByClassName("bui-switch-input")[0].click();
            }
          }
        }
        setTimeout(auDm,8000);
        //展开详情
        function zkXq(){
          var isXq = document.getElementById("isXq").checked;
          localStorage.setItem("isXq",isXq);
          if(isXq){
            
            if(document.getElementsByClassName("desc-info").length>0){
              if(document.getElementsByClassName("desc-info")[0].getAttribute('class').indexOf('open') < 0){
                document.getElementsByClassName("toggle-btn")[0].click()
              }
            }else{
              if(document.querySelector("a.media-desc i").innerText = "展开"){
                document.querySelector("a.media-desc i").click()
              }
            }
          }
        }
        setTimeout(zkXq,4000);
        var autoSend = document.getElementById("isAutoSend").checked;
        localStorage.setItem("isAutoSend",autoSend);
        var jtime = parseInt(document.getElementById("asjg").value) * 1000;
        localStorage.setItem("jtime",jtime);
        console.log(jtime);
        console.log(3);
        if(autoSend){
          setInterval(function () {
            var ev = new Event('input', { bubbles: true});
            ev.simulated = true;
            if(document.getElementById("dmNr").value.length > 0){
              document.getElementsByClassName("bilibili-player-video-danmaku-input")[0].value=document.getElementById("dmNr").value;
            }else{
              document.getElementsByClassName("bilibili-player-video-danmaku-input")[0].value="打卡";
            }
            document.getElementsByClassName("bilibili-player-video-danmaku-input")[0].dispatchEvent(ev);
            document.getElementsByClassName("bilibili-player-video-btn-send")[0].click();
          }, jtime);
        }
        function gbFcd(){
          document.getElementById("fcd").style.display = "none";
          document.getElementById("cd").style.display = "block"
          localStorage.setItem("isSx","yes");
        }
        setTimeout(gbFcd,1500);
      }
    }
    document.getElementById("cd").onclick = function(){
      document.getElementById("fcd").style.display = "block";
      this.style.display = "none";
    }
    document.getElementById("close").onclick = function(){
      document.getElementById("fcd").style.display = "none";
      document.getElementById("cd").style.display = "none";
    }
    document.getElementById("longclose").onclick = function(){
      localStorage.setItem("isShow","haha");
    }
    document.getElementById("narrow").onclick = function(){
      document.getElementById("fcd").style.display = "none";
      document.getElementById("cd").style.display = "block";
    }
  }
  setTimeout(loadF,2000);
  function addDiv(){
    var div = document.createElement("div");
    div.innerHTML = "解";
    var css = "position:fixed;top:30px;right:5px;z-index:999999999;line-height:22px;color: white;text-align: center;cursor: pointer;border-radius: 50%;width: 22px;height: 22px;background-color: rgb(252, 157, 154);font-weight: bolder;display: block;";
    div.style.cssText = css;
    div.title = "点击解析此视频!";
    if(window.self === window.top){ document.body.appendChild(div);}
    if(window.location.href.search("bilibili")!=-1){
        div.addEventListener("click",function(){
            let url = window.location.href;
            url = url.replace(url,'https://vip.parwix.com:4433/player/?url='+url);
            window.open(url, "_blank");});
    }else{
        div.addEventListener("click",function(){
            let url = window.location.href;
            url = url.replace(url,'https://vip.bljiex.com/?v='+url);
            window.open(url, "_blank");});
    }
  }
  addDiv();
}
})();