class CustomBotControls extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.isRunning = false;
}
connectedCallback() {
this.render();
this.attachEventListeners();
}
render() {
this.shadowRoot.innerHTML = `
Bot Configuration
Stopped
Double stake after loss to recover previous losses
Risk Warning: Trading involves significant risk. Past performance does not guarantee future results.
`;
}
attachEventListeners() {
const toggleBtn = this.shadowRoot.getElementById('toggle-btn');
const strategySelect = this.shadowRoot.getElementById('strategy');
const strategyDesc = this.shadowRoot.getElementById('strategy-desc');
toggleBtn.addEventListener('click', () => {
this.isRunning = !this.isRunning;
this.updateButtonState();
// Dispatch event to main script
const event = new CustomEvent(this.isRunning ? 'start-bot' : 'stop-bot', {
bubbles: true,
composed: true
});
this.dispatchEvent(event);
// Update config
this.dispatchConfigChange();
});
strategySelect.addEventListener('change', (e) => {
const descriptions = {
martingale: 'Double stake after loss to recover previous losses',
'martingale-0.5': 'Increase stake by 50% after loss for gradual recovery',
trend: 'Follow the market trend direction',
reversal: 'Trade against the current trend',
random: 'Random entry points for testing'
};
strategyDesc.textContent = descriptions[e.target.value];
this.dispatchConfigChange();
});
// Listen for all input changes
this.shadowRoot.querySelectorAll('input, select').forEach(input => {
input.addEventListener('change', () => this.dispatchConfigChange());
});
}
updateButtonState() {
const btn = this.shadowRoot.getElementById('toggle-btn');
const status = this.shadowRoot.getElementById('bot-status');
if (this.isRunning) {
btn.className = 'toggle-btn stop-btn';
btn.innerHTML = `