Mintegral Report Page Height Fix

Increase max-height for some elements and limit row height for specific tables on Mintegral pages.

当前为 2025-09-26 提交的版本,查看 最新版本

// ==UserScript==
// @name         Mintegral Report Page Height Fix
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Increase max-height for some elements and limit row height for specific tables on Mintegral pages.
// @author       Grok & Gemini
// @match        https://adv.mintegral.com/*
// @grant        none
// @license      GPL-3.0 License
// ==/UserScript==
(function() {
    'use strict';

    // =================================================================
    // 功能: 在特定页面上限制表格行高
    // =================================================================
    function limitTableRowHeight() {
        const currentUrl = window.location.href;
        const isCreativesPage = currentUrl.includes('/cn/creatives');
        const isOffersEditPage = /cn\/offers\/edit\?id=\d+/.test(currentUrl);

        // --- 规则 1: 仅针对 Offer 编辑页面 ---
        if (isOffersEditPage) {
            console.log('Mintegral Script: Offer Edit page detected. Applying styles.');
            const editPageSelector = '.creative-table .el-table__body-wrapper tbody td';
            const editPageStyles = `
                ${editPageSelector} {
                    padding: 2px 0 !important;
                    line-height: 1.2 !important;
                }
                ${editPageSelector} .cell {
                    max-height: 40px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: normal;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                }
            `;
            const styleSheet = document.createElement('style');
            styleSheet.type = 'text/css';
            styleSheet.innerText = editPageStyles;
            document.head.appendChild(styleSheet);
            console.log('Mintegral Script: Styles for Offer Edit page injected.');
        }

        // --- 规则 2: 仅针对 Creatives 列表页面 ---
        if (isCreativesPage) {
            console.log('Mintegral Script: Creatives List page detected. Applying styles.');
            // 根据您的最新反馈,使用 #pane-creativeSet 作为目标
            const creativesPageSelector = '#pane-creativeSet .el-table__body-wrapper tbody td';
            // 参考 edit 页面的成功样式
            const creativesPageStyles = `
                ${creativesPageSelector} {
                    padding: 2px 0 !important;
                    line-height: 1.2 !important;
                }
                ${creativesPageSelector} .cell {
                    max-height: 40px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: normal;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                }
            `;
            const styleSheet = document.createElement('style');
            styleSheet.type = 'text/css';
            styleSheet.innerText = creativesPageStyles;
            document.head.appendChild(styleSheet);
            console.log('Mintegral Script: Styles for Creatives List page injected.');
        }
    }

    // 在脚本开始时执行一次新功能
    limitTableRowHeight();


    // =================================================================
    // 原有功能: 增加表格区域的最大高度
    // =================================================================
    const selectors = [
        '#__layout div.el-card.is-always-shadow > div > section.margin-top-4 > div > div.el-table.mtg_table.el-table--fluid-height',
        '#__layout div.el-card.is-always-shadow > div > section.margin-top-4 > div > div.el-table__body-wrapper',
        '#__layout div.el-card.is-always-shadow > div > section.margin-top-4 > div > div.el-table__fixed',
        'div.el-table--fluid-height',
        'div.el-table.mtg_table',
        'div.el-table__body-wrapper',
        'div.el-table__fixed',
        'div.el-table__fixed-body-wrapper'
    ];
    const DEFAULT_HEIGHT = 900;
    const HEIGHT_INCREMENT = 400;
    const style = document.createElement('style');
    style.textContent = selectors.map(sel => `${sel} { max-height: none !important; height: auto !important; overflow-y: auto !important; }`).join('\n');
    document.head.appendChild(style);

    function modifyHeight(element, selector) {
        if (element && !element.dataset.heightModified) {
            const computedStyle = window.getComputedStyle(element);
            let currentMaxHeight = computedStyle.maxHeight;
            if (currentMaxHeight && currentMaxHeight !== 'none' && currentMaxHeight.includes('px')) {
                const currentHeight = parseFloat(currentMaxHeight);
                const newHeight = currentHeight + HEIGHT_INCREMENT;
                element.style.maxHeight = `${newHeight}px !important`;
                element.dataset.heightModified = 'true';
                console.log(`Mintegral Script: Modified max-height for ${selector}: ${currentMaxHeight} -> ${newHeight}px`);
            } else {
                element.style.maxHeight = `${DEFAULT_HEIGHT}px !important`;
                element.dataset.heightModified = 'true';
                console.log(`Mintegral Script: Set max-height for ${selector} to ${DEFAULT_HEIGHT}px (no previous max-height)`);
            }
            element.style.height = 'auto !important';
            element.style.overflowY = 'auto !important';
        }
    }

    window.addEventListener('load', () => {
        selectors.forEach(selector => {
            try {
                const element = document.querySelector(selector);
                if (element) {
                    modifyHeight(element, selector);
                }
            } catch (error) {
                console.error(`Mintegral Script: Error processing selector ${selector}:`, error);
            }
        });
    });

    const observer = new MutationObserver(() => {
        selectors.forEach(selector => {
            const element = document.querySelector(selector);
            modifyHeight(element, selector);
        });
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    setInterval(() => {
        selectors.forEach(selector => {
            const element = document.querySelector(selector);
            modifyHeight(element, selector);
        });
    }, 500);

    setTimeout(() => {
        selectors.forEach(selector => {
            const element = document.querySelector(selector);
            modifyHeight(element, selector);
        });
    }, 5000);

    setTimeout(() => {
        selectors.forEach(selector => {
            const element = document.querySelector(selector);
            modifyHeight(element, selector);
        });
    }, 10000);
})();