Compare commits

..
2 Commits
Author SHA1 Message Date
ali 3118b3096f 添加排除功能 2026-07-29 16:56:48 +08:00
ali b827b7615d 筛选项目添加"全选"按钮 2026-07-29 16:45:22 +08:00
+102 -14
View File
@@ -50,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: 'csv', exportFilename: '钢材透视价格表', debugMode: false, devMode: false };
const saved = localStorage.getItem('mysteel_filters'); const saved = localStorage.getItem('mysteel_filters');
if (saved) { if (saved) {
try { try {
@@ -70,12 +70,14 @@
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');
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,
@@ -150,7 +152,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
@@ -176,10 +178,19 @@
.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:8px 12px; 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="16" height="16" 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>
@@ -197,33 +208,47 @@
</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> </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:8px 12px; 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:72px; 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:8px 12px; 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:8px 12px; 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>
@@ -286,6 +311,40 @@
container.appendChild(gearBtn); container.appendChild(gearBtn);
document.body.appendChild(container); document.body.appendChild(container);
// 初始化及绑定全选事件
const 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;
}
});
};
['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');
@@ -358,6 +417,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);
@@ -603,12 +665,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 });
} }
@@ -690,6 +761,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);