// ==UserScript== // @name SHEIN订单统计助手 // @namespace https://tampermonkey.net/ // @version 2.1 // @description 插入到店铺名左边,点击显示统计,5秒自动隐藏 // @author 助手 // @match https://sso.geiwohuo.com/* // @grant none // @run-at document-end // ==/UserScript== (function() { 'use strict'; const AUTO_HIDE_SECONDS = 3; // 自动隐藏秒数 // 创建统计按钮 function createStatsButton() { const btn = document.createElement('button'); btn.textContent = '📊 订单统计'; btn.style.cssText = ` padding: 4px 10px; background: #1677ff; color: #fff; border: none; border-radius: 4px; font-size: 12px; cursor: pointer; margin-right: 10px; vertical-align: middle; `; btn.onmouseover = () => btn.style.background = '#4096ff'; btn.onmouseout = () => btn.style.background = '#1677ff'; return btn; } // 创建面板 let panelYesterday, panelToday; function createPanels() { if (panelYesterday && panelToday) return; panelYesterday = document.createElement('div'); panelYesterday.id = 'orderStatsPanelYesterday'; panelYesterday.style.cssText = ` position: fixed;top: 70px; right: 420px; z-index: 9999; width: 280px; padding: 15px; background: white; border-radius: 6px; box-shadow: 0 2px 12px rgba(0,0,0,0.15); font-size: 14px; line-height: 1.8; display: none; margin-bottom: 10px; `; panelToday = document.createElement('div'); panelToday.id = 'orderStatsPanelToday'; panelToday.style.cssText = ` position: fixed; top: 230px; right: 420px; z-index: 9999; width: 280px; padding: 15px; background: white; border-radius: 6px; box-shadow: 0 2px 12px rgba(0,0,0,0.15); font-size: 14px; line-height: 1.8; display: none; `; document.body.appendChild(panelYesterday); document.body.appendChild(panelToday); } // 日期 function getDateRange(dayOffset) { const date = new Date(); date.setDate(date.getDate() + dayOffset); const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); return { dateStr: `${year}-${month}-${day}`, start: `${year}-${month}-${day} 00:00:00`, end: `${year}-${month}-${day} 23:59:59` }; } // 请求接口 async function fetchStats(dayOffset) { const { start, end } = getDateRange(dayOffset); try { const response = await fetch('https://sso.geiwohuo.com/gsp/orderPlus/list/statistics', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json;Charset=utf-8' }, body: JSON.stringify({ allocateTimeStart: start, allocateTimeEnd: end, excludeOrderType: 5, tabIndex: 1, page: 1, perPage: 50, randomId: Date.now() }) }); if (!response.ok) throw new Error(`HTTP ${response.status}`); const res = await response.json(); const info = res.info || {}; return { success: true, dateStr: getDateRange(dayOffset).dateStr, orderCount: info.orderCount || 0, orderGoodsCount: info.orderGoodsCount || 0, orderGoodsTotalPrice: info.orderGoodsTotalPrice || 0 }; } catch (err) { return { success: false, dateStr: dayOffset === -1 ? '昨天' : '今天', msg: err.message }; } } // 显示并自动隐藏 async function fetchAll() { const btn = this; createPanels(); btn.textContent = '加载中...'; btn.disabled = true; btn.style.background = '#ccc'; const [yesterday, today] = await Promise.all([ fetchStats(-1), fetchStats(0) ]); // 昨天 panelYesterday.style.display = 'block'; if (yesterday.success) { panelYesterday.innerHTML = `