Warning: fopen(/www/sites/update.greasyfork.icu/index/store/forever/8db9de626009685146c29dae62d20a43.js): failed to open stream: No space left on device in /www/sites/update.greasyfork.icu/index/scriptControl.php on line 65
// ==UserScript==
// @name 小窗口视频(bili,mgtv)
// @version 0.2
// @license MPL-2.0
// @namespace
// @description 小窗口视频(bili,mgtv)。网页右下角会出现一个小按钮,点击之后视频会通过小窗口播放。基于chrome浏览器的画中画(Picture in Picture)。
// @author c4r
// @require https://code.jquery.com/jquery-latest.js
// @match https://www.bilibili.com/video/*
// @match https://www.bilibili.com/bangumi/*
// @match https://live.bilibili.com/*
// @match https://www.mgtv.com/b/*
// @match https://www.bilibili.com/watchlater/*
// @match https://www.youtube.com/watch*
// @grant none
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
let videoUrl = undefined;
/**
*
*/
let callbackVideo = function (mutationList, observer) {
// console.log("coin change : ", mutationList)
if ($('video').length > 0) {
// if (videoUrl != $('video').attr('src')) {
// 视频地址发生变更
videoUrl = $('video').attr('src')
if (document.pictureInPictureElement
&& document.pictureInPictureElement.src != document.getElementsByTagName('video')[0].src) {
// console.log("picInpic : video address changed ", $('video').attr('src'))
// 在画中画里
// console.log("picInpic : pictureInPictureElement ", document.pictureInPictureElement)
console.log("picInpic : pictureInPictureElement ", document.getElementsByTagName('video')[0])
setTimeout(() => {
console.log("picInpic : setTimeout")
document.getElementsByTagName('video')[0].requestPictureInPicture().catch(error => {
// 视频无法进入画中画模式
console.log('picInpic error : ', error, document.pictureInPictureElement)
});
}, 1000);
// setTimeout(() => {
// console.log("picInpic : setTimeout")
// document.getElementsByTagName('video')[0].requestPictureInPicture().catch(error => {
// // 视频无法进入画中画模式
// console.log('picInpic error : ', error, document.pictureInPictureElement)
// });
// }, 6000);
document.getElementsByTagName('video')[0].addEventListener("loadeddata", () => {
console.log("picInpic : loadeddata")
// document.exitPictureInPicture()
document.getElementsByTagName('video')[0].requestPictureInPicture().catch(error => {
// 视频无法进入画中画模式
console.log('picInpic error : ', error, document.pictureInPictureElement)
});
})
// $('video').on("timeupdate", () => {
// if (document.pictureInPictureElement
// && document.pictureInPictureElement.src != document.getElementsByTagName('video')[0].src) {
// document.getElementsByTagName('video')[0].requestPictureInPicture().catch(error => {
// // 视频无法进入画中画模式
// console.log('picInpic error : ', error, document.pictureInPictureElement)
// });
// }
// })
}
// }
}
}
let observerVideo = new MutationObserver(callbackVideo)
document.body.insertAdjacentHTML('beforeend', '')
document.getElementById('c4r-oxgs73w7rh').addEventListener("click", () => {
// if (!document.pictureInPictureElement) {
document.getElementsByTagName('video')[0].requestPictureInPicture().then(() => {
observerVideo.disconnect()
observerVideo.observe($('body').get(0),
{
subtree: true, childList: true, characterData: true, attributes: true,
attributeOldValue: false, characterDataOldValue: false
})
}).catch(error => {
// 视频无法进入画中画模式
});
// } else {
// document.exitPictureInPicture()
// .catch(error => {
// // 视频无法退出画中画模式
// });
// }
})
})();