1013 lines
40 KiB
HTML
1013 lines
40 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>RomFast - Contact</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
line-height: 1.6;
|
|
margin: 0;
|
|
padding: 0;
|
|
color: #333;
|
|
background: #444;
|
|
}
|
|
|
|
/* Stiluri pentru butonul mic de generare link */
|
|
.link-button-small {
|
|
background: transparent !important;
|
|
border: none !important;
|
|
padding: 0 !important;
|
|
margin: 0 0 0 8px !important;
|
|
height: 56px !important;
|
|
width: 56px !important;
|
|
display: flex !important;
|
|
align-items: center !important;
|
|
justify-content: center !important;
|
|
cursor: pointer !important;
|
|
transition: all 0.2s ease !important;
|
|
border-radius: 6px !important;
|
|
font-size: 18px !important;
|
|
color: #3B81F6 !important;
|
|
opacity: 0.8 !important;
|
|
flex-shrink: 0 !important;
|
|
}
|
|
|
|
.link-button-small:hover {
|
|
background-color: rgba(59, 129, 246, 0.1) !important;
|
|
opacity: 1 !important;
|
|
transform: scale(1.05) !important;
|
|
}
|
|
|
|
.link-button-small:active {
|
|
transform: scale(0.95) !important;
|
|
}
|
|
|
|
.link-button-small.success {
|
|
color: #10B981 !important;
|
|
background-color: rgba(16, 185, 129, 0.1) !important;
|
|
}
|
|
|
|
.toast {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
background-color: #10B981;
|
|
color: white;
|
|
padding: 12px 20px;
|
|
border-radius: 6px;
|
|
z-index: 10000;
|
|
opacity: 0;
|
|
transform: translateX(100%);
|
|
transition: all 0.3s ease;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
font-size: 14px;
|
|
}
|
|
|
|
.toast.show {
|
|
opacity: 1;
|
|
transform: translateX(0);
|
|
}
|
|
|
|
.toast.error {
|
|
background-color: #EF4444;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<flowise-fullchatbot></flowise-fullchatbot>
|
|
|
|
<script type="module">
|
|
import Chatbot from "https://cdn.jsdelivr.net/npm/flowise-embed/dist/web.js"
|
|
|
|
// Funcție pentru a obține parametrii din URL
|
|
function getUrlParameter(name) {
|
|
try {
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const value = urlParams.get(name);
|
|
|
|
if (value === null) {
|
|
return '';
|
|
}
|
|
|
|
return value;
|
|
} catch (error) {
|
|
console.error("Eroare cu URLSearchParams:", error);
|
|
|
|
try {
|
|
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
|
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
|
var results = regex.exec(location.search);
|
|
|
|
if (results === null) {
|
|
return '';
|
|
}
|
|
|
|
let rawValue = results[1];
|
|
|
|
function safeDecodeURIComponent(str) {
|
|
str = str.replace(/\+/g, ' ');
|
|
|
|
const chunks = str.split('%');
|
|
let result = chunks[0];
|
|
|
|
for (let i = 1; i < chunks.length; i++) {
|
|
const chunk = chunks[i];
|
|
if (chunk.length >= 2) {
|
|
const hexCode = chunk.substring(0, 2);
|
|
const rest = chunk.substring(2);
|
|
|
|
if (/^[0-9A-Fa-f]{2}$/.test(hexCode)) {
|
|
try {
|
|
result += decodeURIComponent('%' + hexCode) + rest;
|
|
} catch (e) {
|
|
result += '%' + chunk;
|
|
}
|
|
} else {
|
|
result += '%' + chunk;
|
|
}
|
|
} else {
|
|
result += '%' + chunk;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
const decoded = safeDecodeURIComponent(rawValue);
|
|
return decoded;
|
|
|
|
} catch (fallbackError) {
|
|
console.error("Eroare și la fallback sigur:", fallbackError);
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Obține mesajul inițial din parametrul URL (dacă există)
|
|
const initialMessage = getUrlParameter('message');
|
|
|
|
// Definește prompt-urile inițiale standard
|
|
const defaultStarterPrompts = [
|
|
'Cum se actualizeaza tokenul eFactura?',
|
|
'Cand se completeaza codul de plata pentru declaratia SAFT?',
|
|
'Cum se configurează o politică de prețuri? Afișeaza pașii complet',
|
|
'Care sunt pasii pentru emiterea unei facturi service auto?',
|
|
'Cum se valideaza o comanda service auto?',
|
|
'Cum se deschide o comanda service auto?',
|
|
'Cum se modifica datele initiale ale unei comenzi service auto (ex: nr. km)?'
|
|
];
|
|
|
|
// Determină dacă să afișeze prompt-urile inițiale sau nu
|
|
const starterPrompts = initialMessage ? [] : defaultStarterPrompts;
|
|
|
|
// Inițializează chatbot-ul
|
|
const chatbotInstance = Chatbot.initFull({
|
|
chatflowid: "d4911620-07fe-41f8-adb4-f2f52d6ec766",
|
|
apiHost: "https://mutual-special-koala.ngrok-free.app",
|
|
theme: {
|
|
chatWindow: {
|
|
showTitle: true,
|
|
title: 'Maria ChatBot - Romfast Suport',
|
|
titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
|
|
showAgentMessages: true,
|
|
welcomeMessage: 'Bună! Eu sunt Maria, specialistul dvs. de suport tehnic Romfast. Sunt aici pentru a vă ajuta cu orice întrebări sau probleme tehnice legate de utilizarea sistemului ROA. Cum vă pot ajuta astăzi?',
|
|
errorMessage: 'Am o eroare! Revino mai tarziu',
|
|
backgroundColor: "#ffffff",
|
|
height: 700,
|
|
width: 500,
|
|
fontSize: 16,
|
|
starterPrompts: starterPrompts,
|
|
starterPromptFontSize: 15,
|
|
clearChatOnReload: true,
|
|
botMessage: {
|
|
backgroundColor: "#f7f8ff",
|
|
textColor: "#303235",
|
|
showAvatar: true,
|
|
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png",
|
|
},
|
|
userMessage: {
|
|
backgroundColor: "#3B81F6",
|
|
textColor: "#ffffff",
|
|
showAvatar: true,
|
|
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png",
|
|
},
|
|
textInput: {
|
|
placeholder: 'Scrieți întrebarea dvs.',
|
|
backgroundColor: '#ffffff',
|
|
textColor: '#303235',
|
|
sendButtonColor: '#3B81F6',
|
|
maxChars: 2000,
|
|
maxCharsWarningMessage: 'Ați depășit limita de caractere. Vă rugăm să introduceți mai puțin de 2000 de caractere.',
|
|
autoFocus: true,
|
|
sendMessageSound: false,
|
|
receiveMessageSound: false,
|
|
},
|
|
feedback: {
|
|
color: '#303235',
|
|
},
|
|
footer: {
|
|
textColor: '#303235',
|
|
text: 'Powered by',
|
|
company: 'Romfast',
|
|
companyLink: 'https://www.romfast.ro',
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// Funcție pentru a afișa toast-ul
|
|
function showToast(message, type = 'success') {
|
|
const toast = document.createElement('div');
|
|
toast.className = 'toast';
|
|
toast.textContent = message;
|
|
|
|
if (type === 'error') {
|
|
toast.classList.add('error');
|
|
}
|
|
|
|
document.body.appendChild(toast);
|
|
|
|
setTimeout(() => {
|
|
toast.classList.add('show');
|
|
}, 100);
|
|
|
|
setTimeout(() => {
|
|
toast.classList.remove('show');
|
|
setTimeout(() => {
|
|
if (document.body.contains(toast)) {
|
|
document.body.removeChild(toast);
|
|
}
|
|
}, 300);
|
|
}, 3000);
|
|
}
|
|
|
|
// Funcție pentru a găsi textarea-ul chatbot-ului cu MutationObserver
|
|
function waitForChatbotInput() {
|
|
return new Promise((resolve) => {
|
|
const selectors = [
|
|
'textarea',
|
|
'input[type="text"]',
|
|
'input',
|
|
'textarea[placeholder*="Scrieți întrebarea"]',
|
|
'textarea[placeholder*="Type your message"]',
|
|
'.text-input',
|
|
'[contenteditable="true"]',
|
|
'[class*="text-input"]',
|
|
'[class*="textarea"]',
|
|
'[class*="input"]'
|
|
];
|
|
|
|
function searchInShadowDOM() {
|
|
const chatbotElement = document.querySelector('flowise-fullchatbot');
|
|
if (chatbotElement && chatbotElement.shadowRoot) {
|
|
for (const selector of selectors) {
|
|
const elements = chatbotElement.shadowRoot.querySelectorAll(selector);
|
|
for (const element of elements) {
|
|
if (element.offsetParent !== null && !element.disabled && !element.readOnly) {
|
|
return element;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
for (const selector of selectors) {
|
|
const elements = document.querySelectorAll(selector);
|
|
for (const element of elements) {
|
|
if (element.offsetParent !== null && !element.disabled && !element.readOnly) {
|
|
resolve(element);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
const shadowElement = searchInShadowDOM();
|
|
if (shadowElement) {
|
|
resolve(shadowElement);
|
|
return;
|
|
}
|
|
|
|
const observer = new MutationObserver((mutations) => {
|
|
for (const selector of selectors) {
|
|
const elements = document.querySelectorAll(selector);
|
|
for (const element of elements) {
|
|
if (element.offsetParent !== null && !element.disabled && !element.readOnly) {
|
|
observer.disconnect();
|
|
resolve(element);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
const shadowElement = searchInShadowDOM();
|
|
if (shadowElement) {
|
|
observer.disconnect();
|
|
resolve(shadowElement);
|
|
return;
|
|
}
|
|
});
|
|
|
|
observer.observe(document.body, {
|
|
childList: true,
|
|
subtree: true
|
|
});
|
|
|
|
setTimeout(() => {
|
|
observer.disconnect();
|
|
console.error('❌ Nu s-a găsit textarea-ul chatbot-ului în 15 secunde');
|
|
resolve(null);
|
|
}, 15000);
|
|
});
|
|
}
|
|
|
|
// Funcție avansată pentru a simula comportamentul real al utilizatorului
|
|
async function simulateRealUserTyping(textarea, message) {
|
|
console.log('🎯 Simulez comportamentul real al utilizatorului...');
|
|
|
|
// Focalizare reală
|
|
textarea.focus();
|
|
await sleep(100);
|
|
|
|
// Curăță textarea-ul complet
|
|
textarea.value = '';
|
|
|
|
// Simulează click în textarea
|
|
const clickEvent = new MouseEvent('click', {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
view: window,
|
|
clientX: textarea.getBoundingClientRect().left + 10,
|
|
clientY: textarea.getBoundingClientRect().top + 10
|
|
});
|
|
textarea.dispatchEvent(clickEvent);
|
|
await sleep(50);
|
|
|
|
// Tastare lentă și realistă
|
|
for (let i = 0; i < message.length; i++) {
|
|
const char = message[i];
|
|
const isLetter = /[a-zA-ZăîâțșĂÎÂȚȘ]/.test(char);
|
|
const isSpace = char === ' ';
|
|
|
|
// Simulates keydown
|
|
const keydownEvent = new KeyboardEvent('keydown', {
|
|
key: char,
|
|
code: isLetter ? `Key${char.toUpperCase()}` : (isSpace ? 'Space' : `Digit${char}`),
|
|
keyCode: char.charCodeAt(0),
|
|
which: char.charCodeAt(0),
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
textarea.dispatchEvent(keydownEvent);
|
|
|
|
// Actualizeaza valoarea
|
|
textarea.value += char;
|
|
|
|
// Simulates input event
|
|
const inputEvent = new InputEvent('input', {
|
|
inputType: 'insertText',
|
|
data: char,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
textarea.dispatchEvent(inputEvent);
|
|
|
|
// Simulates keyup
|
|
const keyupEvent = new KeyboardEvent('keyup', {
|
|
key: char,
|
|
code: isLetter ? `Key${char.toUpperCase()}` : (isSpace ? 'Space' : `Digit${char}`),
|
|
keyCode: char.charCodeAt(0),
|
|
which: char.charCodeAt(0),
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
textarea.dispatchEvent(keyupEvent);
|
|
|
|
// Pauză între caractere (mai rapidă pentru spații)
|
|
await sleep(isSpace ? 30 : 80);
|
|
}
|
|
|
|
// Evenimente finale
|
|
const changeEvent = new Event('change', { bubbles: true, cancelable: true });
|
|
textarea.dispatchEvent(changeEvent);
|
|
|
|
console.log('✅ Tastarea simulată s-a terminat');
|
|
await sleep(200);
|
|
}
|
|
|
|
// Funcție pentru sleep
|
|
function sleep(ms) {
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
}
|
|
|
|
// Funcție pentru a găsi și activa butonul send
|
|
async function findAndActivateSendButton(textarea) {
|
|
console.log('🔍 Căutând și activând butonul send...');
|
|
|
|
// Caută în apropierea textarea-ului
|
|
let container = textarea.parentElement;
|
|
let sendButton = null;
|
|
|
|
// Mergi în sus prin DOM pentru a găsi containerul
|
|
for (let i = 0; i < 5; i++) {
|
|
if (!container) break;
|
|
|
|
const buttons = container.querySelectorAll('button');
|
|
for (const button of buttons) {
|
|
if (button.offsetParent !== null) {
|
|
// Analizează butonul
|
|
const hasIcon = button.querySelector('svg, i');
|
|
const className = button.className.toLowerCase();
|
|
const isNearTextarea = Math.abs(button.getBoundingClientRect().left - textarea.getBoundingClientRect().right) < 100;
|
|
|
|
console.log('🔍 Analizez buton:', {
|
|
element: button,
|
|
hasIcon: !!hasIcon,
|
|
className: className,
|
|
isNear: isNearTextarea,
|
|
disabled: button.disabled,
|
|
isdisabled: button.getAttribute('isdisabled')
|
|
});
|
|
|
|
if (hasIcon || className.includes('chatbot-button') || className.includes('send') || isNearTextarea) {
|
|
sendButton = button;
|
|
console.log('✅ Găsit buton send candidat:', button);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (sendButton) break;
|
|
container = container.parentElement;
|
|
}
|
|
|
|
// Caută și în shadow DOM
|
|
if (!sendButton) {
|
|
const chatbotElement = document.querySelector('flowise-fullchatbot');
|
|
if (chatbotElement && chatbotElement.shadowRoot) {
|
|
const buttons = chatbotElement.shadowRoot.querySelectorAll('button');
|
|
for (const button of buttons) {
|
|
if (button.offsetParent !== null) {
|
|
const hasIcon = button.querySelector('svg, i');
|
|
const className = button.className.toLowerCase();
|
|
|
|
if (hasIcon || className.includes('chatbot-button') || className.includes('send')) {
|
|
sendButton = button;
|
|
console.log('✅ Găsit buton send în shadow DOM:', button);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (sendButton) {
|
|
// Verifică și actualizează starea butonului
|
|
console.log('🔧 Activez butonul send...');
|
|
|
|
// Forțează activarea
|
|
sendButton.disabled = false;
|
|
sendButton.removeAttribute('disabled');
|
|
sendButton.setAttribute('isdisabled', 'false');
|
|
|
|
// Actualizează stilurile pentru a arăta că e activ
|
|
const currentStyle = sendButton.style.cssText;
|
|
sendButton.style.cssText = currentStyle.replace('background: transparent', 'background: #3B81F6');
|
|
sendButton.style.opacity = '1';
|
|
|
|
console.log('✅ Buton activat:', {
|
|
disabled: sendButton.disabled,
|
|
isdisabled: sendButton.getAttribute('isdisabled'),
|
|
style: sendButton.style.background
|
|
});
|
|
|
|
return sendButton;
|
|
}
|
|
|
|
console.log('❌ Nu s-a găsit butonul send');
|
|
return null;
|
|
}
|
|
|
|
// Funcție pentru trimiterea prin Enter realistă
|
|
async function sendWithEnter(textarea) {
|
|
console.log('⌨️ Încerc trimiterea cu Enter...');
|
|
|
|
// Focus pe textarea
|
|
textarea.focus();
|
|
await sleep(100);
|
|
|
|
// Simulează apăsarea Enter
|
|
const enterKeydown = new KeyboardEvent('keydown', {
|
|
key: 'Enter',
|
|
code: 'Enter',
|
|
keyCode: 13,
|
|
which: 13,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
|
|
const enterKeypress = new KeyboardEvent('keypress', {
|
|
key: 'Enter',
|
|
code: 'Enter',
|
|
keyCode: 13,
|
|
which: 13,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
|
|
const enterKeyup = new KeyboardEvent('keyup', {
|
|
key: 'Enter',
|
|
code: 'Enter',
|
|
keyCode: 13,
|
|
which: 13,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
|
|
textarea.dispatchEvent(enterKeydown);
|
|
await sleep(50);
|
|
textarea.dispatchEvent(enterKeypress);
|
|
await sleep(50);
|
|
textarea.dispatchEvent(enterKeyup);
|
|
|
|
console.log('✅ Enter trimis');
|
|
}
|
|
|
|
// Funcția principală pentru injectarea mesajului
|
|
async function injectMessageIntoChat(message) {
|
|
try {
|
|
console.log('🚀 Începe injectarea avansată a mesajului:', message);
|
|
showToast('Se încarcă întrebarea din link...', 'success');
|
|
|
|
// Așteaptă încărcarea completă
|
|
await sleep(3000);
|
|
|
|
// Găsește textarea-ul
|
|
const textarea = await waitForChatbotInput();
|
|
if (!textarea) {
|
|
console.error('❌ Nu s-a găsit textarea-ul');
|
|
showToast('Nu s-a putut găsi casuta de chat.', 'error');
|
|
return;
|
|
}
|
|
|
|
console.log('✅ Textarea găsit:', textarea);
|
|
|
|
// *** CRUCIAL: Simulează interacțiunea reală a utilizatorului ***
|
|
await simulateRealUserInteraction(textarea, message);
|
|
|
|
// Așteaptă puțin după "tastare"
|
|
await sleep(1000);
|
|
|
|
// Încearcă să găsească și să activeze butonul
|
|
const sendButton = await findAndActivateSendButton(textarea);
|
|
|
|
if (sendButton) {
|
|
console.log('🎯 Încerc click pe butonul send...');
|
|
await attemptButtonClick(sendButton);
|
|
|
|
// Verifică dacă a funcționat
|
|
await sleep(1000);
|
|
if (textarea.value.trim() === message.trim()) {
|
|
console.log('⚠️ Butonul nu a funcționat, încerc Enter...');
|
|
await sendWithEnter(textarea);
|
|
}
|
|
} else {
|
|
console.log('⚠️ Nu s-a găsit butonul, încerc direct cu Enter...');
|
|
await sendWithEnter(textarea);
|
|
}
|
|
|
|
// Monitorizează succesul
|
|
await monitorSendingSuccess(textarea, message);
|
|
|
|
// Curăță URL-ul
|
|
const url = new URL(window.location.href);
|
|
url.searchParams.delete('message');
|
|
window.history.replaceState({}, document.title, url.toString());
|
|
|
|
} catch (error) {
|
|
console.error('❌ Eroare:', error);
|
|
showToast('A apărut o eroare. Introduceți manual întrebarea.', 'error');
|
|
}
|
|
}
|
|
|
|
// Funcție pentru a simula interacțiunea reală a utilizatorului
|
|
async function simulateRealUserInteraction(textarea, message) {
|
|
console.log('🎭 Simulez interacțiunea reală a utilizatorului...');
|
|
|
|
// Pas 1: Focus și click real
|
|
textarea.focus();
|
|
await sleep(100);
|
|
|
|
// Simulează click în textarea cu coordonate reale
|
|
const rect = textarea.getBoundingClientRect();
|
|
const clickEvent = new MouseEvent('click', {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
view: window,
|
|
clientX: rect.left + 20,
|
|
clientY: rect.top + rect.height / 2
|
|
});
|
|
textarea.dispatchEvent(clickEvent);
|
|
await sleep(100);
|
|
|
|
// Pas 2: Curăță textarea-ul complet
|
|
textarea.value = '';
|
|
const clearInputEvent = new InputEvent('input', {
|
|
inputType: 'deleteContentBackward',
|
|
bubbles: true,
|
|
cancelable: true
|
|
});
|
|
textarea.dispatchEvent(clearInputEvent);
|
|
await sleep(100);
|
|
|
|
// Pas 3: Tastează mesajul caracter cu caracter (simulare ultra-realistă)
|
|
for (let i = 0; i < message.length; i++) {
|
|
const char = message[i];
|
|
|
|
// Simulează keydown
|
|
const keydownEvent = new KeyboardEvent('keydown', {
|
|
key: char,
|
|
code: getKeyCode(char),
|
|
keyCode: char.charCodeAt(0),
|
|
which: char.charCodeAt(0),
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
textarea.dispatchEvent(keydownEvent);
|
|
|
|
// Adaugă caracterul
|
|
textarea.value += char;
|
|
|
|
// Simulează input event (crucial pentru Flowise)
|
|
const inputEvent = new InputEvent('input', {
|
|
inputType: 'insertText',
|
|
data: char,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
textarea.dispatchEvent(inputEvent);
|
|
|
|
// Simulează keyup
|
|
const keyupEvent = new KeyboardEvent('keyup', {
|
|
key: char,
|
|
code: getKeyCode(char),
|
|
keyCode: char.charCodeAt(0),
|
|
which: char.charCodeAt(0),
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
textarea.dispatchEvent(keyupEvent);
|
|
|
|
// Pauză realistă între caractere
|
|
await sleep(char === ' ' ? 40 : 60);
|
|
}
|
|
|
|
// Pas 4: Evenimente finale pentru a confirma că tastarea s-a terminat
|
|
const changeEvent = new Event('change', { bubbles: true, cancelable: true });
|
|
textarea.dispatchEvent(changeEvent);
|
|
|
|
// Simulează că utilizatorul a terminat de tastat (blur apoi focus)
|
|
const blurEvent = new FocusEvent('blur', { bubbles: true, cancelable: true });
|
|
textarea.dispatchEvent(blurEvent);
|
|
await sleep(50);
|
|
|
|
const focusEvent = new FocusEvent('focus', { bubbles: true, cancelable: true });
|
|
textarea.dispatchEvent(focusEvent);
|
|
|
|
console.log('✅ Simularea interacțiunii s-a terminat');
|
|
}
|
|
|
|
// Funcție pentru a obține codul tastei
|
|
function getKeyCode(char) {
|
|
if (char === ' ') return 'Space';
|
|
if (/[a-zA-Z]/.test(char)) return `Key${char.toUpperCase()}`;
|
|
if (/[0-9]/.test(char)) return `Digit${char}`;
|
|
if (char === '?') return 'Slash';
|
|
if (char === '.') return 'Period';
|
|
if (char === ',') return 'Comma';
|
|
return 'Key' + char.toUpperCase();
|
|
}
|
|
|
|
// Funcție pentru a încerca click pe buton cu mai multe metode
|
|
async function attemptButtonClick(button) {
|
|
console.log('🖱️ Încerc multiple metode de click...');
|
|
|
|
// Metoda 1: Simulează hover apoi click
|
|
const hoverEvent = new MouseEvent('mouseenter', {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
view: window
|
|
});
|
|
button.dispatchEvent(hoverEvent);
|
|
await sleep(100);
|
|
|
|
// Metoda 2: Click cu coordonate exacte
|
|
const rect = button.getBoundingClientRect();
|
|
const realClick = new MouseEvent('click', {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
view: window,
|
|
button: 0,
|
|
buttons: 1,
|
|
clientX: rect.left + rect.width / 2,
|
|
clientY: rect.top + rect.height / 2
|
|
});
|
|
button.dispatchEvent(realClick);
|
|
await sleep(100);
|
|
|
|
// Metoda 3: Sequence completă de mouse events
|
|
const mouseDown = new MouseEvent('mousedown', {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
button: 0,
|
|
buttons: 1
|
|
});
|
|
button.dispatchEvent(mouseDown);
|
|
await sleep(50);
|
|
|
|
const mouseUp = new MouseEvent('mouseup', {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
button: 0,
|
|
buttons: 0
|
|
});
|
|
button.dispatchEvent(mouseUp);
|
|
await sleep(50);
|
|
|
|
// Metoda 4: Click simplu ca backup
|
|
button.click();
|
|
|
|
console.log('✅ Toate metodele de click executate');
|
|
}
|
|
|
|
// Funcție pentru monitorizarea succesului trimiterii
|
|
async function monitorSendingSuccess(textarea, originalMessage) {
|
|
console.log('👀 Monitorizez succesul trimiterii...');
|
|
|
|
let attempts = 0;
|
|
const maxAttempts = 10;
|
|
|
|
const checkSuccess = async () => {
|
|
attempts++;
|
|
const currentValue = textarea.value.trim();
|
|
|
|
console.log(`🔍 Verificare #${attempts}: Conținut textarea: "${currentValue}"`);
|
|
|
|
// Dacă textarea-ul e gol sau conține alt text, mesajul a fost trimis
|
|
if (currentValue === '' || currentValue !== originalMessage.trim()) {
|
|
console.log('✅ Mesajul a fost trimis cu succes!');
|
|
showToast('Întrebarea a fost trimisă cu succes!', 'success');
|
|
return true;
|
|
}
|
|
|
|
// Dacă am epuizat încercările, încearcă o ultimă dată
|
|
if (attempts >= maxAttempts) {
|
|
console.log('❌ Mesajul nu a fost trimis după toate încercările');
|
|
console.log('🔄 Ultimă încercare cu spațiu și Enter...');
|
|
|
|
// Adaugă un spațiu la sfârșitul mesajului (ca în observația ta)
|
|
textarea.value = originalMessage + ' ';
|
|
const spaceInputEvent = new InputEvent('input', {
|
|
inputType: 'insertText',
|
|
data: ' ',
|
|
bubbles: true,
|
|
cancelable: true
|
|
});
|
|
textarea.dispatchEvent(spaceInputEvent);
|
|
|
|
// Apoi șterge spațiul
|
|
await sleep(100);
|
|
textarea.value = originalMessage;
|
|
const deleteInputEvent = new InputEvent('input', {
|
|
inputType: 'deleteContentBackward',
|
|
bubbles: true,
|
|
cancelable: true
|
|
});
|
|
textarea.dispatchEvent(deleteInputEvent);
|
|
|
|
// Încearcă Enter din nou
|
|
await sleep(100);
|
|
await sendWithEnter(textarea);
|
|
|
|
// Verifică din nou
|
|
setTimeout(() => {
|
|
if (textarea.value.trim() === originalMessage.trim()) {
|
|
showToast('Mesajul a fost încărcat. Apăsați Enter pentru a-l trimite.', 'error');
|
|
textarea.focus();
|
|
} else {
|
|
showToast('Întrebarea a fost trimisă cu succes!', 'success');
|
|
}
|
|
}, 2000);
|
|
|
|
return false;
|
|
}
|
|
|
|
// Continuă monitorizarea
|
|
setTimeout(checkSuccess, 1000);
|
|
return false;
|
|
};
|
|
|
|
// Începe monitorizarea
|
|
setTimeout(checkSuccess, 1000);
|
|
}
|
|
|
|
// Variabile pentru butonul de link
|
|
let linkButtonAdded = false;
|
|
let intervalId = null;
|
|
|
|
// Funcție pentru a adăuga butonul de link
|
|
async function addLinkButtonToInput() {
|
|
if (linkButtonAdded) return;
|
|
|
|
const textarea = await waitForChatbotInput();
|
|
if (!textarea) return;
|
|
|
|
let inputContainer = textarea.parentElement;
|
|
let attempts = 0;
|
|
|
|
while (inputContainer && attempts < 10) {
|
|
if (inputContainer.classList.contains('flex') ||
|
|
inputContainer.style.display === 'flex' ||
|
|
inputContainer.querySelector('button')) {
|
|
break;
|
|
}
|
|
inputContainer = inputContainer.parentElement;
|
|
attempts++;
|
|
}
|
|
|
|
if (!inputContainer || inputContainer.querySelector('.link-button-small')) {
|
|
linkButtonAdded = true;
|
|
if (intervalId) {
|
|
clearInterval(intervalId);
|
|
intervalId = null;
|
|
}
|
|
return;
|
|
}
|
|
|
|
const linkButton = document.createElement('button');
|
|
linkButton.className = 'link-button-small';
|
|
linkButton.innerHTML = '🔗';
|
|
linkButton.title = 'Generează link pentru această întrebare';
|
|
linkButton.type = 'button';
|
|
|
|
linkButton.style.cssText = `
|
|
background: transparent !important;
|
|
border: none !important;
|
|
padding: 0 !important;
|
|
margin: 0 0 0 8px !important;
|
|
height: 56px !important;
|
|
width: 56px !important;
|
|
display: flex !important;
|
|
align-items: center !important;
|
|
justify-content: center !important;
|
|
cursor: pointer !important;
|
|
transition: all 0.2s ease !important;
|
|
border-radius: 6px !important;
|
|
font-size: 18px !important;
|
|
color: #3B81F6 !important;
|
|
opacity: 0.8 !important;
|
|
flex-shrink: 0 !important;
|
|
z-index: 1000 !important;
|
|
`;
|
|
|
|
linkButton.addEventListener('mouseenter', () => {
|
|
linkButton.style.backgroundColor = 'rgba(59, 129, 246, 0.1)';
|
|
linkButton.style.opacity = '1';
|
|
linkButton.style.transform = 'scale(1.05)';
|
|
});
|
|
|
|
linkButton.addEventListener('mouseleave', () => {
|
|
linkButton.style.backgroundColor = 'transparent';
|
|
linkButton.style.opacity = '0.8';
|
|
linkButton.style.transform = 'scale(1)';
|
|
});
|
|
|
|
linkButton.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
generateLinkFromInput(textarea, linkButton);
|
|
});
|
|
|
|
inputContainer.appendChild(linkButton);
|
|
linkButtonAdded = true;
|
|
|
|
if (intervalId) {
|
|
clearInterval(intervalId);
|
|
intervalId = null;
|
|
}
|
|
}
|
|
|
|
// Funcție pentru generarea linkului
|
|
function generateLinkFromInput(textarea, button) {
|
|
const message = textarea.value.trim();
|
|
|
|
if (!message) {
|
|
showToast('Vă rugăm să introduceți o întrebare în casuta de chat mai întâi!', 'error');
|
|
return;
|
|
}
|
|
|
|
const url = `${window.location.origin}${window.location.pathname}?message=${encodeURIComponent(message)}`;
|
|
|
|
const originalHTML = button.innerHTML;
|
|
button.innerHTML = '✓';
|
|
button.classList.add('success');
|
|
|
|
navigator.clipboard.writeText(url).then(() => {
|
|
showToast('Link-ul a fost copiat în clipboard!');
|
|
|
|
setTimeout(() => {
|
|
button.innerHTML = originalHTML;
|
|
button.classList.remove('success');
|
|
}, 2000);
|
|
}).catch(() => {
|
|
const textArea = document.createElement('textarea');
|
|
textArea.value = url;
|
|
textArea.style.position = 'fixed';
|
|
textArea.style.opacity = '0';
|
|
document.body.appendChild(textArea);
|
|
textArea.focus();
|
|
textArea.select();
|
|
|
|
try {
|
|
document.execCommand('copy');
|
|
showToast('Link-ul a fost copiat în clipboard!');
|
|
} catch (err) {
|
|
showToast('Eroare la copierea linkului.', 'error');
|
|
}
|
|
|
|
document.body.removeChild(textArea);
|
|
|
|
setTimeout(() => {
|
|
button.innerHTML = originalHTML;
|
|
button.classList.remove('success');
|
|
}, 2000);
|
|
});
|
|
}
|
|
|
|
// Event listeners pentru adăugarea butonului
|
|
window.addEventListener('load', () => {
|
|
if (linkButtonAdded) return;
|
|
|
|
addLinkButtonToInput();
|
|
|
|
setTimeout(() => {
|
|
if (!linkButtonAdded) addLinkButtonToInput();
|
|
}, 2000);
|
|
|
|
setTimeout(() => {
|
|
if (!linkButtonAdded) addLinkButtonToInput();
|
|
}, 5000);
|
|
});
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
if (linkButtonAdded) return;
|
|
|
|
setTimeout(() => {
|
|
if (!linkButtonAdded) addLinkButtonToInput();
|
|
}, 1000);
|
|
});
|
|
|
|
intervalId = setInterval(() => {
|
|
if (linkButtonAdded) {
|
|
clearInterval(intervalId);
|
|
intervalId = null;
|
|
return;
|
|
}
|
|
|
|
const existingButton = document.querySelector('.link-button-small');
|
|
if (!existingButton) {
|
|
const textarea = document.querySelector('textarea') ||
|
|
document.querySelector('input[type="text"]');
|
|
|
|
if (textarea && textarea.offsetParent !== null) {
|
|
addLinkButtonToInput();
|
|
}
|
|
} else {
|
|
linkButtonAdded = true;
|
|
clearInterval(intervalId);
|
|
intervalId = null;
|
|
}
|
|
}, 3000);
|
|
|
|
// Injectează mesajul dacă există
|
|
if (initialMessage && initialMessage.trim() !== '') {
|
|
console.log('📨 Mesaj inițial detectat:', initialMessage);
|
|
|
|
setTimeout(() => {
|
|
injectMessageIntoChat(initialMessage);
|
|
}, 5000);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |