/** * DeepSeek Category Description Generator Pro - v2.0.1 */ jQuery(document).ready(function($) { 'use strict'; console.log('🚀 DeepSeek Category Description carregado!'); // ============================================ // TABS (sem jQuery UI) // ============================================ $('.deepseek-tab-btn').on('click', function() { var tabId = $(this).data('tab'); // Remove active de todos $('.deepseek-tab-btn').removeClass('active'); $('.deepseek-tab-content').removeClass('active'); // Adiciona active no clicado $(this).addClass('active'); $('#tab-' + tabId).addClass('active'); }); // ============================================ // GERAR INDIVIDUAL // ============================================ $('#deepseek-generate-single').on('click', function() { var select = $('#deepseek-category-select'); var termId = select.val(); var termName = select.find('option:selected').data('name'); if (!termId) { alert('Selecione uma categoria primeiro.'); return; } generateSingleDescription(termId, termName); }); function generateSingleDescription(termId, termName) { var $status = $('#single-status'); var $preview = $('#single-preview'); $status.html('⏳ Gerando descrição...'); $preview.hide(); $.ajax({ url: deepseek_ajax.ajax_url, type: 'POST', dataType: 'json', data: { action: 'generate_category_description', term_id: termId, term_name: termName, nonce: deepseek_ajax.nonce }, timeout: 60000, success: function(response) { console.log('Resposta:', response); if (response.success) { $preview.show(); $('.deepseek-description-content').text(response.data.description); $status.html('✅ Gerado com sucesso!'); // Salva o ID para uso no salvamento $preview.data('term-id', termId); } else { $status.html('❌ ' + (response.data || 'Erro desconhecido')); } }, error: function(xhr, status, error) { console.error('Erro:', xhr, status, error); var msg = 'Erro ao gerar descrição'; if (xhr.responseJSON && xhr.responseJSON.data) { msg = xhr.responseJSON.data; } $status.html('❌ ' + msg); } }); } // ============================================ // GERAR EM MASSA // ============================================ $('#deepseek-generate-bulk').on('click', function() { var selected = $('input[name="bulk-categories[]"]:checked'); if (selected.length === 0) { alert('Selecione pelo menos uma categoria.'); return; } var categories = []; selected.each(function() { categories.push({ id: $(this).val(), name: $(this).data('name') }); }); generateBulkDescriptions(categories); }); function generateBulkDescriptions(categories) { var $status = $('#bulk-status'); var $progress = $('#bulk-progress'); var $fill = $('.progress-fill'); var $text = $('.progress-text'); $status.html('⏳ Processando...'); $progress.show(); var completed = 0; var errors = 0; categories.forEach(function(cat, index) { setTimeout(function() { $.ajax({ url: deepseek_ajax.ajax_url, type: 'POST', dataType: 'json', data: { action: 'generate_category_description', term_id: cat.id, term_name: cat.name, nonce: deepseek_ajax.nonce, bulk: true }, success: function(response) { completed++; if (!response.success) errors++; updateProgress(completed, categories.length, errors); }, error: function() { completed++; errors++; updateProgress(completed, categories.length, errors); } }); }, index * 2000); // Delay entre requisições }); function updateProgress(completed, total, errors) { var percent = (completed / total) * 100; $fill.css('width', percent + '%'); $text.text(completed + ' / ' + total + ' (❌ ' + errors + ' erros)'); if (completed === total) { var success = total - errors; $status.html('✅ Concluído! ' + success + ' de ' + total + ' geradas.'); } } } // ============================================ // BOTÃO NA EDIÇÃO DA CATEGORIA // ============================================ $(document).on('click', '#deepseek-generate-desc', function() { var $button = $(this); var termId = $button.data('term-id'); var termName = $button.data('term-name'); var $status = $('#deepseek-status'); if (!termId || !termName) { $status.html('❌ Erro: Dados da categoria não encontrados'); return; } $button.prop('disabled', true); $status.html('⏳ Gerando...'); $.ajax({ url: deepseek_ajax.ajax_url, type: 'POST', dataType: 'json', data: { action: 'generate_category_description', term_id: termId, term_name: termName, nonce: deepseek_ajax.nonce }, timeout: 60000, success: function(response) { if (response.success) { var description = response.data.description; // Preenche no editor if (typeof tinyMCE !== 'undefined' && tinyMCE.get('description')) { tinyMCE.get('description').setContent(description); $('#description').val(description); } else { $('#description').val(description); } $status.html('✅ Gerado com sucesso!'); } else { $status.html('❌ ' + (response.data || 'Erro')); } }, error: function() { $status.html('❌ Erro ao gerar'); }, complete: function() { $button.prop('disabled', false); } }); }); // ============================================ // SALVAR PROMPT // ============================================ $('#save-prompt').on('click', function() { var prompt = $('#deepseek-custom-prompt').val(); $.ajax({ url: deepseek_ajax.ajax_url, type: 'POST', dataType: 'json', data: { action: 'save_prompt', prompt: prompt, nonce: deepseek_ajax.nonce }, success: function(response) { if (response.success) { alert('✅ Prompt salvo com sucesso!'); } else { alert('❌ Erro ao salvar: ' + response.data); } }, error: function() { alert('❌ Erro ao salvar prompt'); } }); }); $('#reset-prompt').on('click', function() { if (confirm('Restaurar prompt padrão?')) { $('#deepseek-custom-prompt').val(''); alert('✅ Prompt restaurado!'); } }); // ============================================ // FUNÇÕES GLOBAIS PARA OS BOTÕES // ============================================ window.deepseekSelectAll = function() { $('input[name="bulk-categories[]"]').prop('checked', true); }; window.deepseekDeselectAll = function() { $('input[name="bulk-categories[]"]').prop('checked', false); }; window.deepseekSelectEmpty = function() { $('input[name="bulk-categories[]"]').prop('checked', false); $('input[name="bulk-categories[]"][data-empty="true"]').prop('checked', true); }; window.deepseekCopyDescription = function() { var text = $('.deepseek-description-content').text(); if (text) { navigator.clipboard.writeText(text).then(function() { alert('📋 Descrição copiada!'); }).catch(function() { // Fallback var textarea = document.createElement('textarea'); textarea.value = text; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); document.body.removeChild(textarea); alert('📋 Descrição copiada!'); }); } }; window.deepseekSaveDescription = function() { var termId = $('#single-preview').data('term-id'); var description = $('.deepseek-description-content').text(); if (!termId || !description) { alert('Nenhuma descrição para salvar.'); return; } // A descrição já foi salva via AJAX, então apenas recarregamos a página alert('💾 Descrição salva na categoria! Recarregando...'); location.reload(); }; // ============================================ // MONITORA MUDANÇAS NO CAMPO DE DESCRIÇÃO // ============================================ $('#description').on('change input', function() { var hasContent = $(this).val().trim().length > 0; var $status = $('#deepseek-status'); if (hasContent) { $status.html('✓ Descrição personalizada'); } else { $status.html(''); } }); // Atualiza valor da temperatura $('#deepseek_temperature').on('input', function() { $('#temperature-value').text($(this).val()); }); console.log('✅ DeepSeek Category Description Pro v2.0.1 pronto!'); }); Jogos de Vestir - Jogue no Variboo

2020 Spring Style

2020 Spring Style