🔑 Chaves API & Afiliado AliExpress
🔒 Segurança
➕ Cadastrar Produto
`;
document.getElementById('productsGrid').insertAdjacentHTML('beforeend', newCardHTML);
document.getElementById('newProdLink').value = '';
atualizarListaSelectADM();
alert('Produto cadastrado com sucesso!');
} catch (err) {
alert('Erro ao buscar produto: ' + err.message);
} finally {
btn.textContent = '⚡ Importar via API AliExpress';
btn.disabled = false;
}
}
const cards = document.querySelectorAll('.product-card');
cards.forEach(card => {
const catCard = card.getAttribute('data-category');
if (nomeCategoria === 'TODOS' || catCard === nomeCategoria) {
card.style.display = 'flex';
} else {
card.style.display = 'none';
}
});
}
function abrirModal() {
document.getElementById('loginModal').classList.add('active');
document.getElementById('adminPassword').focus();
}
function fecharModal() {
document.getElementById('loginModal').classList.remove('active');
document.getElementById('adminPassword').value = '';
}
function fecharAdmin() {
document.getElementById('adminPanel').classList.remove('active');
document.body.classList.remove('admin-mode');
}
function autenticarPrototipo() {
const senhaDigitada = document.getElementById('adminPassword').value;
if (senhaDigitada === SENHA_MASTER) {
document.getElementById('adminPanel').classList.add('active');
document.body.classList.add('admin-mode');
carregarChavesAPI();
atualizarListaSelectADM();
fecharModal();
window.scrollTo({ top: 0, behavior: 'smooth' });
} else {
alert('Senha incorreta!');
document.getElementById('adminPassword').value = '';
}
}
function alterarSenha(e) {
e.preventDefault();
const n1 = document.getElementById('newPass').value;
const n2 = document.getElementById('confirmPass').value;
if (n1 !== n2) {
alert('As senhas não coincidem!');
return;
}
SENHA_MASTER = n1;
localStorage.setItem('hk_admin_pass', n1);
alert('Senha alterada com sucesso!');
document.getElementById('passwordForm').reset();
}
function salvarDadosAPI(e) {
e.preventDefault();
const key = document.getElementById('appKey').value.trim();
const secret = document.getElementById('appSecret').value.trim();
const tracking = document.getElementById('trackingId').value.trim();
localStorage.setItem('ali_app_key', key);
localStorage.setItem('ali_app_secret', secret);
localStorage.setItem('ali_tracking_id', tracking);
alert('Chaves e Tracking ID salvos com sucesso!');
}
function carregarChavesAPI() {
document.getElementById('appKey').value = localStorage.getItem('ali_app_key') || '';
document.getElementById('appSecret').value = localStorage.getItem('ali_app_secret') || '';
document.getElementById('trackingId').value = localStorage.getItem('ali_tracking_id') || '';
}
function atualizarListaSelectADM() {
const select = document.getElementById('editProdSelect');
select.innerHTML = '';
const cards = document.querySelectorAll('.product-card');
cards.forEach(card => {
const id = card.id;
const descText = card.querySelector('.product-desc').innerText;
const opt = document.createElement('option');
opt.value = id;
opt.textContent = descText.substring(0, 40) + '...';
select.appendChild(opt);
});
if (cards.length > 0) {
document.getElementById('editProdDescText').value = cards[0].querySelector('.product-desc').innerText;
}
select.onchange = function() {
const selectedId = this.value;
const card = document.getElementById(selectedId);
if (card) {
document.getElementById('editProdDescText').value = card.querySelector('.product-desc').innerText;
}
};
}
function salvarNovaDescricao() {
const selectedId = document.getElementById('editProdSelect').value;
const novaDesc = document.getElementById('editProdDescText').value;
const card = document.getElementById(selectedId);
if (card && novaDesc.trim() !== '') {
card.querySelector('.product-desc').innerText = novaDesc;
alert('Descrição atualizada com sucesso!');
atualizarListaSelectADM();
} else {
alert('Por favor, selecione um produto e informe uma descrição válida.');
}
}
function simularBuscaAliExpress() {
const cat = document.getElementById('newProdCategory').value;
const link = document.getElementById('newProdLink').value.trim();
if (!link) {
alert('Por favor, informe o link do produto AliExpress.');
return;
}
const newId = 'prod-' + Date.now();
const newCardHTML = `
✕
${cat}
Produto importado via link AliExpress (${cat}).
R$ 49,90
+ impostos
`;
document.getElementById('productsGrid').insertAdjacentHTML('beforeend', newCardHTML);
document.getElementById('newProdLink').value = '';
atualizarListaSelectADM();
alert('Produto cadastrado com sucesso!');
}
function removerProduto(id) {
if (confirm('Tem certeza que deseja remover este produto?')) {
const card = document.getElementById(id);
if (card) {
card.remove();
atualizarListaSelectADM();
}
}
}