2ch.hk Full page video fix

Fix video div to fill page with correct aspect ratio

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         2ch.hk Full page video fix
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  Fix video div to fill page with correct aspect ratio
// @author       vkc
// @match        https://2ch.hk/*/*
// @match        https://2ch.su/*/*
// @match        https://2ch.life/*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=2ch.hk
// @grant        none
// @license      MIT
// ==/UserScript==

/* globals Settings, MediaViewer, CFG, Store */

(function() {
    'use strict';

    let hasSettings = typeof Settings === 'object' && Settings !== null;
    let hasMediaViewer = typeof MediaViewer === 'function' && MediaViewer !== null;
    let hasCFG = typeof CFG === 'object' && CFG !== null;
    let hasStore = typeof Store === 'object' && Store !== null;
    let defaultValue = true;

    if (!hasSettings || !hasMediaViewer || !hasCFG || !hasStore) {
        return
    }

    let _BORDER = 8;
    let _HEADER = 48;
    let _STORE_KEY_MEDIA = 'media';
    let _STORE_KEY_MEDIA_FULLSCREEN = 'media.open_fullscreen';
    let _SETTING_TITLE = 'Разворачивать мультимедиа на весь экран';

    Settings.addSetting(_STORE_KEY_MEDIA, _STORE_KEY_MEDIA_FULLSCREEN, {
        label: _SETTING_TITLE,
        default: defaultValue
    });

    MediaViewer.prototype.scale = function() {
        if (this.data.w > CFG.W_WIDTH || this.data.h > CFG.W_HEIGHT || Store.get(_STORE_KEY_MEDIA_FULLSCREEN, defaultValue)) {
            let multW = Math.max(0.1, Math.round((CFG.W_WIDTH - _BORDER * 2) / this.data.w * 100) / 100);
            let multH = Math.max(0.1, Math.round((CFG.W_HEIGHT - _BORDER * 2 - _HEADER) / this.data.h * 100) / 100);
            this.resize(Math.min(multW, multH), true);
        }
    }

})();