
画中画功能还是很好用的,可以上班的时候摸鱼看电影。所以写个脚本给开启画中画加个快捷键方便使用。加入油猴之后在视频页按 alt+p 就可以了。
// ==UserScript==// @name 开启画中画// @namespace https://cnwangjie.com// @version 0.1// @description 开启画中画// @author cnwangjie// @match https://*.bilibili.com/*// @match https://*.youku.com/*// @match https://*.douyu.com/*// @grant none// ==/UserScript==
(function () {const getCurrentPlayingVideo = () => { const videos = [].slice.call(document.querySelectorAll('video')) const [video] = videos.filter(v => !v.paused) return video}const requestPictureInPictureForCurrentPlayingVideo = () => { const video = getCurrentPlayingVideo() if (!video) return video.requestPictureInPicture() const handler = () => { document.exitPictureInPicture() video.removeEventListener(handler) } video.addEventListener('pause', handler)}document.removeEventListener('keydown', window. 开启画中画键盘事件处理器)window. 开启画中画键盘事件处理器 = document.addEventListener('keydown', e => { if (e.altKey && e.keyCode === 80) requestPictureInPictureForCurrentPlayingVideo()})})()