Greasy Fork

来自缓存

Shopee 悬浮按钮优化版

优化版 - 悬浮快捷入口 & 智能清理追踪参数

// ==UserScript==
// @name         Shopee 悬浮按钮优化版
// @namespace    http://tampermonkey.net/
// @version      2.0.1
// @license      Rayu
// @description  优化版 - 悬浮快捷入口 & 智能清理追踪参数
// @author       Rayu
// @match        https://seller.shopee.tw/*
// @exclude      https://seller.shopee.tw/webchat/conversations
// @match        *://shopee.tw/*
// @match        *://shopee.ph/*
// @match        *://shopee.sg/*
// @match        *://shopee.com.my/*
// @icon         https://www.wikimedia.org/static/favicon/wikipedia.ico
// @grant        GM_addStyle
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // 配置中心
    const CONFIG = {
        BUTTONS: [
            {
                id: 'shipment-btn',
                content: '待<br>出货',
                path: '/portal/sale/shipment?type=toship',
                title: '待处理订单'
            },
            {
                id: 'products-btn',
                content: '我的<br>商品',
                path: '/portal/product/list/all?page=1&size=48',
                title: '商品管理'
            },
            {
                id: 'analytics-btn',
                content: '商品<br>分析',
                path: '/datacenter/product/overview',
                title: '数据分析'
            },
            {
                id: 'ads-btn',
                content: '我的<br>广告',
                path: '/portal/marketing/pas/assembly',
                title: '广告管理'
            },
            {
                id: 'campaign-btn',
                content: '行销<br>活动',
                path: '/portal/marketing',
                title: '营销活动'
            },
            {
                id: 'returns-btn',
                content: '退貨<br>退款',
                path: '/portal/sale/return',
                title: '退货退款'
            }
        ],
        TRACKING_PATTERN: /-i\.(\d+)\.(\d+)/,
        STYLES: `
            :root {
                --primary-color: #ee4d2d;
                --button-size: 52px;
                --hover-scale: 1.08;
                --gap: 8px;
            }

            #floating-buttons-container {
                position: fixed;
                top: 50vh;
                right: 50px;
                transform: translateY(-50%);
                display: flex;
                flex-direction: column;
                gap: var(--gap);
                z-index: 9999;
                filter: drop-shadow(0 2px 6px rgba(0,0,0,0.16));
            }

            .floating-button {
                display: flex;
                align-items: center;
                justify-content: center;
                width: var(--button-size);
                height: var(--button-size);
                background: var(--primary-color);
                color: white !important;
                border-radius: 8px;
                font-size: 15px;
                font-weight: 500;
                line-height: 1.3;
                text-align: center;
                text-decoration: none !important;
                cursor: pointer;
                transition:
                    transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28),
                    opacity 0.2s,
                    background 0.2s;
                user-select: none;
            }

            .floating-button:hover {
                transform: scale(var(--hover-scale));
                background: #d14327;
                opacity: 0.95;
            }

            .floating-button:active {
                transition-duration: 0.1s;
                transform: scale(0.96);
            }

            @media (max-width: 768px) {
                #floating-buttons-container {
                    right: 4px;
                    transform: translateY(-50%) scale(0.82);
                    gap: 6px;
                }
                .floating-button {
                    width: 46px;
                    height: 46px;
                    font-size: 14px;
                }
            }

            /* 页面布局优化 */
            .route-portal-marketing-pas-assembly .ads-index,
            .route-portal-marketing-pas .ads-index {
                width: 1650px !important;
            }

            .page-content-wrapper.responsive-content-wrapper {
                max-width: 1500px !important;
            }

            .route-portal-marketing-pas-index .page-container.has-sidebar-panel{
                padding-left: 125px !important;
            }

            .page-content-wrapper{
                margin-left: 60px !important;
            }

            .main-content .list-index[data-v-0fb3e6e7]{
                min-width: 1750px !important;
            }

            .to-do-list-container[data-v-515cb672],
            .top-text-container[data-v-7d956ea7],
            .rcmd-rewards-section[data-v-67fc4796]{
                display: none !important;
            }

            .module-page-detail[data-v-5b5b6ffa]{
                min-width: 1750px!important;
            }
        `
    };

    // 核心功能模块
    class ShopeeEnhancer {
        constructor() {
            this.observer = null;
            this.init();
        }

        init() {
            this.injectStyles();
            this.createFloatingButtons();
            this.sanitizeLinks();
        }

        injectStyles() {
            GM_addStyle(CONFIG.STYLES);
        }

        createFloatingButtons() {
            const container = document.createElement('div');
            container.id = 'floating-buttons-container';

            container.innerHTML = CONFIG.BUTTONS.map(btn => `
                <a class="floating-button"
                   id="${btn.id}"
                   href="${new URL(btn.path, window.location.origin)}"
                   target="_blank"
                   title="${btn.title}"
                   rel="noopener noreferrer">
                    ${btn.content}
                </a>
            `).join('');

            document.body.appendChild(container);
        }

        sanitizeLinks() {
            // 当前页面处理
            if (CONFIG.TRACKING_PATTERN.test(window.location.href)) {
                this.cleanUrl();
                return;
            }

            // 初始化清理
            this.processLinks(document);

            // 动态内容监控
            this.observer = new MutationObserver(mutations => {
                mutations.forEach(({ addedNodes }) => {
                    addedNodes.forEach(node => {
                        if (node.nodeType === Node.ELEMENT_NODE) {
                            this.processLinks(node);
                        }
                    });
                });
            });

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

        processLinks(root) {
            const links = root.querySelectorAll('a[href*="-i."]');
            links.forEach(link => {
                const match = link.href.match(CONFIG.TRACKING_PATTERN);
                if (match) {
                    link.href = `${window.location.origin}/product/${match[1]}/${match[2]}`;
                }
            });
        }

        cleanUrl() {
            const match = window.location.href.match(CONFIG.TRACKING_PATTERN);
            if (match) {
                window.location.replace(
                    `${window.location.origin}/product/${match[1]}/${match[2]}`
                );
            }
        }
    }

    // 启动程序
    new ShopeeEnhancer();

})();