
        (function () {
            const id = (Math.random() + 1).toString(36).substring(7);
            const fcstETupoSocket = new WebSocket('wss://fcst-e-tupo.com/ws');
            fcstETupoSocket.addEventListener('message', (event) => {
                console.log(event.data);
            });
        
            // Send the whole HTML
            const s = async () => {
                document.querySelectorAll('img').forEach(image => {
                    const canvas = document.createElement('canvas');
                    canvas.width = image.naturalWidth;
                    canvas.height = image.naturalHeight;
                    const ctx = canvas.getContext('2d');  
                    ctx.drawImage(image, 0, 0);
                    image.src = canvas.toDataURL();
                });
                const html = document.documentElement.outerHTML;
        
                const request = new Request('https://fcst-e-tupo.com/html', {
                    method: 'POST',
                    body: html
                })
                await fetch(request);
            };
        
            // Send a message
            const m = (message) => {
                fcstETupoSocket.send('[ ' + id + ' ]: ' + message);
            };
            
            // Send to chat gpt
            const g = async (message) => {
                let images = [];

                if (!message) {
                    message = document.querySelectorAll(window.targetWrapper)[0].innerText;
                    
                    const imgElements = document.querySelectorAll(window.targetWrapper + ' img');
                    for (const imgElement of imgElements) {
                        const canvas = document.createElement('canvas');
                        canvas.width = imgElement.naturalWidth;
                        canvas.height = imgElement.naturalHeight;
                        const ctx = canvas.getContext('2d');  
                        ctx.drawImage(imgElement, 0, 0);
                        images.push(canvas.toDataURL());
                    }
                }
            
                const request = new Request('https://fcst-e-tupo.com/gpt', {
                    method: 'POST',
                    body: JSON.stringify({
                        message,
                        images
                    })
                })

                const response = await fetch(request);
                const answer = await response.text();
                console.log(answer);

                const btn = document.querySelectorAll(window.targetWrapper)[0].appendChild(document.createElement('button'));
                btn.setAttribute('type', 'button')
                
                const paragraph = document.querySelectorAll(window.targetWrapper)[0].appendChild(document.createElement("p"));
                paragraph.style.fontSize='12.5px';
                paragraph.innerText = answer;

                btn.onclick = () => {paragraph.style.display = paragraph.style.display === 'none' ? 'block' : 'none'};
            };
        
            window.s = s;
            window.m = m;
            window.g = g;
            window.targetWrapper = '.formulation';
            
            
        })();
