class CustomProxyForm extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
// Add event listeners
const submitBtn = this.shadowRoot.getElementById('submit-btn');
const urlInput = this.shadowRoot.getElementById('url-input');
const proxyToggle = this.shadowRoot.getElementById('proxy-toggle');
const handleSubmit = () => {
let url = urlInput.value.trim();
// Add https:// if not present
if (!url.startsWith('http://') && !url.startsWith('https://')) {
url = 'https://' + url;
}
// Dispatch custom event
this.dispatchEvent(new CustomEvent('proxy-submit', {
detail: {
url: url,
useProxy: proxyToggle.checked
},
bubbles: true,
composed: true
}));
};
submitBtn.addEventListener('click', handleSubmit);
urlInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
handleSubmit();
}
});
}
}
customElements.define('custom-proxy-form', CustomProxyForm);