-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyt-fit_video_to_window.user.js
78 lines (64 loc) · 2.41 KB
/
yt-fit_video_to_window.user.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
69
70
71
72
73
74
75
76
77
78
// ==UserScript==
// @name YouTube Fit Video to Window
// @namespace http://github.com/uky/greasemonkey
// @author Uky
// @description Resizes video to the browser's window size.
// @version 2013.03.21
// @updateURL https://github.com/uky/greasemonkey/raw/master/yt-fit_video_to_window.meta.js
// @downloadURL https://github.com/uky/greasemonkey/raw/master/yt-fit_video_to_window.user.js
// @grant none
// @include http://www.youtube.com/watch?*
// @include https://www.youtube.com/watch?*
// ==/UserScript==
// [ Constants ]
var header_ID = 'watch7-headline';
var player_ID = 'player-api';
var video_ID = 'watch7-video';
// [ Derived Values ]
var header_height = 0;
var header = document.getElementById(header_ID);
if (header != null)
header_height = header.offsetHeight;
// [ Main Script ]
// Remove guide for extra horizontal viewing area.
var body = document.getElementsByTagName('body')[0];
if (body != null) {
if (body.classList.contains('guide-enabled'))
body.classList.remove('guide-enabled');
if (body.classList.contains('guide-expanded')) {
body.classList.remove('guide-expanded');
body.classList.add('guide-collapsed');
}
}
var video_container = document.getElementById('player');
if (video_container != null)
video_container.style.paddingLeft = 0;
// Prevent video overlays.
var container = document.getElementById('watch7-container');
if (container != null) {
// Force sidebar below video.
var wide_class = 'watch-wide';
if (!container.classList.contains(wide_class))
container.classList.add(wide_class);
// Collapse playlist.
var playlist_class = 'watch-playlist-collapsed';
if (!container.classList.contains(playlist_class))
container.classList.add(playlist_class);
}
// Resize the video to fit the browser window.
function fitToWindow() {
var player = document.getElementById(player_ID);
var video = document.getElementById(video_ID);
if (video != null)
video.style.width = document.body.offsetWidth + 'px';
if (player != null) {
player.style.width = document.body.offsetWidth + 'px';
player.style.height = (document.body.offsetHeight - header_height - 5) + 'px';
}
}
window.addEventListener('resize', fitToWindow, false);
fitToWindow();
// Scroll past the masthead.
var player = document.getElementById(player_ID);
if (player != null)
player.scrollIntoView(true);