视频播放时自动进入网页全屏,播放结束自动退出。
// ==UserScript== // @name 自研 - 哔哩哔哩 - 播放时自动网页全屏 // @name:en_US Self-made - BiliBili - Playing auto WebFull // @description 视频播放时自动进入网页全屏,播放结束自动退出。 // @description:en_US When the video plays, it automatically enters WebFull mode, and automatically exits this mode once the video concludes. // @version 1.1.1 // @author CPlayerCHN // @license MulanPSL-2.0 // @namespace https://www.gitlink.org.cn/CPlayerCHN // @match https://www.bilibili.com/video/* // @match https://www.bilibili.com/bangumi/play/* // @match https://www.bilibili.com/festival/* // @icon https://static.hdslb.com/images/favicon.ico // @run-at document-end // @noframes // ==/UserScript== (function() { 'use strict'; // 定义「网页标题」变量,「元素选择器」「body 元素含有类」函数。 let title = document.title; function $(elm) { return document.querySelector(elm); } function bodyClass(match = /player-mode-[web|full]/) { // 返回结果。 return match.test(document.body.className); } // 定义「元素监听」变量及其回调函数。 const observer = new MutationObserver(() => { // 定义「全屏按钮」变量。 const full = $(".bpx-player-ctrl-btn[aria-label=\"全屏\"]"); // 如果「全屏按钮」存在。 if(full) { // 定义「网页全屏按钮」「视频元素」变量。 const web = $(".bpx-player-ctrl-btn[aria-label=\"网页全屏\"]"), video = $("video"); // 如果播放器不是网页全屏或全屏状态,就网页全屏。 if(!bodyClass()) { web.click(); } // 等待 1 秒。 setTimeout(() => { // 如果是电影类视频且播放器是宽屏状态,就网页全屏。 if(/-电影-高清正版在线观看/.test(title) && bodyClass(/player-mode-wide/)) { web.click(); } }, 1000) // 监听视频播放。 $("video").addEventListener("playing", () => { // 如果「网页标题」和当前页面的不一致且播放器不是网页全屏或全屏状态,就更新「视频编号」变量后全屏。 if(title !== document.title && !bodyClass()) { title = document.title; web.click(); } }); // 监听视频暂停。 $("video").addEventListener("pause", () => { // 如果视频已经播放完成且播放模式不是自动切集。 if((video.duration - video.currentTime) <= 1 && !$(".bpx-player-ctrl-setting-handoff-content input").checked) { // 判断网播放器状态,如果视频网页全屏或全屏就退出它们。 if(bodyClass(/player-mode-full/)) { full.click(); }else if(bodyClass(/player-mode-web/)) { web.click(); } } }); // 中止「元素监听」。 observer.disconnect(); } }); // 配置「元素监听」需要监听的元素和参数。 observer.observe(document.body, { "childList": true, "subtree": true }); })();