Greasy Fork 支持简体中文。

_ 快速提取email log的链接

快速提取email log的链接!

// ==UserScript==
// @name         _ 快速提取email log的链接
// @namespace    http://tampermonkey.net/
// @version      2025.2.13
// @description  快速提取email log的链接!
// @author       You
// @match        http://*/app/system/logs/email-log
// @match        https://*/app/system/logs/email-log
// @icon         https://www.google.com/s2/favicons?sz=64&domain=undefined.localhost
// @license      MIT
// @grant        GM_setClipboard
// @grant        GM_notification
// @grant        GM_addStyle
// ==/UserScript==

(function () {
    'use strict';

    const theme_color = 'rgb(114, 124, 245)';
    const theme_color_hover = 'rgb(114, 124, 245,0.7)';
    const theme_color_feedback = 'rgb(114, 124, 245,0.2)';
    // 创建容器
    const container = document.createElement('div');
    container.classList.add('extract_email_url_container');
    container.style.position = 'fixed';
    container.style.left = '10px';
    container.style.bottom = '10px';
    container.style.width = 'fit-content';
    container.style.maxWidth = '99vw';
    //container.style.height = '62px';
    container.style.backgroundColor = 'white';
    container.style.border = '1px solid #dcdfe6';
    container.style.borderRadius = '6px';
    container.style.boxShadow = '0 2px 12px rgba(0,0,0,0.1)';
    container.style.padding = '10px';
    container.style.zIndex = '9999';
    container.style.display = 'flex';
    container.style.alignItems = 'center';
    container.style.flexDirection = 'column'

    // 创建最小化按钮
    const minimizeBtn = document.createElement('div');
    minimizeBtn.classList.add('extract_email_url_minimize_btn');
    minimizeBtn.style.position = 'absolute';
    minimizeBtn.style.right = '10px';
    minimizeBtn.style.top = '10px';
    minimizeBtn.style.cursor = 'pointer';
    minimizeBtn.style.fontSize = '26px';
    minimizeBtn.innerHTML = '×';
    minimizeBtn.style.width = '28px';
    minimizeBtn.style.height = '28px';
    minimizeBtn.style.lineHeight = '24px';
    minimizeBtn.style.textAlign = 'center';
    minimizeBtn.style.borderRadius = '50%';
    minimizeBtn.style.color = 'white';
    minimizeBtn.style.border = `1px solid rgb(245, 108, 108)`;
    minimizeBtn.style.backgroundColor = 'rgb(245, 108, 108)';
    minimizeBtn.style.transform = 'translate(50%, -50%)';

    // 创建最小化状态的圆形容器
    const circle = document.createElement('div');
    circle.classList.add('extract_email_url_circle');
    circle.style.position = 'fixed';
    circle.style.width = '40px';
    circle.style.height = '40px';
    circle.style.borderRadius = '50%';
    circle.style.backgroundColor = theme_color;
    circle.style.cursor = 'pointer';
    circle.style.display = 'none';
    circle.style.zIndex = '9999';
    circle.style.boxShadow = '0 2px 12px rgba(0,0,0,0.1)';
    circle.style.transition = 'transform 0.3s ease';
    circle.innerHTML = '⚙️';
    circle.style.display = 'flex';
    circle.style.alignItems = 'center';
    circle.style.justifyContent = 'center';
    circle.style.left = '10px';
    circle.style.bottom = '10px';
    // 鼠标悬浮移除minimize状态
    GM_addStyle(`
        .extract_email_url_circle:hover {
            transform: translateX(0);
            opacity: 1;
        }
        .extract_email_url_circle {
            transform: translateX(-70%);
            opacity: 0.5;
        }
    `);

    // 按钮容器
    const action_container = document.createElement('div');
    action_container.classList.add('extract_email_url_action_container');
    action_container.style.display = 'flex';
    action_container.style.width = '100%';
    action_container.style.justifyContent = 'center';
    action_container.style.gap = '10px';
    action_container.style.marginTop = '10px';

    // 使用说明
    const feedback_container = document.createElement('div');
    feedback_container.classList.add('extract_email_url_feedback_container');
    feedback_container.innerHTML = `点击按钮,新页面打开/点击链接,复制链接到剪贴板`;
    feedback_container.style.color = theme_color;
    feedback_container.style.fontSize = '12px';
    feedback_container.style.margin = '10px 0';
    container.appendChild(feedback_container);

    // 创建提取按钮
    const button = document.createElement('button');
    button.classList.add('extract_email_url_button');
    button.textContent = '提取';
    button.style.backgroundColor = theme_color;
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '4px';
    button.style.padding = '5px 10px';
    button.style.cursor = 'pointer';
    button.style.outline = 'none';
    button.style.transition = 'background-color 0.3s';
    button.style.marginLeft = 'auto';
    // 按钮悬停效果
    button.onmouseover = () => {
        button.style.backgroundColor = theme_color_hover;
    };
    button.onmouseout = () => {
        button.style.backgroundColor = theme_color;
    };
    // 按钮点击事件处理
    button.onclick = () => {
        const nodes = document.querySelectorAll('tr>td>a');
        if (nodes.length === 0) {
            showFeedback(`暂无数据`);
            return;
        }
        let res = Array.from(nodes).reduce((acc, item) => {
            acc.push({ content: item.innerText, href: item.dataset.href });
            return acc;
        }, []);
        removeList()
        createList(res)
    };

    const ul = document.createElement('ul');
    ul.style.margin = 0;
    ul.classList.add('result_ul');

    // 创建抓取项目的li节点
    function createList(list) {
        list.forEach(item => {
            const p_item = document.createElement('div');
            p_item.classList.add('result_p');
            p_item.style.display = 'flex';
            p_item.style.alignItems = 'center';
            p_item.style.justifyContent = 'flex-start';
            p_item.style.flexWrap = 'wrap';
            p_item.style.gap = '10px';
            p_item.style.margin = "10px 0";

            const li = document.createElement('li');
            li.style.listStyle = 'auto';

            const span_label = document.createElement('span');
            span_label.textContent = item.content;
            addBtnStyle(span_label)
            addEvent(span_label, item.href)

            const span_colon = document.createElement('span');
            span_colon.textContent = ':';

            const span_href = document.createElement('span');
            span_href.style.cursor = 'pointer';
            span_href.style.color = theme_color;
            span_href.textContent = item.href;
            addStyle(span_href, item.href)

            p_item.appendChild(span_label);
            p_item.appendChild(span_colon);
            p_item.appendChild(span_href);
            li.appendChild(p_item);
            ul.appendChild(li);
        })
    };

    // 创建清空按钮
    const reset = document.createElement('button');
    reset.textContent = '清空';
    reset.style.backgroundColor = '#F56C6C';
    reset.style.color = 'white';
    reset.style.border = 'none';
    reset.style.borderRadius = '4px';
    reset.style.padding = '5px 10px';
    reset.style.cursor = 'pointer';
    reset.style.outline = 'none';
    reset.style.transition = 'background-color 0.3s';
    reset.onclick = () => {
        removeList()
    };

    function removeList() {
        const resultList = document.querySelector('ul.result_ul');
        if (resultList) {
            // 删除所有子节点
            while (resultList.firstChild) {
                resultList.removeChild(resultList.firstChild);
            }
        }
    };

    // hover的样式
    var hoverStyle = {
        backgroundColor: theme_color,
        color: '#f3f3f3',
        'border-radius': '3px',
        transition: 'all .1s ease'
    };
    var normalStyle = {
        backgroundColor: 'transparent',
        color: theme_color,
        'border-radius': '3px',
        transition: 'all .1s ease'
    };

    // 添加样式函数
    function addStyle(element, copyContent) {
        if (!element.dataset.hasListener) { // 防止重复添加事件
            element.style.textDecoration = 'underline';
            // 当鼠标进入元素时添加hover样式
            element.addEventListener('mousedown', function () {
                for (var property in hoverStyle) {
                    element.style[property] = hoverStyle[property];
                }
            });
            // 当鼠标离开元素时移除hover样式
            element.addEventListener('mouseup', function () {
                for (var property in hoverStyle) {
                    element.style[property] = normalStyle[property]; // 重置样式
                }
            });
            element.addEventListener('click', (event) => {
                GM_setClipboard(copyContent); // 将内容复制到剪贴板
                showFeedback(`已复制到剪贴板`);
                event.stopPropagation();
                event.preventDefault()
            });
            element.dataset.hasListener = 'true'; // 标记该元素已添加事件
        }
    }
    function addBtnStyle(element) {
        element.style.cursor = 'pointer';
        element.style.backgroundColor = '#727cf5';
        element.style.color = 'white';
        element.style.padding = '6px 12px';
        element.style.borderRadius = '4px';
    }
    function addEvent(element, href) {
        element.addEventListener('click', () => {
            window.open(href, "_blank");
        })
    }

    // 显示反馈信息
    function showFeedback(message) {
        // 创建反馈元素
        const feedbackElement = document.createElement('div');
        feedbackElement.textContent = message;
        feedbackElement.style.position = 'fixed';
        feedbackElement.style.top = '20px';
        feedbackElement.style.left = '50%';
        feedbackElement.style.padding = '10px 20px';
        feedbackElement.style.border = `1px solid ${theme_color}`;
        feedbackElement.style.backgroundColor = theme_color_feedback; // 绿色背景
        feedbackElement.style.color = 'white';
        feedbackElement.style.borderRadius = '5px';
        feedbackElement.style.zIndex = '9999';
        feedbackElement.style.transition = 'opacity 0.5s';
        feedbackElement.style.opacity = '1';

        document.body.appendChild(feedbackElement);

        // 设定延迟隐藏反馈
        setTimeout(() => {
            feedbackElement.style.opacity = '0'; // Fade out
            setTimeout(() => {
                document.body.removeChild(feedbackElement); // Remove after fade out
            }, 500);
        }, 2000); // 2000毫秒后淡出
    }

    // 将选择框和按钮添加到容器
    container.appendChild(ul);
    container.appendChild(minimizeBtn);
    container.appendChild(action_container);
    action_container.appendChild(feedback_container);
    action_container.appendChild(button);
    action_container.appendChild(reset);
    document.body.appendChild(container);
    document.body.appendChild(circle);

    // 初始状态为最小化
    container.style.display = 'none';
    circle.style.display = 'flex';

    // 最小化/展开切换
    let isMinimized = true;

    minimizeBtn.onclick = () => {
        minimize();
    };

    circle.onclick = () => {
        expand();
    };

    function minimize() {
        container.style.display = 'none';
        circle.style.display = 'flex';
        isMinimized = true;
    }

    function expand() {
        circle.style.display = 'none';
        container.style.display = 'flex';
        isMinimized = false;
    }

    // 添加点击事件监听器到document
    document.addEventListener('click', (event) => {
        // 检查点击是否在container或circle之外
        if (!container.contains(event.target) && !circle.contains(event.target) && !isMinimized) {
            minimize();
        }
    });
})();