Greasy Fork

Greasy Fork is available in English.

Enhanced Mod Card Layout with Miniature Covers on mcmod.cn

Display each mod in a card layout with miniature covers in the top right corner

当前为 2024-04-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Enhanced Mod Card Layout with Miniature Covers on mcmod.cn
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Display each mod in a card layout with miniature covers in the top right corner
// @author       klnon
// @match        https://www.mcmod.cn/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Initially hide the body to prevent flickering
    document.body.style.visibility = 'hidden';

    window.addEventListener('load', function() {
        const blocks = document.querySelectorAll('.modlist-block');
        const listContainer = document.createElement('div');
        listContainer.style.margin = '20px auto'; // Center the container
        listContainer.style.display = 'flex';
        listContainer.style.flexWrap = 'wrap';
        listContainer.style.justifyContent = 'center'; // Ensure cards are centered

        blocks.forEach(block => {
            const modCard = document.createElement('div');
            modCard.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
            modCard.style.border = '1px solid #ccc'; // Add border
            modCard.style.borderRadius = '10px'; // Rounded corners
            modCard.style.transition = '0.3s';
            modCard.style.width = '300px'; // Set a fixed width for each card
            modCard.style.margin = '10px';
            modCard.style.padding = '10px'; // Padding inside the card
            modCard.style.backgroundColor = '#fff'; // Card background color
            modCard.style.textAlign = 'left'; // Text align left
            modCard.style.position = 'relative'; // Required for absolute positioning of the cover

            modCard.onmouseover = function() {
                this.style.boxShadow = '0 8px 16px rgba(0,0,0,0.6)';
            };
            modCard.onmouseout = function() {
                this.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
            };

            const title = block.querySelector('.title').innerHTML;
            const description = block.querySelector('.intro-content span') ? block.querySelector('.intro-content span').textContent.trim() : '无描述';
            const coverImage = block.querySelector('.cover img');
            coverImage.style.width = '100%'; // Set image width to 100% of its container
            coverImage.style.height = 'auto'; // Auto-adjust the height to maintain aspect ratio

            const coverDiv = document.createElement('div');
            coverDiv.style.position = 'absolute';
            coverDiv.style.top = '10px';
            coverDiv.style.right = '10px';
            coverDiv.style.width = '60px'; // Reduced size of the cover container
            coverDiv.style.height = '40px'; // Setting a fixed height for cover container
            coverDiv.style.overflow = 'hidden'; // Prevents content from spilling out
            coverDiv.appendChild(coverImage);

            modCard.innerHTML = `<div class="title"><strong>${title}</strong></div><hr style="margin: 10px 0;"><p>${description}</p>`;
            modCard.appendChild(coverDiv);

            listContainer.appendChild(modCard);
        });

        const contentArea = document.querySelector('.modlist-list-frame');
        contentArea.innerHTML = '';
        contentArea.appendChild(listContainer);

        // Make the body visible again after content replacement
        document.body.style.visibility = 'visible';
    });
})();