默认主/次/次次改为 45m/15m/5m、开始时间一周;SD/CD 按 hist 摆位置和箭头;去掉笔线段背驰与第四类勾选。 Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
/* chart_tv_lifecycle.js — dispose Lightweight Charts / DOM / listeners */
|
|
|
|
/** 释放 Lightweight Charts 实例、DOM 与全局事件,避免自动刷新内存泄漏 */
|
|
function disposeTradingViewCharts() {
|
|
try {
|
|
if (window._tvInitCleanups && Array.isArray(window._tvInitCleanups)) {
|
|
window._tvInitCleanups.forEach(function (fn) { try { fn(); } catch (e) {} });
|
|
}
|
|
window._tvInitCleanups = [];
|
|
if (window._bindSyncCleanups && Array.isArray(window._bindSyncCleanups)) {
|
|
window._bindSyncCleanups.forEach(function (fn) { try { fn(); } catch (e) {} });
|
|
}
|
|
window._bindSyncCleanups = [];
|
|
if (window._tooltipCleanups && Array.isArray(window._tooltipCleanups)) {
|
|
window._tooltipCleanups.forEach(function (fn) { try { fn(); } catch (e) {} });
|
|
}
|
|
window._tooltipCleanups = [];
|
|
|
|
document.querySelectorAll(
|
|
'.volume-crosshair-line, .atr-crosshair-line, .macd-crosshair-line, .chanmacd-crosshair-line'
|
|
).forEach(function (el) { try { el.remove(); } catch (e) {} });
|
|
|
|
if (typeof clearEMA52Series === 'function') {
|
|
try { clearEMA52Series(); } catch (e) {}
|
|
}
|
|
|
|
if (tvWidget) {
|
|
['mainChart', 'volumeChart', 'macdChart', 'chanMacdChart', 'atrChart', 'sentimentChart'].forEach(function (key) {
|
|
try {
|
|
if (tvWidget[key] && typeof tvWidget[key].remove === 'function') {
|
|
tvWidget[key].remove();
|
|
}
|
|
} catch (e) {}
|
|
tvWidget[key] = null;
|
|
});
|
|
if (tvWidget.state) {
|
|
tvWidget.state.isInitialized = false;
|
|
}
|
|
}
|
|
|
|
var chartRoot = document.getElementById('tradingview_chart');
|
|
if (chartRoot) {
|
|
chartRoot.innerHTML = '';
|
|
}
|
|
} catch (e) {
|
|
console.warn('disposeTradingViewCharts 失败(可忽略):', e);
|
|
}
|
|
}
|