/* Copyright (c) 2025-2026 马建军. All rights reserved. * 专有软件 — 未经授权禁止复制、传播、转售。 * 详见 LICENSE.zh-CN.txt */ (function () { var keyTimer = null; var typeEl = document.getElementById('key-type'); var rowAuto = document.getElementById('key-row-auto'); var tradeModeWrap = document.getElementById('key-trade-mode-wrap'); var directionWrap = document.getElementById('key-direction-wrap'); var rrWrap = document.getElementById('key-rr-wrap'); var rrEl = document.getElementById('key-rr'); var trailingWrap = document.getElementById('key-trailing-wrap'); var trailingHint = document.getElementById('key-trailing-hint'); var trailingEl = document.getElementById('key-trailing'); var directionEl = document.getElementById('key-direction'); function isAutoType(typ) { return typ === '箱体突破' || typ === '收敛突破'; } function isBoxType(typ) { return typ === '箱体突破'; } function syncKeyForm() { var typ = typeEl ? typeEl.value : ''; var auto = isAutoType(typ); var box = isBoxType(typ); if (rowAuto) rowAuto.classList.toggle('is-hidden', !auto); if (tradeModeWrap) tradeModeWrap.classList.toggle('is-hidden', !auto); if (rrWrap) rrWrap.classList.toggle('is-hidden', !auto); if (directionWrap) directionWrap.classList.toggle('is-hidden', !box); if (trailingWrap) trailingWrap.classList.toggle('is-hidden', !auto); if (trailingHint) trailingHint.classList.toggle('is-hidden', !auto); if (directionEl) directionEl.disabled = !box; if (!auto && trailingEl) trailingEl.checked = false; if (auto && trailingEl && trailingEl.checked && rrEl) { if (parseFloat(rrEl.value) < 3) rrEl.value = '3'; } } function fmtDist(v) { if (v === null || v === undefined) return '--'; return Number(v).toFixed(2); } function pollKeyPrices() { var list = document.getElementById('key-monitor-list'); if (!list || !list.querySelector('.key-item')) return; fetch('/api/key_prices') .then(function (r) { return r.json(); }) .then(function (rows) { rows.forEach(function (row) { var el = list.querySelector('.key-item[data-key-id="' + row.id + '"]'); if (!el) return; var priceEl = el.querySelector('.live-price'); var upEl = el.querySelector('.dist-up'); var downEl = el.querySelector('.dist-down'); if (priceEl) priceEl.textContent = row.price != null ? row.price : '--'; if (upEl) upEl.textContent = fmtDist(row.dist_upper); if (downEl) downEl.textContent = fmtDist(row.dist_lower); }); }) .catch(function () { /* ignore */ }); } function stopPolling() { if (keyTimer) { clearInterval(keyTimer); keyTimer = null; } } function startPolling() { stopPolling(); pollKeyPrices(); keyTimer = setInterval(pollKeyPrices, 1000); } function bindForm() { if (typeEl) typeEl.addEventListener('change', syncKeyForm); if (trailingEl) { trailingEl.addEventListener('change', function () { if (trailingEl.checked && rrEl && parseFloat(rrEl.value) < 3) { rrEl.value = '3'; } }); } syncKeyForm(); } if (window.qihuoPageBoot) window.qihuoPageBoot(function () { bindForm(); startPolling(); }, '#key-monitor-list'); else if (window.qihuoOnPageLoad) window.qihuoOnPageLoad(function () { bindForm(); startPolling(); }); else document.addEventListener('DOMContentLoaded', function () { bindForm(); startPolling(); }); if (window.qihuoOnPageLeave) window.qihuoOnPageLeave(stopPolling); })();