| Server IP : 69.6.249.155 / Your IP : 216.73.216.69 Web Server : Apache System : Linux sh00204.hostgator.com.br 5.14.0-687.36.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Aug 7 05:40:49 EDT 2026 x86_64 User : eltonj33 ( 1904) PHP Version : 8.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home2/eltonj33/alfaprompt.net/assets/ |
Upload File : |
(function () {
let categoriaAtiva = 'todos';
let termoPesquisa = '';
let paginaAtual = 1;
let temMais = false;
let carregando = false;
const grid = document.getElementById('grid-prompts');
const contador = document.getElementById('contador');
const btnMais = document.getElementById('btn-carregar-mais');
const inputPesquisa = document.getElementById('filtro-pesquisa');
const botoesFiltro = document.getElementById('botoes-filtro');
function nomeCategoria(slug) {
const btn = botoesFiltro.querySelector(`[data-categoria="${slug}"]`);
return btn ? btn.textContent : slug;
}
function renderizarItens(itens, anexar) {
if (!anexar) grid.innerHTML = '';
if (itens.length === 0 && !anexar) {
grid.innerHTML = '<p style="grid-column:1/-1;text-align:center;">Nenhum prompt encontrado.</p>';
return;
}
const frag = document.createDocumentFragment();
itens.forEach(function (p) {
const item = document.createElement('div');
item.className = 'item-prompt';
const tag = document.createElement('div');
tag.className = 'categoria-tag';
tag.textContent = nomeCategoria(p.categoria);
const h3 = document.createElement('h3');
h3.textContent = p.titulo;
const par = document.createElement('p');
par.textContent = p.texto;
const botao = document.createElement('button');
botao.className = 'botao-copiar';
botao.textContent = 'Copiar Prompt';
botao.addEventListener('click', function () { copiarPrompt(p, botao); });
item.appendChild(tag);
item.appendChild(h3);
item.appendChild(par);
item.appendChild(botao);
frag.appendChild(item);
});
grid.appendChild(frag);
}
function copiarPrompt(p, botao) {
const texto = p.titulo + '\n\n' + p.texto;
navigator.clipboard.writeText(texto).then(function () {
const original = botao.textContent;
botao.textContent = '✓ Copiado!';
botao.classList.add('copiado');
setTimeout(function () {
botao.textContent = original;
botao.classList.remove('copiado');
}, 2000);
}).catch(function () {
alert('Não foi possível copiar o prompt.');
});
}
function buscar(anexar) {
if (carregando) return;
carregando = true;
const params = new URLSearchParams({
categoria: categoriaAtiva,
q: termoPesquisa,
pagina: paginaAtual,
});
fetch('api/prompts.php?' + params.toString())
.then(function (r) { return r.json(); })
.then(function (data) {
renderizarItens(data.itens, anexar);
temMais = data.tem_mais;
btnMais.style.display = temMais ? 'inline-block' : 'none';
contador.textContent = 'Exibindo ' + (anexar ? grid.children.length : data.itens.length) + ' de ' + data.total + ' prompts';
carregando = false;
})
.catch(function () {
contador.textContent = 'Erro ao carregar prompts.';
carregando = false;
});
}
botoesFiltro.addEventListener('click', function (e) {
const btn = e.target.closest('.botao-filtro');
if (!btn) return;
categoriaAtiva = btn.getAttribute('data-categoria');
paginaAtual = 1;
document.querySelector('.botao-filtro.ativo')?.classList.remove('ativo');
btn.classList.add('ativo');
buscar(false);
});
let debounceTimer;
inputPesquisa.addEventListener('input', function () {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(function () {
termoPesquisa = inputPesquisa.value.trim();
paginaAtual = 1;
buscar(false);
}, 300);
});
btnMais.addEventListener('click', function () {
paginaAtual += 1;
buscar(true);
});
buscar(false);
})();