Vilipix推荐作品按原图比例展示

增大Vilipix推荐作品的图片并按原图比例展示

// ==UserScript==
// @name         Vilipix推荐作品按原图比例展示
// @namespace    https://greasyfork.org/zh-CN/scripts/489774
// @version      0.2
// @description  增大Vilipix推荐作品的图片并按原图比例展示
// @author       dshs
// @match        https://vilipix.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function resizeImages() {
        var pixCards = document.querySelectorAll('.pix-card');
        pixCards.forEach(function(card) {
            var illust = card.querySelector('.illust');
            var elImage = card.querySelector('.el-image');
            var img = card.querySelector('img.el-image__inner');

            if (img && img.naturalWidth && img.naturalHeight) {
                var width1 = img.naturalWidth;
                var height1 = img.naturalHeight;
                var width = 368
                var height = width * height1 / width1

                card.style.width = width + 'px';
                illust.style.width = width + 'px';
                illust.style.height = height + 'px';
                elImage.style.width = width + 'px';
                elImage.style.height = height + 'px';
            }
        });
    }

    function observeDOM(callback) {
        var observer = new MutationObserver(function(mutations) {
            callback();
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    resizeImages();
    observeDOM(resizeImages);
})();