// ==UserScript== // @name Bilibili 自动切P // @namespace https://github.com/Tsuk1ko // @version 1.0.3 // @description 为什么要单独写个脚本呢?因为自动连播就是个傻逼…… // @author 神代綺凛 // @license GPL-3.0 // @match https://www.bilibili.com/video/* // @icon https://www.bilibili.com/favicon.ico // @grant unsafeWindow // @run-at document-start // @downloadURL none // ==/UserScript== (() => { 'use strict'; const PlayerEvent = { MEDIA_ENDED: 'MEDIA_ENDED', }; 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(PlayerEvent.MEDIA_ENDED, () => { const curP = get(win, ['__INITIAL_STATE__', 'p']); const totalP = get(win, ['__INITIAL_STATE__', 'videoData', 'videos']); if (curP < totalP) setTimeout(() => player.next(), 100); }); }; Object.defineProperty(win, 'player', { configurable: true, set: player => { delete win.player; win.player = player; initPlayer(); }, }); })();