Mintegral Report Page Height Fix

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

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Mintegral Report Page Height Fix
// @namespace    http://tampermonkey.net/
// @version      1.61
// @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';

    // =================================================================
    // 功能: 在特定页面上限制表格行高 (v1.6 - 支持创意页面和编辑页面)
    // =================================================================
    function limitTableRowHeight() {
        const currentUrl = window.location.href;
        
        // 处理 offer 编辑页
        if (/cn\/offers\/edit/.test(currentUrl) && /\?id=\d+/.test(currentUrl)) {
            console.log('Mintegral Script: Offer Edit page detected. Applying styles (v1.6).');
            const tableCellSelector = '.creative-table .el-table__body-wrapper tbody td';

            const newStyles = `
                /* 减小表格单元格的内边距和行高 */
                ${tableCellSelector} {
                    padding: 2px 0 !important;
                    line-height: 1.2 !important;
                }

                /* 限制单元格内容高度并处理溢出 */
                ${tableCellSelector} .cell {
                    max-height: 40px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: normal;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                }
            `;

            // 移除可能存在的旧样式
            const existingStyle = document.getElementById('mint-edit-table-styles');
            if (existingStyle) {
                existingStyle.remove();
            }

            const styleSheet = document.createElement('style');
            styleSheet.id = 'mint-edit-table-styles';
            styleSheet.type = 'text/css';
            styleSheet.innerText = newStyles;
            document.head.appendChild(styleSheet);

            console.log('Mintegral Script: Styles injected for edit page.');
        }
        // 处理创意页面
        else if (/cn\/creatives/.test(currentUrl)) {
            console.log('Mintegral Script: Creatives page detected. Applying styles (v1.6).');
            const tableCellSelector = '.el-table .el-table__body-wrapper tbody td';
            
            const newStyles = `
                /* 减小表格单元格的内边距和行高 */
                ${tableCellSelector} {
                    padding: 2px 0 !important;
                    line-height: 1.2 !important;
                }

                /* 限制单元格内容高度并处理溢出 */
                ${tableCellSelector} .cell {
                    max-height: 40px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: normal;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                }
                
                /* 针对创意页面特定列的样式调整 */
                #pane-creativeSet .el-table__body-wrapper tbody td.el-table_1_column_5.el-table__cell,
                #pane-creativeSet .el-table__body-wrapper tbody td.el-table_1_column_6.el-table__cell {
                    padding: 2px 0 !important;
                    line-height: 1.2 !important;
                }

                #pane-creativeSet .el-table__body-wrapper tbody td.el-table_1_column_5.el-table__cell .cell,
                #pane-creativeSet .el-table__body-wrapper tbody td.el-table_1_column_6.el-table__cell .cell {
                    max-height: 40px !important;
                    overflow: hidden !important;
                    text-overflow: ellipsis !important;
                    white-space: normal !important;
                    display: -webkit-box !important;
                    -webkit-line-clamp: 2 !important;
                    -webkit-box-orient: vertical !important;
                }
            `;

            // 移除可能存在的旧样式
            const existingStyle = document.getElementById('mint-creative-table-styles');
            if (existingStyle) {
                existingStyle.remove();
            }

            const styleSheet = document.createElement('style');
            styleSheet.id = 'mint-creative-table-styles';
            styleSheet.type = 'text/css';
            styleSheet.innerText = newStyles;
            document.head.appendChild(styleSheet);

            console.log('Mintegral Script: Styles injected for creative page.');
        }
    }

    // 脚本首次加载时运行一次
    limitTableRowHeight();
    
    // 同时在 DOM 完全加载后再次运行
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', limitTableRowHeight);
    } else {
        // 如果 DOM 已经加载,稍等一下再运行以确保页面内容完全渲染
        setTimeout(limitTableRowHeight, 500);
    }
    
    // 监听页面 URL 变化以处理动态路由
    let currentUrl = window.location.href;
    const urlCheckInterval = setInterval(() => {
        if (window.location.href !== currentUrl) {
            currentUrl = window.location.href;
            console.log('Mintegral Script: URL changed, re-applying styles.');
            setTimeout(limitTableRowHeight, 300); // 稍等页面加载后再应用样式
        }
    }, 1000); // 每秒检查一次 URL 变化


    // =================================================================
    // 原有功能: 增加表格区域的最大高度(原始版本)
    // =================================================================
    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';
            } else {
                element.style.maxHeight = `${DEFAULT_HEIGHT}px !important`;
                element.dataset.heightModified = 'true';
            }
            element.style.height = 'auto !important';
            element.style.overflowY = 'auto !important';
        }
    }

    const observer = new MutationObserver(() => {
        selectors.forEach(selector => {
            try {
                const element = document.querySelector(selector);
                if (element) {
                    modifyHeight(element, selector);
                }
            } catch (e) { /* Do nothing */ }
        });
    });

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

})();