Greasy Fork

Shined up real nice.

YouTube Keep Video When Scrolling

Keeps the video in the same place when scrolling on a YouTube page.

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
79
// ==UserScript==
// @name         YouTube Keep Video When Scrolling
// @namespace    http://skoshy.com
// @version      0.2
// @description  Keeps the video in the same place when scrolling on a YouTube page.
// @author       Stefan Koshy
// @match        https://www.youtube.com/watch?*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';

var id = 'youtubeKeepVideoWhenScrolling';

var keepVideoStyle = `
    #player .player-api {
      position: fixed;
      padding-top: 12px;
      padding-bottom: 10px;
      background: #f1f1f1;
      margin-top: -1px;
    }
    .watch-non-stage-mode #player .player-api {
      box-shadow: 1px 1px rgba(241,241,241,1),-1px 1px rgba(241,241,241,1);
    }
    .watch-stage-mode #player .player-api {
      padding-top:10px;
      padding-bottom: 0;
      margin-top: 0;
    }
`;

var otherStyle = `
    #`+id+`PinButton {
      box-sizing: border-box;
      width: 32px 
    }

    #`+id+`PinButton img {
      width: 100%;
      filter: invert(1);
      -webkit-filter: invert(1);
      padding: 3px;
      box-sizing: border-box;
    }
`;


function addGlobalStyle(css, cssID) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.id = cssID;
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

addGlobalStyle(keepVideoStyle, id+'CSS');
addGlobalStyle(otherStyle, id+'OtherCSS');

// add the button to the player
var ytControls = document.querySelector('.ytp-right-controls');
var ytSettingsButton = document.querySelector('.ytp-settings-button');

var pinButton = document.createElement('button');
pinButton.innerHTML = '<img src="http://i.imgur.com/m4vqtk1.png"/>';
pinButton.id = id+'PinButton';
pinButton.className = 'ytp-button';
pinButton.onclick = function() {
    var style = document.querySelector('#'+id+'CSS');
    if (style.disabled === false)
        style.disabled = true;
    else
        style.disabled = false;
};

ytControls.insertBefore(pinButton, ytSettingsButton);