|
| 1 | +// ==UserScript== |
| 2 | +// @name YouTube fast fullscreen toggle on X key |
| 3 | +// @namespace http://tampermonkey.net/ |
| 4 | +// @version 0.1 |
| 5 | +// @description try to take over the world! |
| 6 | +// @author Brendan Weibrecht |
| 7 | +// @match https://www.youtube.com/watch* |
| 8 | +// @grant none |
| 9 | +// ==/UserScript== |
| 10 | + |
| 11 | +(function() { |
| 12 | + 'use strict'; |
| 13 | + |
| 14 | + const fluff = ['#secondary', '#info', '#meta', '#comments', '#masthead-container', '#speedyg'] |
| 15 | + |
| 16 | + const setFluffDisplay = (value) => { |
| 17 | + fluff.forEach(sel => { document.querySelector(sel).style.display = value }) |
| 18 | + } |
| 19 | + |
| 20 | + const hideFluff = () => setFluffDisplay('none') |
| 21 | + const showFluff = () => setFluffDisplay('') |
| 22 | + |
| 23 | + const isFluffShown = () => document.querySelector(fluff[0]).style.display != 'none' |
| 24 | + |
| 25 | + const clickFullScreenButton = () => document.querySelector('.ytp-fullscreen-button').click() |
| 26 | + |
| 27 | + const enterFullScreen = () => { |
| 28 | + hideFluff() |
| 29 | + clickFullScreenButton() |
| 30 | + setTimeout(() => showFluff(), 40) |
| 31 | + } |
| 32 | + |
| 33 | + const exitFullScreen = () => { |
| 34 | + hideFluff() |
| 35 | + clickFullScreenButton() |
| 36 | + setTimeout(() => showFluff(), 40) |
| 37 | + } |
| 38 | + |
| 39 | + const isFullScreen = () => document.querySelector('.html5-video-player.ytp-fullscreen') |
| 40 | + |
| 41 | + const fastToggleFullScreen = () => { |
| 42 | + isFullScreen() ? exitFullScreen() : enterFullScreen() |
| 43 | + } |
| 44 | + |
| 45 | + document.addEventListener("keydown", e => { |
| 46 | + if (e.code == 'KeyX') { |
| 47 | + fastToggleFullScreen() |
| 48 | + } else if (e.code == 'KeyF') { |
| 49 | + alert('Reminder: Press X instead for speed!') |
| 50 | + } |
| 51 | + }) |
| 52 | + |
| 53 | + /*document.addEventListener('wheel', e => { |
| 54 | + if (e.deltaY > 0 && !isFluffShown()) { |
| 55 | + showFluff() |
| 56 | + } |
| 57 | + })*/ |
| 58 | +})(); |
0 commit comments