Bilibili 自动切P

为什么要单独写个脚本呢?因为自动连播就是个傻逼……

目前為 2021-09-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Bilibili 自动切P
// @namespace    https://github.com/Tsuk1ko
// @version      1.0.1
// @description  为什么要单独写个脚本呢?因为自动连播就是个傻逼……
// @author       神代綺凛
// @match        https://www.bilibili.com/video/*
// @icon         https://www.bilibili.com/favicon.ico
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(() => {
    'use strict';

    const PLAYER_EVENT = {
        VIDEO_MEDIA_ENDED: 'video_media_ended',
        VIDEO_DESTROY: 'video_destroy',
    };

    const win = typeof unsafeWindow === 'undefined' ? window : unsafeWindow;

    const get = (obj, paths) => paths.reduce((prev, path) => (typeof prev === 'undefined' ? undefined : prev[path]), obj);

    const initPlayer = () => {
        const { player } = win;
        if (!player) return;
        player.on(PLAYER_EVENT.VIDEO_MEDIA_ENDED, () => {
            if (get(win, ['__INITIAL_STATE__', 'p']) < get(win, ['__INITIAL_STATE__', 'videoData', 'videos'])) {
                player.next();
            }
        });
        player.on(PLAYER_EVENT.VIDEO_DESTROY, () => {
            setTimeout(initPlayer);
        });
    };

    Object.defineProperty(win, 'player', {
        configurable: true,
        set: player => {
            delete win.player;
            win.player = player;
            initPlayer();
        },
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址