From 90b6c445e2a1769cf6b48be4669d0e1a280a023a Mon Sep 17 00:00:00 2001 From: ali Date: Tue, 28 Jul 2026 15:34:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20MysteelGetMinPrice.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加登录状态查询 --- MysteelGetMinPrice.js | 54 ++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/MysteelGetMinPrice.js b/MysteelGetMinPrice.js index cdf62f5..292a2e8 100644 --- a/MysteelGetMinPrice.js +++ b/MysteelGetMinPrice.js @@ -1,11 +1,11 @@ // ==UserScript== -// @name Mysteel 钢铁价格提取器 +// @name Mysteel 钢铁价格提取器 (双擎透视+缓存+登录校验版) // @namespace http://tampermonkey.net/ -// @version 6.0 -// @description 合并列表页与详情页的抓取逻辑,统一透视表导出,支持多维筛选及本地缓存 +// @version 6.1 +// @description 合并列表页与详情页的抓取逻辑,统一透视表导出,支持多维筛选及本地缓存,加入登录状态拦截 // @author ali -// @match https://jiancai.mysteel.com/market/* -// @match https://jiancai.mysteel.com/m/* +// @match *://*.mysteel.com/market/* +// @match *://*.mysteel.com/m/* // @grant none // ==/UserScript== @@ -23,6 +23,20 @@ materials: ['HPB300', 'HRB400', 'HRB400E', 'HRB500E'] }; + // ========================================== + // 状态守卫区 + // ========================================== + + // 校验登录状态 + function isUserLoggedIn() { + // 未登录时页面存在带有 'topbar-nav-login' 类的元素 + const loginElement = document.querySelector('.topbar-nav-login'); + if (loginElement) { + return false; // 存在“登录”按钮,说明未登录 + } + return true; // 已登录 + } + // 读取本地缓存的筛选条件 function loadSavedFilters() { const saved = localStorage.getItem('mysteel_filters'); @@ -50,7 +64,9 @@ }; } - // 1. 构建交互 UI (动态适配列表/详情页) + // ========================================== + // 构建交互 UI + // ========================================== function injectUI() { if (document.getElementById('mysteel-tool-container')) return; @@ -68,7 +84,7 @@ const btn = document.createElement('button'); btn.id = 'mysteel-action-btn'; // 根据页面类型设定按钮文字 - btn.innerText = isListPage ? '🚀 批量导出' : '📊 单日导出'; + btn.innerText = isListPage ? '🚀 批量提取并透视导出' : '📊 导出当日数据(透视版)'; Object.assign(btn.style, { padding: '12px 24px', @@ -186,9 +202,15 @@ } // ========================================== - // 引擎 A: 详情页单页抓取 (复用已有逻辑) + // 引擎 A: 详情页单页抓取 // ========================================== function startSingleProcess() { + // 🔒 登录状态守卫拦截 + if (!isUserLoggedIn()) { + alert('系统检测到您未登录!\n请先登录 Mysteel 账号后再进行数据提取。'); + return; + } + const btn = document.getElementById('mysteel-action-btn'); const originalText = btn.innerText; btn.innerText = '正在提取...'; @@ -227,6 +249,12 @@ // 引擎 B: 列表页批量抓取 // ========================================== async function startBatchProcess() { + // 🔒 登录状态守卫拦截 + if (!isUserLoggedIn()) { + alert('系统检测到您未登录!\n请先登录 Mysteel 账号后再进行批量提取。'); + return; + } + const btn = document.getElementById('mysteel-action-btn'); const originalText = btn.innerText; btn.disabled = true; @@ -343,7 +371,7 @@ }); } - // 核心提取与数据清洗过滤引擎 (合并版) + // 核心提取与数据清洗过滤引擎 function extractDataFromDoc(doc, dateStr, filters) { const targetTable = doc.getElementById('marketTable'); if (!targetTable) return []; @@ -375,7 +403,7 @@ const spec = cleanText(tdSpec); const material = cleanText(tdMaterial); - // 执行多维筛选校验:如果有勾选项且当前值不在勾选项内,则拦截跳过 + // 筛选校验拦截 if (filters.names.length > 0 && !filters.names.includes(name)) continue; if (filters.specs.length > 0 && !filters.specs.includes(spec)) continue; if (filters.materials.length > 0 && !filters.materials.includes(material)) continue; @@ -400,9 +428,9 @@ return Array.from(dataMap.values()); } - // 数据透视与生成 CSV (统一导出逻辑) + // 数据透视与生成 CSV function generatePivotCSV(flatData, filePrefix) { - // 1. 提取独立日期并升序排列 (保证横向展示时从老日期到新日期) + // 1. 提取独立日期并升序排列 const uniqueDates = [...new Set(flatData.map(d => d.date))].sort((a, b) => a.localeCompare(b)); // 日期格式化:将 "2026-07-24" 转为 "7/24" @@ -462,7 +490,7 @@ URL.revokeObjectURL(url); } - // 延时加载注入,保障单页框架的各种加载时序 + // 延时加载注入 window.addEventListener('load', injectUI); setTimeout(injectUI, 2000); setTimeout(injectUI, 5000);