Spaces:
Running
Running
Manual changes saved
Browse files- injector.js +97 -126
injector.js
CHANGED
|
@@ -1,36 +1,33 @@
|
|
| 1 |
// Hugging Face AI Injector - Versão Corrigida
|
| 2 |
// Este script injeta funcionalidades automatizadas nas páginas do Hugging Face
|
| 3 |
-
|
| 4 |
(function() {
|
| 5 |
'use strict';
|
| 6 |
-
|
| 7 |
// Verificar se já foi injetado
|
| 8 |
if (window.hfInjectorLoaded) {
|
| 9 |
console.log('HF Injector já foi carregado');
|
| 10 |
return;
|
| 11 |
}
|
| 12 |
window.hfInjectorLoaded = true;
|
| 13 |
-
|
| 14 |
// Aguardar a página carregar completamente
|
| 15 |
function waitForElement(selector, callback, maxAttempts = 50) {
|
| 16 |
let attempts = 0;
|
| 17 |
-
|
| 18 |
function check() {
|
| 19 |
attempts++;
|
| 20 |
const element = document.querySelector(selector);
|
| 21 |
-
|
| 22 |
if (element) {
|
| 23 |
callback(element);
|
| 24 |
} else if (attempts < maxAttempts) {
|
| 25 |
setTimeout(check, 200);
|
| 26 |
} else {
|
|
|
|
| 27 |
console.error(`Elemento não encontrado após ${maxAttempts} tentativas: ${selector}`);
|
| 28 |
}
|
| 29 |
}
|
| 30 |
-
|
| 31 |
check();
|
| 32 |
}
|
| 33 |
-
|
| 34 |
// Injetar o painel de controle
|
| 35 |
function injectControlPanel() {
|
| 36 |
// Remover painel existente se houver
|
|
@@ -38,78 +35,56 @@
|
|
| 38 |
if (existingPanel) {
|
| 39 |
existingPanel.remove();
|
| 40 |
}
|
| 41 |
-
|
| 42 |
// Criar painel
|
| 43 |
const panel = document.createElement('div');
|
| 44 |
panel.id = 'hf-ai-injector-panel';
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
right: 20px !important;
|
| 49 |
-
width: 320px !important;
|
| 50 |
-
background: white !important;
|
| 51 |
-
border: 2px solid #6366f1 !important;
|
| 52 |
-
border-radius: 12px !important;
|
| 53 |
-
padding: 20px !important;
|
| 54 |
-
box-shadow: 0 10px 25px rgba(0,0,0,0.2) !important;
|
| 55 |
-
z-index: 999999 !important;
|
| 56 |
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
|
| 57 |
-
font-size: 14px !important;
|
| 58 |
-
`;
|
| 59 |
-
|
| 60 |
// Determinar qual AI estamos
|
| 61 |
const isQwen = window.location.href.includes('Qwen') || window.location.href.includes('qwen');
|
| 62 |
const isZai = window.location.href.includes('zai-org') || window.location.href.includes('zai');
|
| 63 |
const aiType = isQwen ? 'Qwen' : (isZai ? 'ZAI' : 'HF Chat');
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
'</button>' : '') +
|
| 83 |
-
'</div>' +
|
| 84 |
-
'<div id="status-message" style="margin-top: 10px; padding: 8px; background: #f0f9ff; border-radius: 6px; font-size: 12px; color: #0369a1; display: none; white-space: normal; word-wrap: break-word;">' +
|
| 85 |
-
'</div>';
|
| 86 |
-
document.body.appendChild(panel);
|
| 87 |
-
|
| 88 |
// Adicionar event listeners
|
| 89 |
document.getElementById('close-injector').onclick = () => {
|
| 90 |
panel.remove();
|
| 91 |
window.hfInjectorLoaded = false;
|
| 92 |
};
|
| 93 |
-
|
| 94 |
document.getElementById('inject-prompt').onclick = injectPrompt;
|
| 95 |
document.getElementById('auto-fill').onclick = autoFillFromClipboard;
|
| 96 |
document.getElementById('extract-response').onclick = extractResponse;
|
| 97 |
-
|
| 98 |
if (isQwen) {
|
| 99 |
document.getElementById('send-to-zai').onclick = sendToZai;
|
| 100 |
}
|
| 101 |
-
|
| 102 |
showStatus('Injector ativado com sucesso!', 'success');
|
| 103 |
}
|
| 104 |
-
|
| 105 |
// Mostrar mensagem de status
|
| 106 |
function showStatus(message, type = 'info') {
|
| 107 |
const statusEl = document.getElementById('status-message');
|
| 108 |
if (!statusEl) return;
|
| 109 |
-
|
| 110 |
statusEl.textContent = message;
|
| 111 |
statusEl.style.display = 'block';
|
| 112 |
-
|
| 113 |
if (type === 'error') {
|
| 114 |
statusEl.style.background = '#fef2f2';
|
| 115 |
statusEl.style.color = '#dc2626';
|
|
@@ -120,42 +95,58 @@ document.body.appendChild(panel);
|
|
| 120 |
statusEl.style.background = '#f0f9ff';
|
| 121 |
statusEl.style.color = '#0369a1';
|
| 122 |
}
|
| 123 |
-
|
| 124 |
setTimeout(() => {
|
| 125 |
statusEl.style.display = 'none';
|
| 126 |
}, 4000);
|
| 127 |
}
|
| 128 |
-
|
| 129 |
// Injetar prompt otimizado
|
| 130 |
function injectPrompt() {
|
| 131 |
const isQwen = window.location.href.includes('Qwen') || window.location.href.includes('qwen');
|
| 132 |
let prompt;
|
|
|
|
|
|
|
| 133 |
if (isQwen) {
|
| 134 |
-
prompt =
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
} else {
|
| 147 |
-
prompt =
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
}
|
| 158 |
-
|
|
|
|
| 159 |
const selectors = [
|
| 160 |
'textarea[data-testid="chat-input"]',
|
| 161 |
'textarea[placeholder*="Message"]',
|
|
@@ -165,7 +156,7 @@ document.body.appendChild(panel);
|
|
| 165 |
'textarea',
|
| 166 |
'[contenteditable="true"]'
|
| 167 |
];
|
| 168 |
-
|
| 169 |
let textarea = null;
|
| 170 |
for (const selector of selectors) {
|
| 171 |
textarea = document.querySelector(selector);
|
|
@@ -174,23 +165,20 @@ document.body.appendChild(panel);
|
|
| 174 |
break;
|
| 175 |
}
|
| 176 |
}
|
| 177 |
-
|
| 178 |
if (textarea) {
|
| 179 |
// Tentar diferentes métodos para definir o valor
|
| 180 |
try {
|
| 181 |
if (textarea.tagName.toLowerCase() === 'textarea') {
|
| 182 |
textarea.value = prompt;
|
| 183 |
textarea.focus();
|
| 184 |
-
|
| 185 |
// Disparar eventos para garantir que o valor seja registrado
|
| 186 |
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
| 187 |
textarea.dispatchEvent(new Event('change', { bubbles: true }));
|
| 188 |
-
} else {
|
| 189 |
-
// Para contenteditable
|
| 190 |
textarea.textContent = prompt;
|
| 191 |
textarea.focus();
|
| 192 |
}
|
| 193 |
-
|
| 194 |
showStatus('Prompt injetado com sucesso!', 'success');
|
| 195 |
} catch (error) {
|
| 196 |
console.error('Erro ao injetar prompt:', error);
|
|
@@ -200,12 +188,11 @@ document.body.appendChild(panel);
|
|
| 200 |
showStatus('Campo de entrada não encontrado. Clique na caixa de texto primeiro.', 'error');
|
| 201 |
}
|
| 202 |
}
|
| 203 |
-
|
| 204 |
// Preencher automaticamente da área de transferência
|
| 205 |
async function autoFillFromClipboard() {
|
| 206 |
try {
|
| 207 |
const text = await navigator.clipboard.readText();
|
| 208 |
-
|
| 209 |
const selectors = [
|
| 210 |
'textarea[data-testid="chat-input"]',
|
| 211 |
'textarea[placeholder*="Message"]',
|
|
@@ -215,7 +202,7 @@ document.body.appendChild(panel);
|
|
| 215 |
'textarea',
|
| 216 |
'[contenteditable="true"]'
|
| 217 |
];
|
| 218 |
-
|
| 219 |
let textarea = null;
|
| 220 |
for (const selector of selectors) {
|
| 221 |
textarea = document.querySelector(selector);
|
|
@@ -223,7 +210,7 @@ document.body.appendChild(panel);
|
|
| 223 |
break;
|
| 224 |
}
|
| 225 |
}
|
| 226 |
-
|
| 227 |
if (textarea) {
|
| 228 |
try {
|
| 229 |
if (textarea.tagName.toLowerCase() === 'textarea') {
|
|
@@ -235,7 +222,6 @@ document.body.appendChild(panel);
|
|
| 235 |
textarea.textContent = text;
|
| 236 |
textarea.focus();
|
| 237 |
}
|
| 238 |
-
|
| 239 |
showStatus('Conteúdo colado com sucesso!', 'success');
|
| 240 |
} catch (error) {
|
| 241 |
console.error('Erro ao colar:', error);
|
|
@@ -249,7 +235,7 @@ document.body.appendChild(panel);
|
|
| 249 |
showStatus('Erro ao acessar área de transferência', 'error');
|
| 250 |
}
|
| 251 |
}
|
| 252 |
-
|
| 253 |
// Extrair resposta da IA
|
| 254 |
function extractResponse() {
|
| 255 |
// Tentar diferentes seletores para encontrar as mensagens
|
|
@@ -262,7 +248,7 @@ document.body.appendChild(panel);
|
|
| 262 |
'[class*="response"]',
|
| 263 |
'[class*="turn"]'
|
| 264 |
];
|
| 265 |
-
|
| 266 |
let messages = [];
|
| 267 |
for (const selector of selectors) {
|
| 268 |
messages = document.querySelectorAll(selector);
|
|
@@ -271,9 +257,10 @@ document.body.appendChild(panel);
|
|
| 271 |
break;
|
| 272 |
}
|
| 273 |
}
|
| 274 |
-
|
| 275 |
if (messages.length === 0) {
|
| 276 |
// Tentar encontrar textos que parecem ser respostas
|
|
|
|
| 277 |
const allElements = document.querySelectorAll('*');
|
| 278 |
for (const element of allElements) {
|
| 279 |
if (element.textContent && element.textContent.length > 100) {
|
|
@@ -286,11 +273,10 @@ document.body.appendChild(panel);
|
|
| 286 |
}
|
| 287 |
}
|
| 288 |
}
|
| 289 |
-
|
| 290 |
if (messages.length > 0) {
|
| 291 |
const lastMessage = messages[messages.length - 1];
|
| 292 |
let messageText = '';
|
| 293 |
-
|
| 294 |
// Tentar extrair texto de diferentes maneiras
|
| 295 |
if (lastMessage.textContent) {
|
| 296 |
messageText = lastMessage.textContent.trim();
|
|
@@ -299,7 +285,7 @@ document.body.appendChild(panel);
|
|
| 299 |
} else {
|
| 300 |
messageText = lastMessage.innerHTML.replace(/<[^>]*>/g, '').trim();
|
| 301 |
}
|
| 302 |
-
|
| 303 |
if (messageText && messageText.length > 10) {
|
| 304 |
navigator.clipboard.writeText(messageText).then(() => {
|
| 305 |
showStatus('Resposta copiada com sucesso!', 'success');
|
|
@@ -320,7 +306,7 @@ document.body.appendChild(panel);
|
|
| 320 |
showStatus('Nenhuma mensagem encontrada', 'error');
|
| 321 |
}
|
| 322 |
}
|
| 323 |
-
|
| 324 |
// Enviar para ZAI
|
| 325 |
function sendToZai() {
|
| 326 |
// Extrair resposta primeiro
|
|
@@ -330,7 +316,7 @@ document.body.appendChild(panel);
|
|
| 330 |
'.message-content',
|
| 331 |
'.markdown-body'
|
| 332 |
];
|
| 333 |
-
|
| 334 |
let messages = [];
|
| 335 |
for (const selector of selectors) {
|
| 336 |
messages = document.querySelectorAll(selector);
|
|
@@ -338,40 +324,38 @@ document.body.appendChild(panel);
|
|
| 338 |
break;
|
| 339 |
}
|
| 340 |
}
|
| 341 |
-
|
| 342 |
if (messages.length === 0) {
|
| 343 |
showStatus('Nenhuma mensagem encontrada para enviar', 'error');
|
| 344 |
return;
|
| 345 |
}
|
| 346 |
-
|
| 347 |
const lastMessage = messages[messages.length - 1];
|
| 348 |
let messageText = '';
|
| 349 |
-
|
| 350 |
if (lastMessage.textContent) {
|
| 351 |
messageText = lastMessage.textContent.trim();
|
| 352 |
} else if (lastMessage.innerText) {
|
| 353 |
messageText = lastMessage.innerText.trim();
|
| 354 |
}
|
| 355 |
-
|
| 356 |
if (messageText && messageText.length > 10) {
|
| 357 |
// Armazenar em localStorage
|
| 358 |
localStorage.setItem('qwen_to_zai_transfer', messageText);
|
| 359 |
-
|
| 360 |
// Abrir ZAI em nova aba
|
| 361 |
const zaiUrl = 'https://huggingface.co/zai-org/GLM-4.6';
|
| 362 |
window.open(zaiUrl, '_blank');
|
| 363 |
-
|
| 364 |
showStatus('Enviado para ZAI! Abrindo nova aba...', 'success');
|
| 365 |
} else {
|
| 366 |
showStatus('Não foi possível extrair o texto para enviar', 'error');
|
| 367 |
}
|
| 368 |
}
|
| 369 |
-
|
| 370 |
// Verificar dados recebidos do Qwen (apenas na página ZAI)
|
| 371 |
function checkForIncomingData() {
|
| 372 |
const isZai = window.location.href.includes('zai-org') || window.location.href.includes('zai');
|
| 373 |
if (!isZai) return;
|
| 374 |
-
|
| 375 |
const incomingData = localStorage.getItem('qwen_to_zai_transfer');
|
| 376 |
if (incomingData) {
|
| 377 |
const selectors = [
|
|
@@ -382,7 +366,7 @@ document.body.appendChild(panel);
|
|
| 382 |
'textarea',
|
| 383 |
'[contenteditable="true"]'
|
| 384 |
];
|
| 385 |
-
|
| 386 |
let textarea = null;
|
| 387 |
for (const selector of selectors) {
|
| 388 |
textarea = document.querySelector(selector);
|
|
@@ -390,7 +374,7 @@ document.body.appendChild(panel);
|
|
| 390 |
break;
|
| 391 |
}
|
| 392 |
}
|
| 393 |
-
|
| 394 |
if (textarea) {
|
| 395 |
try {
|
| 396 |
if (textarea.tagName.toLowerCase() === 'textarea') {
|
|
@@ -402,7 +386,6 @@ document.body.appendChild(panel);
|
|
| 402 |
textarea.textContent = incomingData;
|
| 403 |
textarea.focus();
|
| 404 |
}
|
| 405 |
-
|
| 406 |
showStatus('Dados do Qwen recebidos e injetados!', 'success');
|
| 407 |
localStorage.removeItem('qwen_to_zai_transfer');
|
| 408 |
} catch (error) {
|
|
@@ -412,43 +395,31 @@ document.body.appendChild(panel);
|
|
| 412 |
}
|
| 413 |
}
|
| 414 |
}
|
| 415 |
-
|
| 416 |
// Função principal de inicialização
|
| 417 |
function init() {
|
| 418 |
console.log('HF AI Injector: Inicializando...');
|
| 419 |
-
|
| 420 |
// Verificar se estamos em uma página suportada
|
| 421 |
-
const supportedUrls = [
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
'qwen',
|
| 425 |
-
'zai-org',
|
| 426 |
-
'zai'
|
| 427 |
-
];
|
| 428 |
-
|
| 429 |
-
const isSupported = supportedUrls.some(url =>
|
| 430 |
-
window.location.href.includes(url)
|
| 431 |
-
);
|
| 432 |
-
|
| 433 |
if (!isSupported) {
|
| 434 |
console.log('HF Injector: Página não suportada');
|
| 435 |
return;
|
| 436 |
}
|
| 437 |
-
|
| 438 |
// Aguardar um pouco para a página carregar
|
| 439 |
setTimeout(() => {
|
| 440 |
injectControlPanel();
|
| 441 |
-
|
| 442 |
// Verificar dados recebidos periodicamente (para ZAI)
|
| 443 |
setInterval(checkForIncomingData, 3000);
|
| 444 |
}, 1000);
|
| 445 |
}
|
| 446 |
-
|
| 447 |
// Inicializar
|
| 448 |
if (document.readyState === 'loading') {
|
| 449 |
document.addEventListener('DOMContentLoaded', init);
|
| 450 |
} else {
|
| 451 |
init();
|
| 452 |
}
|
| 453 |
-
|
| 454 |
})();
|
|
|
|
| 1 |
// Hugging Face AI Injector - Versão Corrigida
|
| 2 |
// Este script injeta funcionalidades automatizadas nas páginas do Hugging Face
|
|
|
|
| 3 |
(function() {
|
| 4 |
'use strict';
|
| 5 |
+
|
| 6 |
// Verificar se já foi injetado
|
| 7 |
if (window.hfInjectorLoaded) {
|
| 8 |
console.log('HF Injector já foi carregado');
|
| 9 |
return;
|
| 10 |
}
|
| 11 |
window.hfInjectorLoaded = true;
|
| 12 |
+
|
| 13 |
// Aguardar a página carregar completamente
|
| 14 |
function waitForElement(selector, callback, maxAttempts = 50) {
|
| 15 |
let attempts = 0;
|
|
|
|
| 16 |
function check() {
|
| 17 |
attempts++;
|
| 18 |
const element = document.querySelector(selector);
|
|
|
|
| 19 |
if (element) {
|
| 20 |
callback(element);
|
| 21 |
} else if (attempts < maxAttempts) {
|
| 22 |
setTimeout(check, 200);
|
| 23 |
} else {
|
| 24 |
+
// CORREÇÃO: Adicionadas crases ao redor da string do console.error
|
| 25 |
console.error(`Elemento não encontrado após ${maxAttempts} tentativas: ${selector}`);
|
| 26 |
}
|
| 27 |
}
|
|
|
|
| 28 |
check();
|
| 29 |
}
|
| 30 |
+
|
| 31 |
// Injetar o painel de controle
|
| 32 |
function injectControlPanel() {
|
| 33 |
// Remover painel existente se houver
|
|
|
|
| 35 |
if (existingPanel) {
|
| 36 |
existingPanel.remove();
|
| 37 |
}
|
| 38 |
+
|
| 39 |
// Criar painel
|
| 40 |
const panel = document.createElement('div');
|
| 41 |
panel.id = 'hf-ai-injector-panel';
|
| 42 |
+
// CORREÇÃO: Adicionadas aspas simples no início e no final da string CSS
|
| 43 |
+
panel.style.cssText = 'position: fixed !important; top: 20px !important; right: 20px !important; width: 320px !important; background: white !important; border: 2px solid #6366f1 !important; border-radius: 12px !important; padding: 20px !important; box-shadow: 0 10px 25px rgba(0,0,0,0.2) !important; z-index: 999999 !important; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important; font-size: 14px !important;';
|
| 44 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
// Determinar qual AI estamos
|
| 46 |
const isQwen = window.location.href.includes('Qwen') || window.location.href.includes('qwen');
|
| 47 |
const isZai = window.location.href.includes('zai-org') || window.location.href.includes('zai');
|
| 48 |
const aiType = isQwen ? 'Qwen' : (isZai ? 'ZAI' : 'HF Chat');
|
| 49 |
+
|
| 50 |
+
// CORREÇÃO: Adicionadas crases no início e no final da string HTML para permitir múltiplas linhas e template literals
|
| 51 |
+
panel.innerHTML = `
|
| 52 |
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
|
| 53 |
+
<h3 style="margin: 0; color: #333; font-size: 16px; font-weight: 600;">🤖 ${aiType} Injector</h3>
|
| 54 |
+
<button id="close-injector" style="background: none; border: none; font-size: 20px; cursor: pointer; color: #666; padding: 0; width: 24px; height: 24px;">×</button>
|
| 55 |
+
</div>
|
| 56 |
+
<div id="injector-controls">
|
| 57 |
+
<button id="inject-prompt" style="width: 100%; background: #6366f1; color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer; margin-bottom: 10px; font-weight: 500; font-size: 13px;">📝 Injetar Prompt Otimizado</button>
|
| 58 |
+
<button id="auto-fill" style="width: 100%; background: #10b981; color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer; margin-bottom: 10px; font-weight: 500; font-size: 13px;">🔄 Colar da Área de Transferência</button>
|
| 59 |
+
<button id="extract-response" style="width: 100%; background: #f59e0b; color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer; margin-bottom: 10px; font-weight: 500; font-size: 13px;">📋 Copiar Resposta</button>
|
| 60 |
+
${isQwen ? '<button id="send-to-zai" style="width: 100%; background: #8b5cf6; color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer; font-weight: 500; font-size: 13px;">➡️ Enviar para ZAI</button>' : ''}
|
| 61 |
+
</div>
|
| 62 |
+
<div id="status-message" style="margin-top: 10px; padding: 8px; background: #f0f9ff; border-radius: 6px; font-size: 12px; color: #0369a1; display: none; white-space: normal; word-wrap: break-word;"></div>
|
| 63 |
+
`;
|
| 64 |
+
|
| 65 |
+
document.body.appendChild(panel);
|
| 66 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
// Adicionar event listeners
|
| 68 |
document.getElementById('close-injector').onclick = () => {
|
| 69 |
panel.remove();
|
| 70 |
window.hfInjectorLoaded = false;
|
| 71 |
};
|
|
|
|
| 72 |
document.getElementById('inject-prompt').onclick = injectPrompt;
|
| 73 |
document.getElementById('auto-fill').onclick = autoFillFromClipboard;
|
| 74 |
document.getElementById('extract-response').onclick = extractResponse;
|
|
|
|
| 75 |
if (isQwen) {
|
| 76 |
document.getElementById('send-to-zai').onclick = sendToZai;
|
| 77 |
}
|
| 78 |
+
|
| 79 |
showStatus('Injector ativado com sucesso!', 'success');
|
| 80 |
}
|
| 81 |
+
|
| 82 |
// Mostrar mensagem de status
|
| 83 |
function showStatus(message, type = 'info') {
|
| 84 |
const statusEl = document.getElementById('status-message');
|
| 85 |
if (!statusEl) return;
|
|
|
|
| 86 |
statusEl.textContent = message;
|
| 87 |
statusEl.style.display = 'block';
|
|
|
|
| 88 |
if (type === 'error') {
|
| 89 |
statusEl.style.background = '#fef2f2';
|
| 90 |
statusEl.style.color = '#dc2626';
|
|
|
|
| 95 |
statusEl.style.background = '#f0f9ff';
|
| 96 |
statusEl.style.color = '#0369a1';
|
| 97 |
}
|
|
|
|
| 98 |
setTimeout(() => {
|
| 99 |
statusEl.style.display = 'none';
|
| 100 |
}, 4000);
|
| 101 |
}
|
| 102 |
+
|
| 103 |
// Injetar prompt otimizado
|
| 104 |
function injectPrompt() {
|
| 105 |
const isQwen = window.location.href.includes('Qwen') || window.location.href.includes('qwen');
|
| 106 |
let prompt;
|
| 107 |
+
|
| 108 |
+
// CORREÇÃO: Adicionadas crases para delimitar as strings de várias linhas
|
| 109 |
if (isQwen) {
|
| 110 |
+
prompt = `Você é um especialista em análise de código com alta autonomia.
|
| 111 |
+
|
| 112 |
+
=== TAREFA PRINCIPAL ===
|
| 113 |
+
Analise o código fornecido e identifique TODOS os problemas possíveis.
|
| 114 |
+
|
| 115 |
+
=== FORMATO DE SAÍDA OBRIGATÓRIO ===
|
| 116 |
+
Para cada arquivo com problemas:
|
| 117 |
+
nome/do/arquivo.ext
|
| 118 |
+
\`\`\`
|
| 119 |
+
"código_completo_corrigido"
|
| 120 |
+
\`\`\`
|
| 121 |
+
|
| 122 |
+
=== REGRAS ===
|
| 123 |
+
1. Use sempre aspas para delimitar o código
|
| 124 |
+
2. Inclua o caminho completo do arquivo
|
| 125 |
+
3. Forneça o código COMPLETO e corrigido
|
| 126 |
+
4. Sem explicações extras, apenas o formato acima
|
| 127 |
+
|
| 128 |
+
=== CÓDIGO PARA ANÁLISE ===`;
|
| 129 |
} else {
|
| 130 |
+
prompt = `Você é um finalizador de código.
|
| 131 |
+
|
| 132 |
+
=== TAREFA ===
|
| 133 |
+
Receba o diagnóstico do Qwen e produza o código final corrigido.
|
| 134 |
+
|
| 135 |
+
=== FORMATO EXATO ===
|
| 136 |
+
nome/do/arquivo.ext
|
| 137 |
+
\`\`\`
|
| 138 |
+
"código_final_completo"
|
| 139 |
+
\`\`\`
|
| 140 |
+
|
| 141 |
+
=== REGRAS ===
|
| 142 |
+
1. Apenas o código corrigido
|
| 143 |
+
2. Sem explicações
|
| 144 |
+
3. Formato exato acima
|
| 145 |
+
|
| 146 |
+
=== ENTRADA DO QWEN ===`;
|
| 147 |
}
|
| 148 |
+
|
| 149 |
+
// Tentar encontrar o textarea de várias maneiras
|
| 150 |
const selectors = [
|
| 151 |
'textarea[data-testid="chat-input"]',
|
| 152 |
'textarea[placeholder*="Message"]',
|
|
|
|
| 156 |
'textarea',
|
| 157 |
'[contenteditable="true"]'
|
| 158 |
];
|
| 159 |
+
|
| 160 |
let textarea = null;
|
| 161 |
for (const selector of selectors) {
|
| 162 |
textarea = document.querySelector(selector);
|
|
|
|
| 165 |
break;
|
| 166 |
}
|
| 167 |
}
|
| 168 |
+
|
| 169 |
if (textarea) {
|
| 170 |
// Tentar diferentes métodos para definir o valor
|
| 171 |
try {
|
| 172 |
if (textarea.tagName.toLowerCase() === 'textarea') {
|
| 173 |
textarea.value = prompt;
|
| 174 |
textarea.focus();
|
|
|
|
| 175 |
// Disparar eventos para garantir que o valor seja registrado
|
| 176 |
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
| 177 |
textarea.dispatchEvent(new Event('change', { bubbles: true }));
|
| 178 |
+
} else { // Para contenteditable
|
|
|
|
| 179 |
textarea.textContent = prompt;
|
| 180 |
textarea.focus();
|
| 181 |
}
|
|
|
|
| 182 |
showStatus('Prompt injetado com sucesso!', 'success');
|
| 183 |
} catch (error) {
|
| 184 |
console.error('Erro ao injetar prompt:', error);
|
|
|
|
| 188 |
showStatus('Campo de entrada não encontrado. Clique na caixa de texto primeiro.', 'error');
|
| 189 |
}
|
| 190 |
}
|
| 191 |
+
|
| 192 |
// Preencher automaticamente da área de transferência
|
| 193 |
async function autoFillFromClipboard() {
|
| 194 |
try {
|
| 195 |
const text = await navigator.clipboard.readText();
|
|
|
|
| 196 |
const selectors = [
|
| 197 |
'textarea[data-testid="chat-input"]',
|
| 198 |
'textarea[placeholder*="Message"]',
|
|
|
|
| 202 |
'textarea',
|
| 203 |
'[contenteditable="true"]'
|
| 204 |
];
|
| 205 |
+
|
| 206 |
let textarea = null;
|
| 207 |
for (const selector of selectors) {
|
| 208 |
textarea = document.querySelector(selector);
|
|
|
|
| 210 |
break;
|
| 211 |
}
|
| 212 |
}
|
| 213 |
+
|
| 214 |
if (textarea) {
|
| 215 |
try {
|
| 216 |
if (textarea.tagName.toLowerCase() === 'textarea') {
|
|
|
|
| 222 |
textarea.textContent = text;
|
| 223 |
textarea.focus();
|
| 224 |
}
|
|
|
|
| 225 |
showStatus('Conteúdo colado com sucesso!', 'success');
|
| 226 |
} catch (error) {
|
| 227 |
console.error('Erro ao colar:', error);
|
|
|
|
| 235 |
showStatus('Erro ao acessar área de transferência', 'error');
|
| 236 |
}
|
| 237 |
}
|
| 238 |
+
|
| 239 |
// Extrair resposta da IA
|
| 240 |
function extractResponse() {
|
| 241 |
// Tentar diferentes seletores para encontrar as mensagens
|
|
|
|
| 248 |
'[class*="response"]',
|
| 249 |
'[class*="turn"]'
|
| 250 |
];
|
| 251 |
+
|
| 252 |
let messages = [];
|
| 253 |
for (const selector of selectors) {
|
| 254 |
messages = document.querySelectorAll(selector);
|
|
|
|
| 257 |
break;
|
| 258 |
}
|
| 259 |
}
|
| 260 |
+
|
| 261 |
if (messages.length === 0) {
|
| 262 |
// Tentar encontrar textos que parecem ser respostas
|
| 263 |
+
// CORREÇÃO: Alterado o seletor de '' para '*' para buscar todos os elementos.
|
| 264 |
const allElements = document.querySelectorAll('*');
|
| 265 |
for (const element of allElements) {
|
| 266 |
if (element.textContent && element.textContent.length > 100) {
|
|
|
|
| 273 |
}
|
| 274 |
}
|
| 275 |
}
|
| 276 |
+
|
| 277 |
if (messages.length > 0) {
|
| 278 |
const lastMessage = messages[messages.length - 1];
|
| 279 |
let messageText = '';
|
|
|
|
| 280 |
// Tentar extrair texto de diferentes maneiras
|
| 281 |
if (lastMessage.textContent) {
|
| 282 |
messageText = lastMessage.textContent.trim();
|
|
|
|
| 285 |
} else {
|
| 286 |
messageText = lastMessage.innerHTML.replace(/<[^>]*>/g, '').trim();
|
| 287 |
}
|
| 288 |
+
|
| 289 |
if (messageText && messageText.length > 10) {
|
| 290 |
navigator.clipboard.writeText(messageText).then(() => {
|
| 291 |
showStatus('Resposta copiada com sucesso!', 'success');
|
|
|
|
| 306 |
showStatus('Nenhuma mensagem encontrada', 'error');
|
| 307 |
}
|
| 308 |
}
|
| 309 |
+
|
| 310 |
// Enviar para ZAI
|
| 311 |
function sendToZai() {
|
| 312 |
// Extrair resposta primeiro
|
|
|
|
| 316 |
'.message-content',
|
| 317 |
'.markdown-body'
|
| 318 |
];
|
| 319 |
+
|
| 320 |
let messages = [];
|
| 321 |
for (const selector of selectors) {
|
| 322 |
messages = document.querySelectorAll(selector);
|
|
|
|
| 324 |
break;
|
| 325 |
}
|
| 326 |
}
|
| 327 |
+
|
| 328 |
if (messages.length === 0) {
|
| 329 |
showStatus('Nenhuma mensagem encontrada para enviar', 'error');
|
| 330 |
return;
|
| 331 |
}
|
| 332 |
+
|
| 333 |
const lastMessage = messages[messages.length - 1];
|
| 334 |
let messageText = '';
|
| 335 |
+
|
| 336 |
if (lastMessage.textContent) {
|
| 337 |
messageText = lastMessage.textContent.trim();
|
| 338 |
} else if (lastMessage.innerText) {
|
| 339 |
messageText = lastMessage.innerText.trim();
|
| 340 |
}
|
| 341 |
+
|
| 342 |
if (messageText && messageText.length > 10) {
|
| 343 |
// Armazenar em localStorage
|
| 344 |
localStorage.setItem('qwen_to_zai_transfer', messageText);
|
|
|
|
| 345 |
// Abrir ZAI em nova aba
|
| 346 |
const zaiUrl = 'https://huggingface.co/zai-org/GLM-4.6';
|
| 347 |
window.open(zaiUrl, '_blank');
|
|
|
|
| 348 |
showStatus('Enviado para ZAI! Abrindo nova aba...', 'success');
|
| 349 |
} else {
|
| 350 |
showStatus('Não foi possível extrair o texto para enviar', 'error');
|
| 351 |
}
|
| 352 |
}
|
| 353 |
+
|
| 354 |
// Verificar dados recebidos do Qwen (apenas na página ZAI)
|
| 355 |
function checkForIncomingData() {
|
| 356 |
const isZai = window.location.href.includes('zai-org') || window.location.href.includes('zai');
|
| 357 |
if (!isZai) return;
|
| 358 |
+
|
| 359 |
const incomingData = localStorage.getItem('qwen_to_zai_transfer');
|
| 360 |
if (incomingData) {
|
| 361 |
const selectors = [
|
|
|
|
| 366 |
'textarea',
|
| 367 |
'[contenteditable="true"]'
|
| 368 |
];
|
| 369 |
+
|
| 370 |
let textarea = null;
|
| 371 |
for (const selector of selectors) {
|
| 372 |
textarea = document.querySelector(selector);
|
|
|
|
| 374 |
break;
|
| 375 |
}
|
| 376 |
}
|
| 377 |
+
|
| 378 |
if (textarea) {
|
| 379 |
try {
|
| 380 |
if (textarea.tagName.toLowerCase() === 'textarea') {
|
|
|
|
| 386 |
textarea.textContent = incomingData;
|
| 387 |
textarea.focus();
|
| 388 |
}
|
|
|
|
| 389 |
showStatus('Dados do Qwen recebidos e injetados!', 'success');
|
| 390 |
localStorage.removeItem('qwen_to_zai_transfer');
|
| 391 |
} catch (error) {
|
|
|
|
| 395 |
}
|
| 396 |
}
|
| 397 |
}
|
| 398 |
+
|
| 399 |
// Função principal de inicialização
|
| 400 |
function init() {
|
| 401 |
console.log('HF AI Injector: Inicializando...');
|
|
|
|
| 402 |
// Verificar se estamos em uma página suportada
|
| 403 |
+
const supportedUrls = ['huggingface.co', 'Qwen', 'qwen', 'zai-org', 'zai'];
|
| 404 |
+
const isSupported = supportedUrls.some(url => window.location.href.includes(url));
|
| 405 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
if (!isSupported) {
|
| 407 |
console.log('HF Injector: Página não suportada');
|
| 408 |
return;
|
| 409 |
}
|
| 410 |
+
|
| 411 |
// Aguardar um pouco para a página carregar
|
| 412 |
setTimeout(() => {
|
| 413 |
injectControlPanel();
|
|
|
|
| 414 |
// Verificar dados recebidos periodicamente (para ZAI)
|
| 415 |
setInterval(checkForIncomingData, 3000);
|
| 416 |
}, 1000);
|
| 417 |
}
|
| 418 |
+
|
| 419 |
// Inicializar
|
| 420 |
if (document.readyState === 'loading') {
|
| 421 |
document.addEventListener('DOMContentLoaded', init);
|
| 422 |
} else {
|
| 423 |
init();
|
| 424 |
}
|
|
|
|
| 425 |
})();
|