tradingview-alert-dispatcher/app/static/app.js
2026-05-14 21:40:22 +08:00

30 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function updateMessageForm(scope) {
const typeSelect = scope.querySelector("[data-message-type]");
if (!typeSelect) return;
const isText = typeSelect.value === "text";
const titleLabel = scope.querySelector("[data-title-label]");
const bodyLabel = scope.querySelector("[data-body-label]");
const titleTemplate = scope.querySelector("[data-title-template]");
const bodyTemplate = scope.querySelector("[data-body-template]");
scope.classList.toggle("text-message", isText);
if (titleLabel) titleLabel.textContent = isText ? "文本标题模板" : "卡片标题模板";
if (bodyLabel) bodyLabel.textContent = isText ? "文本内容模板" : "卡片正文模板";
if (titleTemplate) {
titleTemplate.placeholder = isText ? "例如TradingView {{symbol}}" : "例如TradingView {{symbol}} {{action}}";
}
if (bodyTemplate) {
bodyTemplate.placeholder = isText ? "{{symbol}} {{timeframe}} {{strategy}} {{action}}" : "**品种**: {{symbol}}";
}
}
document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll("[data-message-form]").forEach((scope) => {
updateMessageForm(scope);
const typeSelect = scope.querySelector("[data-message-type]");
if (typeSelect) {
typeSelect.addEventListener("change", () => updateMessageForm(scope));
}
});
});