Skip to content

Instantly share code, notes, and snippets.

@biuuu
Last active March 21, 2022 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biuuu/5b675ec85d73542c53617a9561541cfb to your computer and use it in GitHub Desktop.
Save biuuu/5b675ec85d73542c53617a9561541cfb to your computer and use it in GitHub Desktop.
保持bilibili播放器宽屏模式
// ==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