Last active
March 21, 2022 07:36
-
-
Save biuuu/5b675ec85d73542c53617a9561541cfb to your computer and use it in GitHub Desktop.
保持bilibili播放器宽屏模式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bilibili宽屏模式On | |
// @namespace https://gist.github.com/biuuu/ | |
// @match https://www.bilibili.com/* | |
// @grant none | |
// @version 1.3 | |
// @author biuuu | |
// @run-at document-end | |
// @description 保持bilibili播放器宽屏模式 | |
// ==/UserScript== | |
const obConfig = { | |
subtree: true, | |
childList: true | |
} | |
const wideContList = ['squirtle-video-widescreen', 'bilibili-player-video-btn-widescreen', 'bpx-player-ctrl-wide'] | |
const hasClass = (name) => { | |
for (let i = 0; i < wideContList.length; i++) { | |
if (name.includes(wideContList[i])) { | |
return true | |
} | |
} | |
return false | |
} | |
const mutationCallback = (mutationsList) => { | |
for (let mutation of mutationsList) { | |
const type = mutation.type | |
const addedNodes = mutation.addedNodes | |
if (type === 'childList' && addedNodes.length) { | |
addedNodes.forEach(node => { | |
if (node.className?.includes && hasClass(node.className)) { | |
node.querySelector('.squirtle-video-widescreen:not(.active) .squirtle-widescreen-inactive,.bilibili-player-iconfont-widescreen-off,.bpx-player-ctrl-wide-enter').click() | |
} | |
}) | |
} | |
} | |
} | |
const targetNode = document.getElementById('bilibili-player') | |
const observer = new MutationObserver(mutationCallback) | |
observer.observe(targetNode, obConfig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment