Gelbooru Size Video in View

Keeps video player where it always looks good, even without scrolling.

// ==UserScript==
// @name         Gelbooru Size Video in View
// @namespace    https://greasyfork.org/en/users/460331-xerodusk
// @version      1.0.0
// @description  Keeps video player where it always looks good, even without scrolling.
// @author       Xerodusk
// @homepage     https://greasyfork.org/en/users/460331-xerodusk
// @license      GPL-3.0-or-later
// @match        https://gelbooru.com/index.php?page=post&s=view*
// @grant        none
// @icon         https://gelbooru.com/favicon.png
// ==/UserScript==
/* jshint esversion: 6 */

(function() {
    'use strict';

    // Get video dimensions
    const videoElement = document.getElementById('gelcomVideoPlayer');
    if (!videoElement) {
        return;
    }
    const videoWidth = videoElement.width;
    const videoHeight = videoElement.height;

    // Remove conflicting styling
    videoElement.parentNode.style = '';

    // Apply styling to fix size
    const css = document.createElement('style');
    css.appendChild(document.createTextNode(`
        #fluid_video_wrapper_gelcomVideoPlayer {
            width: auto !important;
            max-width: min(100%, 1000px) !important;
            max-height: calc(100vh - 244px) !important;
            aspect-ratio: ${videoWidth} / ${videoHeight} !important;
        }
        #gelcomVideoPlayer {
            width: auto !important;
            height: 100% !important;
            max-height: 100% !important;
            margin: auto !important;
        }
    `));
    document.head.appendChild(css);
})();