-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
66 lines (56 loc) · 2.26 KB
/
script.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
let playerOriginalHeight = 0;
let autoplay = undefined;
window.addEventListener('scroll', event => {
if (window.location.href.indexOf('watch') !== -1) {
let player = document.querySelector('#player.style-scope');
if (player.clientWidth === 0) {
player = document.querySelector('#player-theater-container');
}
const playerBoundingClientRect = player.getBoundingClientRect();
let scrollTop = event.srcElement.scrollingElement.scrollTop
if (scrollTop < 240) {
playerOriginalHeight = playerBoundingClientRect.bottom - playerBoundingClientRect.top;
}
const autoplayBtn = document.getElementsByTagName('paper-toggle-button')[0];
const content = document.querySelector('#columns > #primary');
let isSmallPlayer = false;
if (scrollTop > playerOriginalHeight) {
isSmallPlayer = true;
content.style.marginTop = `${playerOriginalHeight}px`;
if (autoplay === undefined) {
if (autoplayBtn.getAttribute('aria-pressed') === 'true') {
autoplay = true;
} else {
autoplay = false;
}
}
if (autoplay === true) {
if (autoplayBtn.getAttribute('aria-pressed') === 'true') {
autoplayBtn.click();
}
}
} else {
isSmallPlayer = false;
content.style.marginTop = 0;
if (autoplay === true) {
if (autoplayBtn.getAttribute('aria-pressed') === 'false') {
autoplayBtn.click();
}
}
}
const html5Player = document.getElementsByClassName('html5-main-video')[0];
html5Player.classList.toggle('video-float', isSmallPlayer);
const playerContainer = document.querySelector('#player-container-outer');
if (playerContainer) {
playerContainer.classList.toggle('container-float', isSmallPlayer);
}
const theaterPlayerContainer = document.querySelector('#player-theater-container');
if (theaterPlayerContainer) {
theaterPlayerContainer.classList.toggle('container-float', isSmallPlayer);
}
const moviePlayer = document.querySelector('#movie_player')
moviePlayer.classList.toggle('ytp-small-mode', isSmallPlayer);
const chrome_bottom = document.getElementsByClassName('ytp-chrome-bottom')[0];
chrome_bottom.classList.toggle('chrome-bottom-float', isSmallPlayer);
}
});