Wanikani Forums: Expand Tall Images

Expands tall images on the Wanikani forums

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Wanikani Forums: Expand Tall Images
// @namespace    http://tampermonkey.net/
// @version      0.1.8
// @description  Expands tall images on the Wanikani forums
// @author       Kumirei
// @include      https://community.wanikani.com*
// @require      https://greatest.deepsurf.us/scripts/432418-wait-for-selector/code/Wait%20For%20Selector.js?version=974318
// @grant        none
// ==/UserScript==

(function($, wfs) {
    //wait for images
    wfs.wait('.lightbox img', function(elem) {
        //get the infos
        var dim = [elem.width, elem.height];
        if (elem.height == 500) {//all images which need to be expanded are 500px height
            if ($(elem.nextSibling).find('.informations').length) {
                var infoElem = $(elem.nextSibling).find('.informations')[0];
                var ogDim = infoElem.innerHTML.split(' ')[0];
                if (ogDim.includes("x")) ogDim = ogDim.split('x');
                else if (ogDim.includes("×")) ogDim = ogDim.split('×');
                var scaledDim = [dim[0], Math.round(dim[0]/ogDim[0]*ogDim[1])]; //scales the height to the current width
                if (scaledDim[1] != 499 && dim[1] != scaledDim[1]) {//499 happened often, persumably because Discourse rounds up
                    var url = elem.closest('.lightbox').href;
                    elem.src = url;
                    elem.height = scaledDim[1];
                    elem.style = 'max-height: unset;';
                    infoElem.innerHTML += ' <small>Expanded as tall image</small>';
                }
            }
        }
    });
})(window.jQuery, window.wfs);