-
Notifications
You must be signed in to change notification settings - Fork 0
/
YouTubeMiniPlayer.js
68 lines (64 loc) · 2.57 KB
/
YouTubeMiniPlayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// ==UserScript==
// @name YouTube Mini Player
// @namespace http://tampermonkey.net/
// @version 1.0
// @license MIT
// @description let you watch video and comments at the same time!
// @updateURL https://raw.githubusercontent.com/AkiyaKiko/YouTubeMiniPlayer/main/YouTubeMiniPlayer.js
// @downloadURL https://raw.githubusercontent.com/AkiyaKiko/YouTubeMiniPlayer/main/YouTubeMiniPlayer.js
// @author https://github.com/AkiyaKiko
// @homepage https://github.com/AkiyaKiko/YouTubeMiniPlayer
// @match https://www.youtube.com/watch*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
let video = document.getElementsByTagName('video')[0];
let button = document.createElement('button');
button.id = 'YTMiniPlayerButton';
button.style.position = 'fixed';
button.style.right = '90px';
button.style.bottom = '40px';
button.style.zIndex = '1000000 !important'
button.innerText = 'PIP';
button.style.opacity = '0';
button.style.pointerEvents = 'none';
button.onclick = function(){
RPIP(video);
button.style.opacity = '0';
button.style.pointerEvents = 'none';
}
document.body.appendChild(button);
let buttonDOM = document.getElementById('YTMiniPlayerButton');
let io = new IntersectionObserver(
entries => {
entries.forEach(
entry => {
if (entry.isIntersecting){
// if (document.pictureInPictureElement === video){
buttonDOM.style.opacity = '0';
buttonDOM.style.pointerEvents = 'none';
document.exitPictureInPicture();
// document.body.click();
console.log("videoContainerGetintofView");
// }
}else{
if (document.pictureInPictureElement !== video || document.pictureInPictureElement === null || !document.hasFocus()){
buttonDOM.style.opacity = '1';
buttonDOM.style.pointerEvents = '';
// document.body.click();
console.log("videoContainerOutofView");
}
}
}
);
},{threshold:0}
);
io.observe(video);
// Your code here...
})();
function RPIP(video){
video.requestPictureInPicture();
}