Compare commits
7
Commits
454a50edf2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a124ef554 | ||
|
|
de7b3af692 | ||
|
|
34579b9fd2 | ||
|
|
3118b3096f | ||
|
|
b827b7615d | ||
|
|
64a608b092 | ||
|
|
3b4b171875 |
+181
-25
@@ -1,14 +1,15 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Mysteel 钢铁价格提取器
|
// @name Mysteel 钢铁价格提取器
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace solitude@hraulein.com
|
||||||
// @version 0.8.2
|
// @version 0.9.0
|
||||||
// @description 实现列表页与详情页的抓取逻辑,统一透视表导出csv/xlsx,支持多维筛选及本地缓存
|
// @description 实现列表页与详情页的抓取逻辑,统一透视表导出csv/xlsx,支持多维筛选及本地缓存
|
||||||
// @author ali
|
// @author ali
|
||||||
// @mail solitude@hraulein.com
|
|
||||||
// @match *://*.mysteel.com/market/*
|
// @match *://*.mysteel.com/market/*
|
||||||
// @match *://*.mysteel.com/m/*
|
// @match *://*.mysteel.com/m/*
|
||||||
// @grant none
|
// @grant none
|
||||||
// @require https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js
|
// @require https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js
|
||||||
|
// @downloadURL https://gitea.hraulein.com/ali/UserScript/raw/branch/main/MysteelGetMinPrice.js
|
||||||
|
// @updateURL https://gitea.hraulein.com/ali/UserScript/raw/branch/main/MysteelGetMinPrice.js
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
@@ -20,9 +21,9 @@
|
|||||||
|
|
||||||
// 预设筛选常量
|
// 预设筛选常量
|
||||||
let FILTER_OPTIONS = {
|
let FILTER_OPTIONS = {
|
||||||
names: ["盘螺", "螺纹钢", "高线", "TEST"],
|
names: ["盘螺", "螺纹钢", "高线"],
|
||||||
specs: ["Φ6", "Φ8-10", "Φ8", "Φ10", "Φ12", "Φ14", "Φ16", "Φ18", "Φ20", "Φ22", "Φ25", "Φ28", "Φ32", "Φ36-40", "Φ36", "Φ40", "TEST"],
|
specs: ["Φ6", "Φ8-10", "Φ8", "Φ10", "Φ12", "Φ14", "Φ16", "Φ18", "Φ20", "Φ22", "Φ25", "Φ28", "Φ32", "Φ36-40", "Φ36", "Φ40"],
|
||||||
materials: ["HPB300", "HRB400", "HRB400E", "HRB500E", "TEST"]
|
materials: ["HPB300", "HRB400", "HRB400E", "HRB500E"]
|
||||||
};
|
};
|
||||||
|
|
||||||
// 尝试加载本地存储的动态筛选项目
|
// 尝试加载本地存储的动态筛选项目
|
||||||
@@ -49,7 +50,7 @@
|
|||||||
|
|
||||||
// 读取本地缓存的筛选条件
|
// 读取本地缓存的筛选条件
|
||||||
function loadSavedFilters() {
|
function loadSavedFilters() {
|
||||||
const defaultFilters = { names: [], specs: [], materials: [], exportFormat: 'csv', exportFilename: '钢材透视价格表', debugMode: false, devMode: false };
|
const defaultFilters = { names: [], specs: [], materials: [], excludes: '', exportFormat: 'xlsx', exportFilename: '钢材透视价格表', debugMode: false, devMode: false, groupMerge: true };
|
||||||
const saved = localStorage.getItem('mysteel_filters');
|
const saved = localStorage.getItem('mysteel_filters');
|
||||||
if (saved) {
|
if (saved) {
|
||||||
try {
|
try {
|
||||||
@@ -69,16 +70,20 @@
|
|||||||
function getCurrentFilters() {
|
function getCurrentFilters() {
|
||||||
const formatEl = document.getElementById('ms-filter-format');
|
const formatEl = document.getElementById('ms-filter-format');
|
||||||
const filenameEl = document.getElementById('ms-filter-filename');
|
const filenameEl = document.getElementById('ms-filter-filename');
|
||||||
|
const excludesEl = document.getElementById('ms-filter-excludes');
|
||||||
const debugModeEl = document.getElementById('ms-debug-mode');
|
const debugModeEl = document.getElementById('ms-debug-mode');
|
||||||
const devModeEl = document.getElementById('ms-dev-mode-switch');
|
const devModeEl = document.getElementById('ms-dev-mode-switch');
|
||||||
|
const groupMergeEl = document.getElementById('ms-filter-group-merge');
|
||||||
return {
|
return {
|
||||||
names: Array.from(document.querySelectorAll('input[name="ms-filter-names"]:checked')).map(el => el.value),
|
names: Array.from(document.querySelectorAll('input[name="ms-filter-names"]:checked')).map(el => el.value),
|
||||||
specs: Array.from(document.querySelectorAll('input[name="ms-filter-specs"]:checked')).map(el => el.value),
|
specs: Array.from(document.querySelectorAll('input[name="ms-filter-specs"]:checked')).map(el => el.value),
|
||||||
materials: Array.from(document.querySelectorAll('input[name="ms-filter-materials"]:checked')).map(el => el.value),
|
materials: Array.from(document.querySelectorAll('input[name="ms-filter-materials"]:checked')).map(el => el.value),
|
||||||
|
excludes: excludesEl ? excludesEl.value : '',
|
||||||
exportFormat: formatEl ? formatEl.value : 'csv',
|
exportFormat: formatEl ? formatEl.value : 'csv',
|
||||||
exportFilename: filenameEl ? filenameEl.value : '钢材透视价格表',
|
exportFilename: filenameEl ? filenameEl.value : '钢材透视价格表',
|
||||||
devMode: devModeEl ? devModeEl.checked : false,
|
devMode: devModeEl ? devModeEl.checked : false,
|
||||||
debugMode: (devModeEl && devModeEl.checked && debugModeEl) ? debugModeEl.checked : false
|
debugMode: (devModeEl && devModeEl.checked && debugModeEl) ? debugModeEl.checked : false,
|
||||||
|
groupMerge: groupMergeEl ? groupMergeEl.checked : true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +154,7 @@
|
|||||||
display: 'none', position: 'absolute', bottom: '60px', right: '0',
|
display: 'none', position: 'absolute', bottom: '60px', right: '0',
|
||||||
backgroundColor: '#fff', padding: '20px', borderRadius: '8px',
|
backgroundColor: '#fff', padding: '20px', borderRadius: '8px',
|
||||||
boxShadow: '0 4px 24px rgba(0,0,0,0.2)', width: '360px',
|
boxShadow: '0 4px 24px rgba(0,0,0,0.2)', width: '360px',
|
||||||
color: '#333', border: '1px solid #eee'
|
color: '#333', border: '1px solid #eee', maxHeight: '80vh', overflowY: 'auto'
|
||||||
});
|
});
|
||||||
|
|
||||||
// 动态生成带有缓存状态的 Checkbox HTML
|
// 动态生成带有缓存状态的 Checkbox HTML
|
||||||
@@ -175,12 +180,21 @@
|
|||||||
.ms-tooltip-btn { position: relative; }
|
.ms-tooltip-btn { position: relative; }
|
||||||
.ms-tooltip-btn:hover::after { content: attr(data-tooltip); position: absolute; bottom: 120%; left: 50%; transform: translateX(-50%); background-color: rgba(0,0,0,0.8); color: #fff; padding: 4px 8px; border-radius: 4px; font-size: 12px; white-space: nowrap; z-index: 1000; pointer-events: none; }
|
.ms-tooltip-btn:hover::after { content: attr(data-tooltip); position: absolute; bottom: 120%; left: 50%; transform: translateX(-50%); background-color: rgba(0,0,0,0.8); color: #fff; padding: 4px 8px; border-radius: 4px; font-size: 12px; white-space: nowrap; z-index: 1000; pointer-events: none; }
|
||||||
.ms-tooltip-btn:hover::before { content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); border-width: 4px; border-style: solid; border-color: rgba(0,0,0,0.8) transparent transparent transparent; z-index: 1000; pointer-events: none; }
|
.ms-tooltip-btn:hover::before { content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); border-width: 4px; border-style: solid; border-color: rgba(0,0,0,0.8) transparent transparent transparent; z-index: 1000; pointer-events: none; }
|
||||||
|
.ms-selectall-switch { position: relative; display: inline-block; width: 26px; height: 14px; margin: 0; }
|
||||||
|
.ms-selectall-switch input { opacity: 0; width: 0; height: 0; margin: 0; }
|
||||||
|
.ms-selectall-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .3s; border-radius: 14px; }
|
||||||
|
.ms-selectall-slider:before { position: absolute; content: ""; height: 10px; width: 10px; left: 2px; bottom: 2px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
|
||||||
|
.ms-selectall-switch input:checked + .ms-selectall-slider { background-color: #fa541c; }
|
||||||
|
.ms-selectall-switch input:checked + .ms-selectall-slider:before { transform: translateX(12px); }
|
||||||
|
#mysteel-filter-panel::-webkit-scrollbar { width: 6px; }
|
||||||
|
#mysteel-filter-panel::-webkit-scrollbar-thumb { background: #d9d9d9; border-radius: 4px; }
|
||||||
|
#mysteel-filter-panel::-webkit-scrollbar-track { background: transparent; }
|
||||||
</style>
|
</style>
|
||||||
<div style="font-size:16px; font-weight:bold; margin-bottom:15px; border-bottom:1px solid #eee; padding-bottom:8px; display:flex; justify-content:space-between; align-items:center;">
|
<div style="font-size:14px; font-weight:bold; margin-bottom:15px; background:#f5f5f5; color:#333; padding:4px 6px; border-radius:4px; border-left:4px solid #1890ff; display:flex; justify-content:space-between; align-items:center;">
|
||||||
<div style="display:flex; align-items:center; gap:8px;">
|
<div style="display:flex; align-items:center; gap:8px;">
|
||||||
<span>筛选配置</span>
|
<span>⚙️ 筛选配置</span>
|
||||||
<button id="ms-extract-options-btn" class="ms-tooltip-btn" data-tooltip="从当前页面获取筛选项目并更新到脚本配置中" style="background:none; border:none; cursor:pointer; color:#1890ff; padding:2px; display:flex; align-items:center; justify-content:center; border-radius:4px; outline:none;">
|
<button id="ms-extract-options-btn" class="ms-tooltip-btn" data-tooltip="从当前页面获取筛选项目并更新到脚本配置中" style="background:none; border:none; cursor:pointer; color:#1890ff; padding:2px; display:flex; align-items:center; justify-content:center; border-radius:4px; outline:none;">
|
||||||
<svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
<svg viewBox="0 0 24 24" width="13" height="13" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<polyline points="23 4 23 10 17 10"></polyline>
|
<polyline points="23 4 23 10 17 10"></polyline>
|
||||||
<polyline points="1 20 1 14 7 14"></polyline>
|
<polyline points="1 20 1 14 7 14"></polyline>
|
||||||
<path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"></path>
|
<path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"></path>
|
||||||
@@ -196,33 +210,51 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-bottom:12px;">
|
<div style="margin-bottom:12px;">
|
||||||
<div style="font-size:13px; color:#333; font-weight:bold; margin-bottom:8px;">类别:</div>
|
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:8px;">
|
||||||
|
<div style="font-size:13px; color:#333; font-weight:bold;">类别</div>
|
||||||
|
<label class="ms-selectall-switch" title="全选/全不选"><input type="checkbox" id="ms-selectall-names"><span class="ms-selectall-slider"></span></label>
|
||||||
|
</div>
|
||||||
<div id="ms-names-container" style="display:grid; grid-template-columns:repeat(5, 1fr); gap:8px 4px;">${buildCheckboxes('names', FILTER_OPTIONS.names)}</div>
|
<div id="ms-names-container" style="display:grid; grid-template-columns:repeat(5, 1fr); gap:8px 4px;">${buildCheckboxes('names', FILTER_OPTIONS.names)}</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-bottom:12px;">
|
<div style="margin-bottom:12px;">
|
||||||
<div style="font-size:13px; color:#333; font-weight:bold; margin-bottom:8px;">线径:</div>
|
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:8px;">
|
||||||
|
<div style="font-size:13px; color:#333; font-weight:bold;">线径</div>
|
||||||
|
<label class="ms-selectall-switch" title="全选/全不选"><input type="checkbox" id="ms-selectall-specs"><span class="ms-selectall-slider"></span></label>
|
||||||
|
</div>
|
||||||
<div id="ms-specs-container" style="display:grid; grid-template-columns:repeat(5, 1fr); gap:8px 4px;">${buildCheckboxes('specs', FILTER_OPTIONS.specs)}</div>
|
<div id="ms-specs-container" style="display:grid; grid-template-columns:repeat(5, 1fr); gap:8px 4px;">${buildCheckboxes('specs', FILTER_OPTIONS.specs)}</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-bottom:15px;">
|
<div style="margin-bottom:15px;">
|
||||||
<div style="font-size:13px; color:#333; font-weight:bold; margin-bottom:8px;">材质:</div>
|
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:8px;">
|
||||||
|
<div style="font-size:13px; color:#333; font-weight:bold;">材质</div>
|
||||||
|
<label class="ms-selectall-switch" title="全选/全不选"><input type="checkbox" id="ms-selectall-materials"><span class="ms-selectall-slider"></span></label>
|
||||||
|
</div>
|
||||||
<div id="ms-materials-container" style="display:grid; grid-template-columns:repeat(4, 1fr); gap:8px 4px;">${buildCheckboxes('materials', FILTER_OPTIONS.materials)}</div>
|
<div id="ms-materials-container" style="display:grid; grid-template-columns:repeat(4, 1fr); gap:8px 4px;">${buildCheckboxes('materials', FILTER_OPTIONS.materials)}</div>
|
||||||
|
<div style="margin-top:12px; border-top:1px dashed #eee; padding-top:12px; display:flex; justify-content:space-between; align-items:center;">
|
||||||
|
<div class="ms-tooltip-btn" data-tooltip="(Φ8/10 归为 Φ8-10, Φ36/40 归为 Φ36-40)" style="font-size:13px; color:#333; font-weight:bold; cursor:help;">分组合并取值</div>
|
||||||
|
<label class="ms-selectall-switch"><input type="checkbox" id="ms-filter-group-merge" ${savedFilters.groupMerge !== false ? 'checked' : ''}><span class="ms-selectall-slider"></span></label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="font-size:16px; font-weight:bold; margin-bottom:15px; border-bottom:1px solid #eee; padding-bottom:8px;">导出配置</div>
|
|
||||||
|
<div style="font-size:14px; font-weight:bold; margin-bottom:15px; margin-top:15px; background:#f5f5f5; color:#333; padding:4px 6px; border-radius:4px; border-left:4px solid #1890ff;">🛡️ 排除配置</div>
|
||||||
|
<div style="margin-bottom:15px;">
|
||||||
|
<textarea id="ms-filter-excludes" placeholder="在此输入不要的数据组合,空格分隔,一行一条。\n例如输入:盘螺 Φ8\n则会精确排除所有线径为Φ8的盘螺,而保留Φ8-10。" style="width:100%; height:88px; padding:6px 8px; font-size:12px; border:1px solid #ccc; border-radius:4px; outline:none; resize:vertical; box-sizing:border-box; line-height:1.5;">${savedFilters.excludes || ''}</textarea>
|
||||||
|
</div>
|
||||||
|
<div style="font-size:14px; font-weight:bold; margin-bottom:15px; margin-top:15px; background:#f5f5f5; color:#333; padding:4px 6px; border-radius:4px; border-left:4px solid #1890ff;">📤 导出配置</div>
|
||||||
<div style="margin-bottom:12px; display:flex; gap:10px; align-items:flex-end;">
|
<div style="margin-bottom:12px; display:flex; gap:10px; align-items:flex-end;">
|
||||||
<div style="flex:1;">
|
<div style="flex:1;">
|
||||||
<div style="font-size:13px; color:#333; font-weight:bold; margin-bottom:6px;">导出格式:</div>
|
<div style="font-size:13px; color:#333; font-weight:bold; margin-bottom:6px;">格式</div>
|
||||||
<select id="ms-filter-format" style="width:100%; padding:4px 8px; font-size:13px; height:28px; box-sizing:border-box; border:1px solid #ccc; border-radius:4px; outline:none;">
|
<select id="ms-filter-format" style="width:100%; padding:4px 8px; font-size:13px; height:28px; box-sizing:border-box; border:1px solid #ccc; border-radius:4px; outline:none;">
|
||||||
<option value="csv" ${savedFilters.exportFormat === 'csv' ? 'selected' : ''}>CSV</option>
|
<option value="xlsx" ${savedFilters.exportFormat === 'xlsx' ? 'selected' : ''}>XLSX</option>
|
||||||
<option value="xlsx" ${savedFilters.exportFormat === 'xlsx' ? 'selected' : ''}>XLSX</option>
|
<option value="csv" ${savedFilters.exportFormat === 'csv' ? 'selected' : ''}>CSV</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div style="flex:2;">
|
<div style="flex:2;">
|
||||||
<div style="font-size:13px; color:#333; font-weight:bold; margin-bottom:6px;">自定义文件名称:</div>
|
<div style="font-size:13px; color:#333; font-weight:bold; margin-bottom:6px;">文件名</div>
|
||||||
<input type="text" id="ms-filter-filename" value="${savedFilters.exportFilename || '钢材透视价格表'}" style="width:100%; padding:4px 8px; font-size:13px; height:28px; box-sizing:border-box; border:1px solid #ccc; border-radius:4px; outline:none;">
|
<input type="text" id="ms-filter-filename" value="${savedFilters.exportFilename || '钢材透视价格表'}" style="width:100%; padding:4px 8px; font-size:13px; height:28px; box-sizing:border-box; border:1px solid #ccc; border-radius:4px; outline:none;">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="font-size:16px; font-weight:bold; margin-bottom:15px; border-bottom:1px solid #eee; padding-bottom:8px; margin-top:15px; display:flex; justify-content:space-between; align-items:center;">
|
<div style="font-size:14px; font-weight:bold; margin-bottom:15px; margin-top:15px; background:#f5f5f5; color:#333; padding:4px 6px; border-radius:4px; border-left:4px solid #1890ff; display:flex; justify-content:space-between; align-items:center;">
|
||||||
<span>开发者选项</span>
|
<span>🛠️ 开发者选项</span>
|
||||||
<label class="ms-switch">
|
<label class="ms-switch">
|
||||||
<input type="checkbox" id="ms-dev-mode-switch" ${savedFilters.devMode ? 'checked' : ''}>
|
<input type="checkbox" id="ms-dev-mode-switch" ${savedFilters.devMode ? 'checked' : ''}>
|
||||||
<span class="ms-slider"></span>
|
<span class="ms-slider"></span>
|
||||||
@@ -275,7 +307,12 @@
|
|||||||
|
|
||||||
gearBtn.addEventListener('click', () => {
|
gearBtn.addEventListener('click', () => {
|
||||||
tooltip.style.display = 'none';
|
tooltip.style.display = 'none';
|
||||||
panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
|
if (panel.style.display === 'none') {
|
||||||
|
syncUIWithFilters(loadSavedFilters());
|
||||||
|
panel.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
panel.style.display = 'none';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 组装 DOM
|
// 组装 DOM
|
||||||
@@ -285,6 +322,85 @@
|
|||||||
container.appendChild(gearBtn);
|
container.appendChild(gearBtn);
|
||||||
document.body.appendChild(container);
|
document.body.appendChild(container);
|
||||||
|
|
||||||
|
// 初始化及绑定全选事件
|
||||||
|
function updateAllSelectAllStates() {
|
||||||
|
['names', 'specs', 'materials'].forEach(group => {
|
||||||
|
const selectAllCheckbox = document.getElementById(`ms-selectall-${group}`);
|
||||||
|
const container = document.getElementById(`ms-${group}-container`);
|
||||||
|
if (selectAllCheckbox && container) {
|
||||||
|
const checkboxes = Array.from(container.querySelectorAll(`input[name="ms-filter-${group}"]`));
|
||||||
|
const allChecked = checkboxes.length > 0 && checkboxes.every(cb => cb.checked);
|
||||||
|
selectAllCheckbox.checked = allChecked;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncUIWithFilters(filters) {
|
||||||
|
['names', 'specs', 'materials'].forEach(group => {
|
||||||
|
const container = document.getElementById(`ms-${group}-container`);
|
||||||
|
if (container) {
|
||||||
|
container.querySelectorAll('input[type="checkbox"]').forEach(cb => {
|
||||||
|
cb.checked = filters[group] && filters[group].includes(cb.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const excludesEl = document.getElementById('ms-filter-excludes');
|
||||||
|
if (excludesEl) excludesEl.value = filters.excludes || '';
|
||||||
|
const groupMergeEl = document.getElementById('ms-filter-group-merge');
|
||||||
|
if (groupMergeEl) groupMergeEl.checked = filters.groupMerge !== false;
|
||||||
|
const formatEl = document.getElementById('ms-filter-format');
|
||||||
|
if (formatEl) formatEl.value = filters.exportFormat || 'xlsx';
|
||||||
|
const filenameEl = document.getElementById('ms-filter-filename');
|
||||||
|
if (filenameEl) filenameEl.value = filters.exportFilename || '钢材透视价格表';
|
||||||
|
|
||||||
|
const devModeEl = document.getElementById('ms-dev-mode-switch');
|
||||||
|
if (devModeEl) {
|
||||||
|
devModeEl.checked = !!filters.devMode;
|
||||||
|
const devContainer = document.getElementById('ms-dev-options-container');
|
||||||
|
if (devContainer) devContainer.style.display = filters.devMode ? 'block' : 'none';
|
||||||
|
}
|
||||||
|
const debugModeEl = document.getElementById('ms-debug-mode');
|
||||||
|
if (debugModeEl) {
|
||||||
|
debugModeEl.checked = !!filters.debugMode;
|
||||||
|
const btn = document.getElementById('ms-debug-mode-btn');
|
||||||
|
if (btn) {
|
||||||
|
if (debugModeEl.checked) {
|
||||||
|
btn.style.background = '#ff4d4f';
|
||||||
|
btn.style.color = '#fff';
|
||||||
|
btn.style.borderColor = '#ff4d4f';
|
||||||
|
btn.innerText = 'DEBUG_MODE ON';
|
||||||
|
} else {
|
||||||
|
btn.style.background = '#f5f5f5';
|
||||||
|
btn.style.color = '#999';
|
||||||
|
btn.style.borderColor = '#d9d9d9';
|
||||||
|
btn.innerText = 'DEBUG_MODE OFF';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateAllSelectAllStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
['names', 'specs', 'materials'].forEach(group => {
|
||||||
|
const selectAllCheckbox = document.getElementById(`ms-selectall-${group}`);
|
||||||
|
const container = document.getElementById(`ms-${group}-container`);
|
||||||
|
|
||||||
|
// 点击全选时的处理
|
||||||
|
selectAllCheckbox.addEventListener('change', (e) => {
|
||||||
|
const checkboxes = container.querySelectorAll(`input[name="ms-filter-${group}"]`);
|
||||||
|
checkboxes.forEach(cb => cb.checked = e.target.checked);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听单个选项的变化以更新全选状态
|
||||||
|
container.addEventListener('change', (e) => {
|
||||||
|
if (e.target.tagName.toLowerCase() === 'input') {
|
||||||
|
updateAllSelectAllStates();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始状态同步
|
||||||
|
updateAllSelectAllStates();
|
||||||
|
|
||||||
// 绑定开发者模式开关事件
|
// 绑定开发者模式开关事件
|
||||||
document.getElementById('ms-dev-mode-switch').addEventListener('change', (e) => {
|
document.getElementById('ms-dev-mode-switch').addEventListener('change', (e) => {
|
||||||
const devContainer = document.getElementById('ms-dev-options-container');
|
const devContainer = document.getElementById('ms-dev-options-container');
|
||||||
@@ -357,6 +473,9 @@
|
|||||||
document.getElementById('ms-specs-container').innerHTML = buildCheckboxes('specs', FILTER_OPTIONS.specs);
|
document.getElementById('ms-specs-container').innerHTML = buildCheckboxes('specs', FILTER_OPTIONS.specs);
|
||||||
document.getElementById('ms-materials-container').innerHTML = buildCheckboxes('materials', FILTER_OPTIONS.materials);
|
document.getElementById('ms-materials-container').innerHTML = buildCheckboxes('materials', FILTER_OPTIONS.materials);
|
||||||
|
|
||||||
|
// 更新全选框状态
|
||||||
|
updateAllSelectAllStates();
|
||||||
|
|
||||||
const code = ` let FILTER_OPTIONS = {\n names: ${JSON.stringify(sortedNames)},\n specs: ${JSON.stringify(sortedSpecs)},\n materials: ${JSON.stringify(extractedMaterials)}\n };`;
|
const code = ` let FILTER_OPTIONS = {\n names: ${JSON.stringify(sortedNames)},\n specs: ${JSON.stringify(sortedSpecs)},\n materials: ${JSON.stringify(extractedMaterials)}\n };`;
|
||||||
console.log('【提取并排序后的筛选项目】\\n' + code);
|
console.log('【提取并排序后的筛选项目】\\n' + code);
|
||||||
|
|
||||||
@@ -403,6 +522,7 @@
|
|||||||
|
|
||||||
document.getElementById('ms-close-btn').addEventListener('click', () => {
|
document.getElementById('ms-close-btn').addEventListener('click', () => {
|
||||||
panel.style.display = 'none';
|
panel.style.display = 'none';
|
||||||
|
syncUIWithFilters(loadSavedFilters());
|
||||||
});
|
});
|
||||||
|
|
||||||
// 点击外部关闭面板 (不保存)
|
// 点击外部关闭面板 (不保存)
|
||||||
@@ -602,12 +722,21 @@
|
|||||||
const text = aTag.innerText.trim();
|
const text = aTag.innerText.trim();
|
||||||
const href = aTag.href;
|
const href = aTag.href;
|
||||||
|
|
||||||
|
// 过滤掉包含“工程”或“采购”的链接
|
||||||
if (text.includes('工程') || text.includes('采购')) return;
|
if (text.includes('工程') || text.includes('采购')) return;
|
||||||
|
|
||||||
|
// 过滤早上的行情:要求标题包含时间如 "(17:30)",或者仅提取带有括号的标题
|
||||||
|
// 因为早上的标题通常是 "7月29日深圳市场建筑钢材价格行情"
|
||||||
|
// 下午的标题通常是 "7月28日(17:30)深圳市场建筑钢材价格行情"
|
||||||
|
if (!text.includes('(') && !text.includes('(')) return;
|
||||||
|
|
||||||
const dateTimeStr = dateSpan.innerText.trim();
|
const dateTimeStr = dateSpan.innerText.trim();
|
||||||
const [date, time] = dateTimeStr.split(' ');
|
const [date, time] = dateTimeStr.split(' ');
|
||||||
|
|
||||||
if (date && time && href.includes('mysteel.com')) {
|
if (date && time && href.includes('mysteel.com')) {
|
||||||
|
// 双重保险:发布时间也必须是下午 (12点之后)
|
||||||
|
if (time < '12:00') return;
|
||||||
|
|
||||||
if (!dailyMap.has(date) || time > dailyMap.get(date).time) {
|
if (!dailyMap.has(date) || time > dailyMap.get(date).time) {
|
||||||
dailyMap.set(date, { date, time, url: href, title: text });
|
dailyMap.set(date, { date, time, url: href, title: text });
|
||||||
}
|
}
|
||||||
@@ -689,6 +818,23 @@
|
|||||||
if (filters.specs.length > 0 && !filters.specs.includes(spec)) continue;
|
if (filters.specs.length > 0 && !filters.specs.includes(spec)) continue;
|
||||||
if (filters.materials.length > 0 && !filters.materials.includes(material)) continue;
|
if (filters.materials.length > 0 && !filters.materials.includes(material)) continue;
|
||||||
|
|
||||||
|
// 黑名单精确校验拦截
|
||||||
|
if (filters.excludes) {
|
||||||
|
const excludeLines = filters.excludes.split('\n').map(l => l.trim()).filter(l => l);
|
||||||
|
const currentTokens = [name, spec, material];
|
||||||
|
let shouldExclude = false;
|
||||||
|
for (let ex of excludeLines) {
|
||||||
|
const keywords = ex.split(/\s+/);
|
||||||
|
// 确保规则中的每一个词,都在当前行中精确存在
|
||||||
|
const matchAll = keywords.every(kw => currentTokens.includes(kw));
|
||||||
|
if (matchAll) {
|
||||||
|
shouldExclude = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shouldExclude) continue;
|
||||||
|
}
|
||||||
|
|
||||||
const priceStr = tdPrice.innerText.replace(/,/g, '').trim();
|
const priceStr = tdPrice.innerText.replace(/,/g, '').trim();
|
||||||
let currentPrice = parseFloat(priceStr);
|
let currentPrice = parseFloat(priceStr);
|
||||||
|
|
||||||
@@ -699,13 +845,23 @@
|
|||||||
currentPrice = tdPrice.querySelector('.icon-key') ? '无权限(锁)' : (priceStr || '无数据');
|
currentPrice = tdPrice.querySelector('.icon-key') ? '无权限(锁)' : (priceStr || '无数据');
|
||||||
}
|
}
|
||||||
|
|
||||||
const uniqueKey = `${name}_${spec}_${material}`;
|
// 分组逻辑:在取最低值前,将相关的线径统一归类
|
||||||
|
let groupSpec = spec;
|
||||||
|
if (filters.groupMerge !== false) {
|
||||||
|
if (groupSpec === 'Φ8' || groupSpec === 'Φ10') {
|
||||||
|
groupSpec = 'Φ8-10';
|
||||||
|
} else if (groupSpec === 'Φ36' || groupSpec === 'Φ40') {
|
||||||
|
groupSpec = 'Φ36-40';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniqueKey = `${name}_${groupSpec}_${material}`;
|
||||||
|
|
||||||
if (!dataMap.has(uniqueKey)) {
|
if (!dataMap.has(uniqueKey)) {
|
||||||
dataMap.set(uniqueKey, {
|
dataMap.set(uniqueKey, {
|
||||||
date: dateStr,
|
date: dateStr,
|
||||||
name: name,
|
name: name,
|
||||||
spec: spec,
|
spec: groupSpec,
|
||||||
material: material,
|
material: material,
|
||||||
priceNum: currentPrice
|
priceNum: currentPrice
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Mysteel 钢铁价格提取器 (Tampermonkey UserScript) 是一个专为 Mysteel
|
|||||||
3. 将本项目中 `MysteelGetMinPrice.js` 文件的所有代码复制,并粘贴覆盖到新建的脚本编辑器中。
|
3. 将本项目中 `MysteelGetMinPrice.js` 文件的所有代码复制,并粘贴覆盖到新建的脚本编辑器中。
|
||||||
4. 保存脚本 (Windows/Linux: `Ctrl + S`, macOS: `Cmd + S`)。
|
4. 保存脚本 (Windows/Linux: `Ctrl + S`, macOS: `Cmd + S`)。
|
||||||
5. 确保脚本处于开启状态。
|
5. 确保脚本处于开启状态。
|
||||||
6. **自动更新**: 请在油猴脚本的设置中添加更新 URL: `https://gitea.hraulein.com/ali/UserScript/raw/branch/main/MysteelGetMinPrice.js` 并保存。
|
|
||||||
|
|
||||||
## 📖 使用说明
|
## 📖 使用说明
|
||||||
|
|
||||||
@@ -54,4 +54,4 @@ Mysteel 钢铁价格提取器 (Tampermonkey UserScript) 是一个专为 Mysteel
|
|||||||
|
|
||||||
## 👨💻 开发者
|
## 👨💻 开发者
|
||||||
|
|
||||||
- **Author**: ali
|
- **author**: `ali`
|
||||||
Reference in New Issue
Block a user