调整配置页面的按钮功能
This commit is contained in:
+75
-23
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name Mysteel 钢铁价格提取器
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 6.5
|
||||
// @version 0.8.2
|
||||
// @description 实现列表页与详情页的抓取逻辑,统一透视表导出csv/xlsx,支持多维筛选及本地缓存
|
||||
// @author ali
|
||||
// @mail solitude@hraulein.com
|
||||
@@ -172,14 +172,14 @@
|
||||
.ms-slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
|
||||
.ms-switch input:checked + .ms-slider { background-color: #1890ff; }
|
||||
.ms-switch input:checked + .ms-slider:before { transform: translateX(14px); }
|
||||
.ms-icon-btn { position: relative; }
|
||||
.ms-icon-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-icon-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; }
|
||||
.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::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; }
|
||||
</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="display:flex; align-items:center; gap:8px;">
|
||||
<span>高级筛选配置</span>
|
||||
<button id="ms-extract-options-btn" class="ms-icon-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;">
|
||||
<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;">
|
||||
<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="1 20 1 14 7 14"></polyline>
|
||||
@@ -188,6 +188,13 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="ms-extract-confirm-box" style="display:none; margin-bottom:15px; padding:10px; background:#e6f7ff; border:1px solid #91d5ff; border-radius:4px;">
|
||||
<div style="font-size:12px; color:#1890ff; margin-bottom:8px; line-height:1.4;">确定要从当前页面提取新的筛选参数吗?<br>这将会更新并覆盖现有的配置项目。</div>
|
||||
<div style="display:flex; justify-content:flex-end; gap:8px;">
|
||||
<button id="ms-extract-cancel-btn" style="background:#f5f5f5; color:#333; border:1px solid #d9d9d9; padding:2px 8px; border-radius:4px; font-size:12px; cursor:pointer; outline:none;">取消</button>
|
||||
<button id="ms-extract-confirm-action-btn" style="background:#1890ff; color:#fff; border:none; padding:2px 8px; border-radius:4px; font-size:12px; cursor:pointer; outline:none;">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-bottom:12px;">
|
||||
<div style="font-size:13px; color:#333; font-weight:bold; margin-bottom:8px;">类别:</div>
|
||||
<div id="ms-names-container" style="display:grid; grid-template-columns:repeat(5, 1fr); gap:8px 4px;">${buildCheckboxes('names', FILTER_OPTIONS.names)}</div>
|
||||
@@ -224,14 +231,25 @@
|
||||
<div id="ms-dev-options-container" style="display:${savedFilters.devMode ? 'block' : 'none'}; margin-bottom:12px;">
|
||||
<div style="display:flex; justify-content:flex-start; align-items:center; gap:10px;">
|
||||
<input type="checkbox" id="ms-debug-mode" style="display:none;" ${savedFilters.debugMode ? 'checked' : ''}>
|
||||
<button id="ms-debug-mode-btn" style="background:${savedFilters.debugMode ? '#ff4d4f' : '#f5f5f5'}; color:${savedFilters.debugMode ? '#fff' : '#999'}; border:1px solid ${savedFilters.debugMode ? '#ff4d4f' : '#d9d9d9'}; padding:4px 8px; border-radius:4px; font-size:12px; cursor:pointer; font-weight:bold; outline:none; transition:.3s;">
|
||||
<button id="ms-debug-mode-btn" class="ms-tooltip-btn" data-tooltip="跳过登录限制、账号查询权限及价格拦截直接导出" style="background:${savedFilters.debugMode ? '#ff4d4f' : '#f5f5f5'}; color:${savedFilters.debugMode ? '#fff' : '#999'}; border:1px solid ${savedFilters.debugMode ? '#ff4d4f' : '#d9d9d9'}; padding:4px 8px; border-radius:4px; font-size:12px; cursor:pointer; font-weight:bold; outline:none; transition:.3s;">
|
||||
DEBUG_MODE ${savedFilters.debugMode ? 'ON' : 'OFF'}
|
||||
</button>
|
||||
<button id="ms-reset-options-btn" title="恢复出厂设置并清除所有缓存数据" style="background:#ff4d4f; color:#fff; border:none; padding:4px 8px; border-radius:4px; font-size:12px; cursor:pointer; font-weight:bold; outline:none;">RESET</button>
|
||||
<button id="ms-reset-options-btn" class="ms-tooltip-btn" data-tooltip="恢复默认配置并清除所有缓存数据" style="background:#ff4d4f; color:#fff; border:none; padding:4px 8px; border-radius:4px; font-size:12px; cursor:pointer; font-weight:bold; outline:none;">RESET</button>
|
||||
</div>
|
||||
<div id="ms-reset-confirm-box" style="display:none; margin-top:10px; padding:10px; background:#fff2f0; border:1px solid #ffccc7; border-radius:4px;">
|
||||
<div style="font-size:12px; color:#ff4d4f; margin-bottom:8px; line-height:1.4;">确定要恢复默认配置吗?<br>这将清除所有保存的配置和提取的筛选参数。</div>
|
||||
<div style="display:flex; justify-content:flex-end; gap:8px;">
|
||||
<button id="ms-reset-cancel-btn" style="background:#f5f5f5; color:#333; border:1px solid #d9d9d9; padding:2px 8px; border-radius:4px; font-size:12px; cursor:pointer; outline:none;">取消</button>
|
||||
<button id="ms-reset-confirm-action-btn" style="background:#ff4d4f; color:#fff; border:none; padding:2px 8px; border-radius:4px; font-size:12px; cursor:pointer; outline:none;">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button id="ms-close-panel-btn" style="width:100%; padding:8px; background:#1890ff; color:#fff; border:none; border-radius:4px; cursor:pointer; font-weight:bold;">保存并关闭</button>
|
||||
<div style="display:flex; gap:10px; margin-top:15px;">
|
||||
<button id="ms-apply-btn" style="flex:1; padding:8px; background:#fff; color:#1890ff; border:1px solid #1890ff; border-radius:4px; cursor:pointer; font-weight:bold; outline:none;">应用</button>
|
||||
<button id="ms-save-btn" style="flex:1; padding:8px; background:#1890ff; color:#fff; border:none; border-radius:4px; cursor:pointer; font-weight:bold; outline:none;">保存</button>
|
||||
<button id="ms-close-btn" style="flex:1; padding:8px; background:#f5f5f5; color:#333; border:1px solid #d9d9d9; border-radius:4px; cursor:pointer; font-weight:bold; outline:none;">关闭</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// --- UI 交互逻辑 ---
|
||||
@@ -291,8 +309,17 @@
|
||||
}
|
||||
});
|
||||
|
||||
// 绑定更新筛选项目按钮事件
|
||||
// 绑定更新筛选项目相关事件
|
||||
document.getElementById('ms-extract-options-btn').addEventListener('click', () => {
|
||||
document.getElementById('ms-extract-confirm-box').style.display = 'block';
|
||||
});
|
||||
|
||||
document.getElementById('ms-extract-cancel-btn').addEventListener('click', () => {
|
||||
document.getElementById('ms-extract-confirm-box').style.display = 'none';
|
||||
});
|
||||
|
||||
document.getElementById('ms-extract-confirm-action-btn').addEventListener('click', () => {
|
||||
document.getElementById('ms-extract-confirm-box').style.display = 'none';
|
||||
const getList = (num) => {
|
||||
const ul = document.querySelector(`.table-filter-select[sort-line-num="${num}"] .table-filter-select-dropdown-list`);
|
||||
if (!ul) return [];
|
||||
@@ -303,7 +330,7 @@
|
||||
const extractedMaterials = getList('3');
|
||||
|
||||
if (extractedNames.length === 0 && extractedSpecs.length === 0 && extractedMaterials.length === 0) {
|
||||
showToast('提取失败:当前页面未发现相关的筛选列表节点!\n请确认当前在列表页或页面结构未改变。', 'error');
|
||||
showToast('筛选项目提取失败:当前页面未发现相关的筛选列表节点!\n请确认当前详情页或页面结构未改变。', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -330,37 +357,62 @@
|
||||
document.getElementById('ms-specs-container').innerHTML = buildCheckboxes('specs', FILTER_OPTIONS.specs);
|
||||
document.getElementById('ms-materials-container').innerHTML = buildCheckboxes('materials', FILTER_OPTIONS.materials);
|
||||
|
||||
const code = ` const 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);
|
||||
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(code).then(() => {
|
||||
showToast('提取成功!代码已复制到剪贴板。', 'success');
|
||||
showToast('筛选项目更新成功,配置代码已复制到剪贴板,可自行更新到脚本的 FILTER_OPTIONS 变量中', 'success');
|
||||
}).catch(() => {
|
||||
showToast('提取成功!请按 F12 前往控制台复制。', 'success');
|
||||
showToast('筛选项目更新成功,配置代码已复制到剪贴板,请按 F12 前往控制台复制。', 'success');
|
||||
});
|
||||
} else {
|
||||
showToast('提取成功!请按 F12 前往控制台复制。', 'success');
|
||||
showToast('筛选项目更新成功,请按 F12 前往控制台复制配置代码。', 'success');
|
||||
}
|
||||
});
|
||||
|
||||
// 绑定恢复出厂设置按钮事件
|
||||
// 绑定恢复默认设置相关事件
|
||||
document.getElementById('ms-reset-options-btn').addEventListener('click', () => {
|
||||
if (confirm('确定要恢复出厂设置吗?\n这将清除所有保存的配置和提取的筛选参数。')) {
|
||||
document.getElementById('ms-reset-confirm-box').style.display = 'block';
|
||||
});
|
||||
|
||||
document.getElementById('ms-reset-cancel-btn').addEventListener('click', () => {
|
||||
document.getElementById('ms-reset-confirm-box').style.display = 'none';
|
||||
});
|
||||
|
||||
document.getElementById('ms-reset-confirm-action-btn').addEventListener('click', () => {
|
||||
localStorage.removeItem('mysteel_filters');
|
||||
localStorage.removeItem('mysteel_dynamic_options');
|
||||
showToast('恢复出厂设置成功!即将刷新页面...', 'success');
|
||||
showToast('恢复默认配置成功!即将刷新页面...', 'success');
|
||||
setTimeout(() => window.location.reload(), 1000);
|
||||
}
|
||||
});
|
||||
|
||||
// 绑定保存关闭按钮事件
|
||||
document.getElementById('ms-close-panel-btn').addEventListener('click', () => {
|
||||
// 绑定底部按钮事件
|
||||
document.getElementById('ms-apply-btn').addEventListener('click', () => {
|
||||
const active = getCurrentFilters();
|
||||
saveFiltersToLocal(active); // 写入 localStorage
|
||||
saveFiltersToLocal(active);
|
||||
showToast('配置已应用', 'success');
|
||||
});
|
||||
|
||||
document.getElementById('ms-save-btn').addEventListener('click', () => {
|
||||
const active = getCurrentFilters();
|
||||
saveFiltersToLocal(active);
|
||||
panel.style.display = 'none';
|
||||
showToast('配置已保存', 'success');
|
||||
});
|
||||
|
||||
document.getElementById('ms-close-btn').addEventListener('click', () => {
|
||||
panel.style.display = 'none';
|
||||
});
|
||||
|
||||
// 点击外部关闭面板 (不保存)
|
||||
document.addEventListener('click', (e) => {
|
||||
if (panel.style.display === 'block') {
|
||||
if (!panel.contains(e.target) && !gearBtn.contains(e.target) && !tooltip.contains(e.target)) {
|
||||
panel.style.display = 'none';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
@@ -777,7 +829,7 @@
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
showToast('导出成功!已触发下载。', 'success');
|
||||
showToast('操作完成,请查看浏览器下载记录!', 'success');
|
||||
}
|
||||
|
||||
// 延时加载注入
|
||||
|
||||
Reference in New Issue
Block a user