Greasy Fork

M站_哔咪动漫脚本

移除推广广告、播放窗口自动网页全屏、快捷键播放下一话

目前为 2024-12-05 提交的版本。查看 最新版本

// ==UserScript==
// @version     1.0
// @author      Feny
// @license     MIT
// @run-at      document-body
// @name        M站_哔咪动漫脚本
// @icon        http://www.bimiacg11.net/favicon.ico
// @description 移除推广广告、播放窗口自动网页全屏、快捷键播放下一话
// @namespace   http://tampermonkey.net/
// @match       *://www.bimiacg4.net/*
// @match       *://www.bimiacg5.net/*
// @match       *://www.bimiacg11.net/*
// @match       *://www.bimiacg12.net/*
// @match       *://*.bimiacg*.net/bangumi/*/play/*
// @require     https://cdnjs.cloudflare.com/ajax/libs/layui/2.9.3/layui.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.5/js.cookie.min.js
// ==/UserScript==
(function () {
    "use strict";

    const pathname = location.pathname
    if (pathname === "/" && jQuery) {
        $(".login-box").remove()
        $(".banner-box").parents(".newhd").remove()
        $(".nav-area").css("margin-bottom", "20px")
        return
    }
    let bimiacg = {
        video: null,
        // 获取播放器容器
        getVideo: function () {
            if (this.video) {
                return this.video;
            }

            this.video = $("iframe").contents().find("video").get(0);
            return this.video;
        },
        // 播放
        play: function (interval) {
            let video = this.video,
                isReload = Cookies.get('isReload')

            if (isReload && video.paused && video.duration > 0) {
                video.muted = true;
                video.play();
                clearInterval(interval);
                Cookies.remove("isReload");

                layer.alert(
                    "由于浏览器限制,需手动确认开启声音!!!",
                    function (index) {
                        video.muted = false;
                        layer.close(index);
                    }
                );
                console.log("哔咪哔咪自动播放成功!!!");
            }
        },
        autoPlay: function () {
            let i = 0,
                that = this,
                interval = setInterval(function () {
                    ++i;
                    if (i >= 5) {
                        clearInterval(interval);
                    }

                    if (that.getVideo()) {
                        that.play(interval);
                    }
                }, 1500);
        },
        keydownListener: function () {
            $(document).on("keydown", function (event) {
                // 播放上一话
                if (event.key === "[") {
                    document.querySelector(".play-qqun > .pre").click();
                }
                // 播放下一话
                if (event.key === "]") {
                    document.querySelector(".play-qqun > .next").click();
                }
            });
        },
        html5Settings: function () {
            localStorage.setItem(
                "html5Settings",
                JSON.stringify({
                    volume: 1,
                    opacity: 1,
                    scale: 1,
                    speed: 1,
                    commentVisible: true,
                    autoOpacity: false,
                    useCSS: false,
                    autoPlay: true,
                    defaultWide: true,
                    defaultFull: true,
                    playSpeed: 1,
                    recordPlaySpeed: false,
                    theme: "bilibili",
                    density: 0,
                })
            );
        },
        init: function () {
            // 移除推广
            $("#bkcl").hide();
            $(".tuiguang").hide();

            // 视频网页全屏
            $(".play-full").click();

            this.autoPlay();
            this.html5Settings();
            this.keydownListener();

            // 刷新时设置缓存
            $(window).on("beforeunload", function () {
                Cookies.set('isReload', true, { expires: 5000 })
            });
        },
    };

    document.addEventListener("DOMContentLoaded", () => bimiacg.init())
})();