Compare commits

...

2 Commits

Author SHA1 Message Date
Ricardo Carneiro
286da5e5de fix: gerar url/link.
Some checks failed
Deploy QR Rapido / test (push) Successful in 32s
Deploy QR Rapido / build-and-push (push) Failing after 9s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Has been skipped
2025-08-01 10:33:34 -03:00
Ricardo Carneiro
ee160135af feat: todos os qr codes com os campos funcionais!!! (falta apenas o dinamico) 2025-07-31 23:59:45 -03:00
4 changed files with 1069 additions and 66 deletions

View File

@ -1,4 +1,5 @@
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(dotnet new:*)",
@ -9,7 +10,9 @@
"Bash(dotnet run:*)",
"Bash(curl:*)",
"Bash(pkill:*)",
"Bash(true)"
"Bash(true)",
"Bash(dotnet clean:*)",
"Bash(grep:*)"
],
"deny": []
}

View File

@ -11,6 +11,9 @@
<div class="container">
<!-- Hidden input for JavaScript premium status check -->
<input type="hidden" id="user-premium-status" value="@(ViewBag.IsPremium == true ? "true" : "false")" />
<div class="row">
<!-- QR Generator Form -->
<div class="col-lg-8">
@ -80,10 +83,6 @@
<option value="vcard">👤 @Localizer["VCard"]</option>
<option value="sms">💬 @Localizer["SMS"]</option>
<option value="email">📧 @Localizer["Email"]</option>
@if (User.Identity.IsAuthenticated)
{
<option value="dynamic">⚡ @Localizer["DynamicQRPremium"]</option>
}
</select>
</div>
<div class="col-md-6 mb-3">
@ -103,7 +102,7 @@
</div>
</div>
<div class="mb-3">
<div class="mb-3" id="content-group">
<label class="form-label fw-semibold">
<i class="fas fa-edit"></i> @Localizer["Content"]
</label>
@ -118,6 +117,56 @@
</div>
</div>
<!-- Dynamic QR Section (Premium) -->
<div id="dynamic-qr-section" style="display: none;">
<div class="premium-feature-box">
<div class="d-flex align-items-center justify-content-between">
<div>
<h6 class="mb-1">
<i class="fas fa-chart-line text-warning"></i> QR Dinâmico - Premium
</h6>
<small class="text-muted">
Analytics em tempo real: cliques, localização, dispositivos, etc.
</small>
</div>
<div class="form-check form-switch">
@if (ViewBag.IsPremium == true)
{
<input class="form-check-input" type="checkbox" id="qr-dynamic-toggle">
<label class="form-check-label" for="qr-dynamic-toggle">
Ativar Analytics
</label>
}
else
{
<div class="premium-upgrade-prompt">
<input class="form-check-input" type="checkbox" disabled>
<label class="form-check-label text-muted">
Ativar Analytics
</label>
<br>
<small>
<a href="/Pagamento/SelecaoPlano" class="text-warning">
Upgrade Premium
</a> para analytics
</small>
</div>
}
</div>
</div>
</div>
</div>
<!-- URL Preview -->
<div id="url-preview" class="mt-3" style="display: none;">
<h6><i class="fas fa-link"></i> Preview</h6>
<div id="url-preview-content" class="bg-light p-3 rounded">
<strong>URL Final:</strong> <span id="final-url-display"></span><br>
<strong>Tipo:</strong> <span id="qr-type-display">QR Code Estático</span>
</div>
</div>
<!-- VCard Interface (dynamic) -->
<div id="vcard-interface" class="mb-3" style="display: none;">
<div class="alert alert-info">
@ -250,15 +299,186 @@
<div class="card bg-light">
<div class="card-body">
<pre id="vcard-preview-text" class="mb-0 small text-muted">BEGIN:VCARD
VERSION:3.0
CHARSET=UTF-8
Preencha os campos acima para ver o preview...
END:VCARD</pre>
VERSION:3.0
CHARSET=UTF-8
Preencha os campos acima para ver o preview...
END:VCARD
</pre>
</div>
</div>
</div>
</div>
<!-- WiFi Interface (dynamic) -->
<div id="wifi-interface" class="mb-3" style="display: none;">
<div class="alert alert-info">
<i class="fas fa-wifi"></i>
<strong>@Localizer["WiFiQRTitle"]</strong> - @Localizer["WiFiQRDescription"]
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">@Localizer["NetworkName"] *</label>
<input type="text" id="wifi-ssid" name="wifi-ssid" class="form-control" placeholder="NomeDaSuaRede" required>
<div class="invalid-feedback">@Localizer["NetworkNameRequired"]</div>
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">@Localizer["SecurityType"]</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="wifi-security" id="wifi-security-wpa" value="WPA" checked>
<label class="form-check-label" for="wifi-security-wpa">@Localizer["WPARecommended"]</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="wifi-security" id="wifi-security-wep" value="WEP">
<label class="form-check-label" for="wifi-security-wep">@Localizer["WEPLegacy"]</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="wifi-security" id="wifi-security-nopass" value="nopass">
<label class="form-check-label" for="wifi-security-nopass">@Localizer["OpenNetwork"]</label>
</div>
</div>
<div class="form-group mb-3" id="wifi-password-group">
<label class="form-label fw-semibold">@Localizer["NetworkPassword"] *</label>
<div class="input-group">
<input type="password" id="wifi-password" name="wifi-password" class="form-control" placeholder="SenhaDaSuaRede" required>
<button class="btn btn-outline-secondary" type="button" id="toggle-password">
<i class="fas fa-eye"></i>
</button>
</div>
<div class="invalid-feedback">@Localizer["PasswordRequiredForSecure"]</div>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="wifi-hidden" name="wifi-hidden">
<label class="form-check-label" for="wifi-hidden">@Localizer["HiddenNetwork"]</label>
</div>
<div class="wifi-preview">
<h6 class="fw-bold text-success mb-2">
<i class="fas fa-eye"></i> @Localizer["WiFiPreviewTitle"]
</h6>
<div class="card bg-light">
<div class="card-body">
<pre id="wifi-preview-text" class="mb-0 small text-muted">WIFI:T:WPA;S:;P:;H:false;;</pre>
</div>
</div>
</div>
</div>
<!-- WiFi Interface (dynamic) -->
<div id="wifi-interface" class="mb-3" style="display: none;">
<div class="alert alert-info">
<i class="fas fa-wifi"></i>
<strong>@Localizer["WiFiQRTitle"]</strong> - @Localizer["WiFiQRDescription"]
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">@Localizer["NetworkName"] *</label>
<input type="text" id="wifi-ssid2" class="form-control" placeholder="NomeDaSuaRede" required>
<div class="invalid-feedback">@Localizer["NetworkNameRequired"]</div>
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">@Localizer["SecurityType"]</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="wifi-security" id="wifi-security-wpa2" value="WPA" checked>
<label class="form-check-label" for="wifi-security-wpa">@Localizer["WPARecommended"]</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="wifi-security" id="wifi-security-wep2" value="WEP">
<label class="form-check-label" for="wifi-security-wep">@Localizer["WEPLegacy"]</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="wifi-security" id="wifi-security-nopass2" value="nopass">
<label class="form-check-label" for="wifi-security-nopass">@Localizer["OpenNetwork"]</label>
</div>
</div>
<div class="form-group mb-3" id="wifi-password-group">
<label class="form-label fw-semibold">@Localizer["NetworkPassword"] *</label>
<div class="input-group">
<input type="password" id="wifi-password2" class="form-control" placeholder="SenhaDaSuaRede" required>
<button class="btn btn-outline-secondary" type="button" id="toggle-password2">
<i class="fas fa-eye"></i>
</button>
</div>
<div class="invalid-feedback">@Localizer["PasswordRequiredForSecure"]</div>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="wifi-hidden2">
<label class="form-check-label" for="wifi-hidden">@Localizer["HiddenNetwork"]</label>
</div>
<div class="wifi-preview">
<h6 class="fw-bold text-success mb-2">
<i class="fas fa-eye"></i> @Localizer["WiFiPreviewTitle"]
</h6>
<div class="card bg-light">
<div class="card-body">
<pre id="wifi-preview-text" class="mb-0 small text-muted">WIFI:T:WPA;S:;P:;H:false;;</pre>
</div>
</div>
</div>
</div>
<!-- SMS Interface (dynamic) -->
<div id="sms-interface" class="mb-3" style="display: none;">
<div class="alert alert-info">
<strong>QR Code SMS:</strong> Permite enviar SMS automático com número e mensagem pré-definidos.
Compatível com Android, iOS e dispositivos modernos.
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">Número do Celular *</label>
<input type="tel" id="sms-number" name="sms-number" class="form-control" placeholder="11999998888" required>
<small class="text-muted">Apenas números (DDD + número, sem espaços)</small>
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">Mensagem *</label>
<textarea id="sms-message" name="sms-message" class="form-control" rows="3" placeholder="Sua mensagem aqui..." required></textarea>
<small class="text-muted">Mensagem que será pré-preenchida no SMS</small>
</div>
<div class="sms-preview">
<h6> Preview do SMS</h6>
<pre id="sms-preview-text" class="bg-light p-3 rounded">SMSTO::</pre>
</div>
</div>
<!-- Email Interface (dynamic) -->
<div id="email-interface" class="mb-3" style="display: none;">
<div class="alert alert-info">
<strong>QR Code Email:</strong> Permite enviar email automático com destinatário, assunto e mensagem pré-definidos.
Compatível com Android, iOS e dispositivos modernos.
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">Email Destinatário *</label>
<input type="email" id="email-to" name="email-to" class="form-control" placeholder="contato@empresa.com" required>
<small class="text-muted">Email que receberá a mensagem</small>
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">Assunto *</label>
<input type="text" id="email-subject" name="email-subject" class="form-control" placeholder="Assunto do email" required>
<small class="text-muted">Linha de assunto do email</small>
</div>
<div class="form-group mb-3">
<label class="form-label fw-semibold">Mensagem</label>
<textarea id="email-body" name="email-body" class="form-control" rows="4" placeholder="Corpo da mensagem..."></textarea>
<small class="text-muted">Corpo da mensagem (opcional)</small>
</div>
<div class="email-preview">
<h6> Preview do Email</h6>
<pre id="email-preview-text" class="bg-light p-3 rounded">mailto:?subject=&body=</pre>
</div>
</div>
<!-- Advanced customization (collapsible) -->
<div class="accordion mb-3" id="customization-accordion">
<div class="accordion-item">

View File

@ -18,6 +18,24 @@ body {
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}
/* URL Validation Feedback */
#url-validation-error {
font-size: 0.875rem;
margin-top: 0.5rem;
padding: 0.5rem;
border-radius: 0.25rem;
}
.form-control.is-invalid {
border-color: #dc3545;
box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}
.form-control.is-valid {
border-color: #28a745;
box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}
/* Share Button Styles */
#share-qr-btn {
position: relative;
@ -123,4 +141,45 @@ body {
.share-success.show {
transform: translateX(0);
}
}
.premium-feature-box {
border: 2px solid #ffc107;
border-radius: 8px;
padding: 15px;
margin: 15px 0;
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
}
.premium-feature-box h6 {
color: #856404;
margin-bottom: 5px;
}
.form-check-input:checked {
background-color: #ffc107;
border-color: #ffc107;
}
.premium-upgrade-prompt {
text-align: center;
padding: 10px;
}
.premium-upgrade-prompt a {
text-decoration: none;
font-weight: bold;
}
.premium-upgrade-prompt a:hover {
text-decoration: underline;
}
#url-preview-content {
font-family: monospace;
border-left: 4px solid #007bff;
}
.text-success {
color: #28a745 !important;
}

View File

@ -106,16 +106,21 @@ class QRRapidoGenerator {
});
});
// VCard fields validation
const vcardFields = ['vcard-name', 'vcard-mobile', 'vcard-email'];
vcardFields.forEach(fieldId => {
const field = document.getElementById(fieldId);
if (field) {
field.addEventListener('input', () => {
this.updateGenerateButton();
});
// Add listeners to all relevant fields to update button state
const fieldsToWatch = [
'qr-content', 'vcard-name', 'vcard-mobile', 'vcard-email',
'wifi-ssid', 'wifi-password', 'sms-number', 'sms-message',
'email-to', 'email-subject', 'email-body'
];
fieldsToWatch.forEach(id => {
const el = document.getElementById(id);
if (el) {
el.addEventListener('input', () => this.updateGenerateButton());
}
});
document.querySelectorAll('input[name="wifi-security"]').forEach(radio => {
radio.addEventListener('change', () => this.updateGenerateButton());
});
// Language selector
document.querySelectorAll('[data-lang]').forEach(link => {
@ -431,6 +436,27 @@ class QRRapidoGenerator {
this.showError('Erro na validação do VCard: ' + error.message);
return false;
}
} else if (qrType === 'wifi') {
const errors = window.wifiGenerator.validateWiFiData();
if (errors.length > 0) {
this.showError(errors.join('<br>'));
return false;
}
return true;
} else if (qrType === 'sms') {
const errors = window.smsGenerator.validateSMSData();
if (errors.length > 0) {
this.showError(errors.join('<br>'));
return false;
}
return true;
} else if (qrType === 'email') {
const errors = window.emailGenerator.validateEmailData();
if (errors.length > 0) {
this.showError(errors.join('<br>'));
return false;
}
return true;
}
// Normal validation for other types
@ -453,7 +479,87 @@ class QRRapidoGenerator {
const type = document.getElementById('qr-type').value;
const quickStyle = document.querySelector('input[name="quick-style"]:checked')?.value || 'classic';
const styleSettings = this.getStyleSettings(quickStyle);
if (type === 'url') {
const dynamicData = window.dynamicQRManager.getDynamicQRData();
if (dynamicData.requiresPremium) {
throw new Error('QR Dinâmico é exclusivo para usuários Premium. Faça upgrade para usar analytics.');
}
return {
data: {
type: 'url',
content: dynamicData.originalUrl,
isDynamic: dynamicData.isDynamic,
quickStyle: quickStyle,
primaryColor: document.getElementById('primary-color').value || (styleSettings.primaryColor || '#000000'),
backgroundColor: document.getElementById('bg-color').value || (styleSettings.backgroundColor || '#FFFFFF'),
size: parseInt(document.getElementById('qr-size').value),
margin: parseInt(document.getElementById('qr-margin').value),
cornerStyle: document.getElementById('corner-style')?.value || 'square',
optimizeForSpeed: true,
language: this.currentLang
},
isMultipart: false,
endpoint: '/api/QR/GenerateRapid'
};
}
if (type === 'wifi') {
const wifiContent = window.wifiGenerator.generateWiFiString();
return {
data: {
type: 'text', // WiFi is treated as text in the backend
content: wifiContent,
quickStyle: quickStyle,
primaryColor: document.getElementById('primary-color').value || (styleSettings.primaryColor || '#000000'),
backgroundColor: document.getElementById('bg-color').value || (styleSettings.backgroundColor || '#FFFFFF'),
size: parseInt(document.getElementById('qr-size').value),
margin: parseInt(document.getElementById('qr-margin').value),
cornerStyle: document.getElementById('corner-style')?.value || 'square',
optimizeForSpeed: true,
language: this.currentLang
},
isMultipart: false,
endpoint: '/api/QR/GenerateRapid'
};
} else if (type === 'sms') {
const smsContent = window.smsGenerator.generateSMSString();
return {
data: {
type: 'text',
content: smsContent,
quickStyle: quickStyle,
primaryColor: document.getElementById('primary-color').value || (styleSettings.primaryColor || '#000000'),
backgroundColor: document.getElementById('bg-color').value || (styleSettings.backgroundColor || '#FFFFFF'),
size: parseInt(document.getElementById('qr-size').value),
margin: parseInt(document.getElementById('qr-margin').value),
cornerStyle: document.getElementById('corner-style')?.value || 'square',
optimizeForSpeed: true,
language: this.currentLang
},
isMultipart: false,
endpoint: '/api/QR/GenerateRapid'
};
} else if (type === 'email') {
const emailContent = window.emailGenerator.generateEmailString();
return {
data: {
type: 'text',
content: emailContent,
quickStyle: quickStyle,
primaryColor: document.getElementById('primary-color').value || (styleSettings.primaryColor || '#000000'),
backgroundColor: document.getElementById('bg-color').value || (styleSettings.backgroundColor || '#FFFFFF'),
size: parseInt(document.getElementById('qr-size').value),
margin: parseInt(document.getElementById('qr-margin').value),
cornerStyle: document.getElementById('corner-style')?.value || 'square',
optimizeForSpeed: true,
language: this.currentLang
},
isMultipart: false,
endpoint: '/api/QR/GenerateRapid'
};
}
// Handle VCard type
if (type === 'vcard') {
if (window.vcardGenerator) {
@ -729,7 +835,7 @@ class QRRapidoGenerator {
'wifi': 'Nombre de red;Contraseña;Tipo de seguridad (WPA/WEP)',
'vcard': 'Nombre;Teléfono;Email;Empresa',
'sms': 'Número;Mensaje',
'email': 'email@ejemplo.com;Asunto;Mensaje'
'email': 'email@ejemplo.com;Asunto;Mensagem'
}
};
@ -888,11 +994,15 @@ class QRRapidoGenerator {
const timeFloat = parseFloat(generationTime);
// Update average time display in the stats cards
const avgElement = document.querySelector('.card-body h5:contains("1.2s")');
if (avgElement) {
const avgTime = window.qrRapidoStats ? window.qrRapidoStats.getAverageTime() : generationTime;
avgElement.innerHTML = `<i class="fas fa-stopwatch"></i> ${avgTime}s`;
}
// Find h5 elements in card bodies and look for one containing time info
const cardElements = document.querySelectorAll('.card-body h5');
cardElements.forEach(element => {
// Look for elements containing time format (e.g., "1.2s", "0.8s", etc.)
if (element.textContent.includes('s') && element.textContent.match(/\d+\.\d+s/)) {
const avgTime = window.qrRapidoStats ? window.qrRapidoStats.getAverageTime() : generationTime;
element.innerHTML = `<i class="fas fa-stopwatch"></i> ${avgTime}s`;
}
});
// Update the generation timer in the header
const timerElement = document.querySelector('.generation-timer span');
@ -1162,10 +1272,8 @@ class QRRapidoGenerator {
const qrContent = document.getElementById('qr-content');
const vcardInterface = document.getElementById('vcard-interface');
// Inicialmente desabilitar campo de conteúdo
if (qrContent) {
qrContent.disabled = true;
}
// FIXED: Don't disable content field initially - let enableContentFields handle it
// The field should be available for typing once a type is selected
// Ocultar interface vCard
if (vcardInterface) {
@ -1173,6 +1281,45 @@ class QRRapidoGenerator {
}
this.updateGenerateButton();
// Setup URL validation event listeners
this.setupURLValidationListeners();
}
setupURLValidationListeners() {
const contentField = document.getElementById('qr-content');
if (!contentField) return;
// Auto-fix URL on blur (when user leaves the field)
contentField.addEventListener('blur', () => {
const type = document.getElementById('qr-type')?.value;
if (type === 'url' && contentField.value.trim()) {
const originalValue = contentField.value.trim();
const fixedValue = this.autoFixURL(originalValue);
if (originalValue !== fixedValue) {
contentField.value = fixedValue;
console.log('🔧 URL auto-corrigida:', originalValue, '→', fixedValue);
// Revalidar após correção
this.updateGenerateButton();
}
}
});
// Real-time validation with debounce
contentField.addEventListener('input', () => {
const type = document.getElementById('qr-type')?.value;
if (type === 'url') {
// Debounce para não validar a cada caractere
clearTimeout(contentField.validationTimeout);
contentField.validationTimeout = setTimeout(() => {
this.updateGenerateButton();
}, 500);
}
});
}
handleTypeSelection(type) {
@ -1207,28 +1354,62 @@ class QRRapidoGenerator {
}
enableContentFields(type) {
const qrContent = document.getElementById('qr-content');
const contentGroup = document.getElementById('content-group');
const vcardInterface = document.getElementById('vcard-interface');
const wifiInterface = document.getElementById('wifi-interface');
const smsInterface = document.getElementById('sms-interface');
const emailInterface = document.getElementById('email-interface');
const dynamicQRSection = document.getElementById('dynamic-qr-section');
const urlPreview = document.getElementById('url-preview');
// Hide all interfaces by default
if (vcardInterface) vcardInterface.style.display = 'none';
if (wifiInterface) wifiInterface.style.display = 'none';
if (smsInterface) smsInterface.style.display = 'none';
if (emailInterface) emailInterface.style.display = 'none';
if (dynamicQRSection) dynamicQRSection.style.display = 'none';
if (urlPreview) urlPreview.style.display = 'none';
if (contentGroup) contentGroup.style.display = 'block';
if (type === 'vcard') {
// Para vCard, ocultar textarea e mostrar interface específica
if (qrContent) {
qrContent.style.display = 'none';
qrContent.removeAttribute('required');
}
if (contentGroup) contentGroup.style.display = 'none';
if (vcardInterface) {
vcardInterface.style.display = 'block';
this.enableVCardFields();
}
} else {
// Para outros tipos, mostrar textarea
if (qrContent) {
qrContent.style.display = 'block';
qrContent.setAttribute('required', 'required');
} else if (type === 'wifi') {
// Para WiFi, ocultar textarea e mostrar interface específica
if (contentGroup) contentGroup.style.display = 'none';
if (wifiInterface) {
wifiInterface.style.display = 'block';
}
} else if (type === 'sms') {
// Para SMS, ocultar textarea e mostrar interface específica
if (contentGroup) contentGroup.style.display = 'none';
if (smsInterface) {
smsInterface.style.display = 'block';
}
} else if (type === 'email') {
// Para Email, ocultar textarea e mostrar interface específica
if (contentGroup) contentGroup.style.display = 'none';
if (emailInterface) {
emailInterface.style.display = 'block';
}
} else if (type === 'url') {
if (dynamicQRSection) dynamicQRSection.style.display = 'block';
if (urlPreview) urlPreview.style.display = 'block';
// CRITICAL FIX: Enable content field for URL type
const qrContent = document.getElementById('qr-content');
if(qrContent) {
qrContent.disabled = false;
}
if (vcardInterface) {
vcardInterface.style.display = 'none';
} else {
// Para outros tipos, mostrar textarea
if (contentGroup) contentGroup.style.display = 'block';
const qrContent = document.getElementById('qr-content');
if(qrContent) {
qrContent.disabled = false;
}
}
}
@ -1250,7 +1431,7 @@ class QRRapidoGenerator {
const vcardInterface = document.getElementById('vcard-interface');
if (qrContent) {
qrContent.disabled = true;
// FIXED: Don't disable content field, just clear it
qrContent.value = '';
}
@ -1320,33 +1501,137 @@ class QRRapidoGenerator {
}
}
updateGenerateButton() {
const generateBtn = document.getElementById('generate-btn');
if (!generateBtn) return;
// ============================================
// URL VALIDATION FUNCTIONS
// ============================================
isValidURL(url) {
if (!url || typeof url !== 'string') return false;
let shouldEnable = false;
const trimmedUrl = url.trim();
// Verificar se tem tipo selecionado
if (this.selectedType) {
if (this.selectedType === 'vcard') {
// Para vCard, validar campos obrigatórios
shouldEnable = this.validateVCardFields();
} else {
// Para outros tipos, validar conteúdo
const content = document.getElementById('qr-content')?.value || '';
shouldEnable = this.validateContent(content);
// Verificar se começa com http:// ou https://
const hasProtocol = trimmedUrl.startsWith('http://') || trimmedUrl.startsWith('https://');
// Verificar se tem pelo menos um ponto
const hasDot = trimmedUrl.includes('.');
// Verificar se não é só o protocolo
const hasContent = trimmedUrl.length > 8; // mais que "https://"
// Regex mais robusta
const urlRegex = /^https?:\/\/.+\..+/i;
return hasProtocol && hasDot && hasContent && urlRegex.test(trimmedUrl);
}
autoFixURL(url) {
if (!url || typeof url !== 'string') return '';
let fixedUrl = url.trim();
// Se não tem protocolo, adicionar https://
if (!fixedUrl.startsWith('http://') && !fixedUrl.startsWith('https://')) {
fixedUrl = 'https://' + fixedUrl;
}
return fixedUrl;
}
showValidationError(message) {
let errorDiv = document.getElementById('url-validation-error');
if (!errorDiv) {
// Criar div de erro se não existir
errorDiv = document.createElement('div');
errorDiv.id = 'url-validation-error';
errorDiv.className = 'alert alert-danger mt-2';
errorDiv.style.display = 'none';
// Inserir após o campo de conteúdo
const contentGroup = document.getElementById('content-group');
if (contentGroup) {
contentGroup.appendChild(errorDiv);
}
}
generateBtn.disabled = !shouldEnable;
// Feedback visual
if (shouldEnable) {
generateBtn.classList.remove('btn-secondary');
errorDiv.innerHTML = `<small><i class="fas fa-exclamation-triangle"></i> ${message}</small>`;
errorDiv.style.display = 'block';
}
clearValidationError() {
const errorDiv = document.getElementById('url-validation-error');
if (errorDiv) {
errorDiv.style.display = 'none';
}
}
updateGenerateButton() {
const generateBtn = document.getElementById('generate-btn');
if (!generateBtn) return;
let isValid = false;
const type = this.selectedType;
if (type === 'url') {
const contentField = document.getElementById('qr-content');
const content = contentField?.value || '';
const trimmedContent = content.trim();
if (!trimmedContent) {
this.showValidationError('URL é obrigatória');
if (contentField) {
contentField.classList.remove('is-valid');
contentField.classList.add('is-invalid');
}
isValid = false;
} else if (!this.isValidURL(trimmedContent)) {
this.showValidationError('URL deve começar com http:// ou https:// e conter pelo menos um ponto (ex: https://google.com)');
if (contentField) {
contentField.classList.remove('is-valid');
contentField.classList.add('is-invalid');
}
isValid = false;
} else {
this.clearValidationError();
if (contentField) {
contentField.classList.remove('is-invalid');
contentField.classList.add('is-valid');
}
isValid = true;
}
} else if (type === 'text') {
const contentField = document.getElementById('qr-content');
const content = contentField?.value || '';
isValid = content.trim().length >= 3;
this.clearValidationError(); // Clear any URL validation errors
if (contentField) {
contentField.classList.remove('is-valid', 'is-invalid');
}
} else if (type === 'vcard') {
isValid = this.validateVCardFields();
} else if (type === 'wifi') {
const data = window.wifiGenerator.collectWiFiData();
isValid = data.ssid.trim() !== '';
if (data.security !== 'nopass' && !data.password.trim()) {
isValid = false;
}
} else if (type === 'sms') {
const data = window.smsGenerator.collectSMSData();
isValid = data.number.trim() !== '' && data.message.trim() !== '';
} else if (type === 'email') {
const data = window.emailGenerator.collectEmailData();
isValid = data.to.trim() !== '' && data.subject.trim() !== '';
}
generateBtn.disabled = !isValid;
if (isValid) {
generateBtn.classList.remove('btn-secondary', 'disabled');
generateBtn.classList.add('btn-primary');
} else {
generateBtn.classList.remove('btn-primary');
generateBtn.classList.add('btn-secondary');
generateBtn.classList.add('btn-secondary', 'disabled');
}
}
@ -1369,7 +1654,7 @@ class QRRapidoGenerator {
// Garantir que o conteúdo seja tratado como UTF-8
try {
// Verificar se há caracteres especiais
const hasSpecialChars = /[^\x00-\x7F]/.test(content);
const hasSpecialChars = /[^-]/.test(content);
if (hasSpecialChars) {
console.log('Caracteres especiais detectados, aplicando codificação UTF-8');
@ -1441,6 +1726,10 @@ class QRRapidoGenerator {
document.addEventListener('DOMContentLoaded', () => {
window.qrGenerator = new QRRapidoGenerator();
window.vcardGenerator = new VCardGenerator();
window.wifiGenerator = new WiFiQRGenerator();
window.smsGenerator = new SMSQRGenerator();
window.emailGenerator = new EmailQRGenerator();
window.dynamicQRManager = new DynamicQRManager();
// Initialize AdSense if necessary
if (window.adsbygoogle && document.querySelector('.adsbygoogle')) {
@ -1448,7 +1737,421 @@ document.addEventListener('DOMContentLoaded', () => {
}
});
class DynamicQRManager {
constructor() {
this.initializeDynamicQR();
}
initializeDynamicQR() {
// Verificar se usuário é premium
this.isPremium = this.checkUserPremium();
// Configurar interface baseado no status
this.setupPremiumInterface();
// Event listeners
this.setupEventListeners();
// Preview inicial
this.updatePreview();
}
checkUserPremium() {
// IMPLEMENTAR: verificar se usuário atual é premium
// Pode ser via elemento hidden, variável global, ou chamada AJAX
// Exemplo 1: Via elemento hidden
const premiumStatus = document.getElementById('user-premium-status');
if (premiumStatus) {
return premiumStatus.value === 'true';
}
// Exemplo 2: Via variável global
if (window.userInfo && window.userInfo.isPremium !== undefined) {
return window.userInfo.isPremium;
}
// Fallback: assumir não-premium
return false;
}
setupPremiumInterface() {
const toggleContainer = document.getElementById('dynamic-toggle-container');
const upgradePrompt = document.querySelector('.premium-upgrade-prompt');
if (this.isPremium) {
// Usuário premium: mostrar toggle funcional
if(toggleContainer) toggleContainer.style.display = 'block';
if (upgradePrompt) upgradePrompt.style.display = 'none';
} else {
// Usuário não-premium: mostrar prompt de upgrade
if(toggleContainer) toggleContainer.style.display = 'none';
if (upgradePrompt) upgradePrompt.style.display = 'block';
}
}
setupEventListeners() {
// Toggle do QR Dinâmico
const dynamicToggle = document.getElementById('qr-dynamic-toggle');
if (dynamicToggle) {
dynamicToggle.addEventListener('change', () => {
this.updatePreview();
});
}
// Campo URL
const urlField = document.getElementById('qr-content');
if (urlField) {
urlField.addEventListener('input', () => {
this.updatePreview();
});
}
}
updatePreview() {
const urlField = document.getElementById('qr-content');
const dynamicToggle = document.getElementById('qr-dynamic-toggle');
const finalUrlDisplay = document.getElementById('final-url-display');
const typeDisplay = document.getElementById('qr-type-display');
if (!urlField || !finalUrlDisplay || !typeDisplay) return;
const originalUrl = urlField.value;
const isDynamic = dynamicToggle && dynamicToggle.checked && this.isPremium;
if (isDynamic && originalUrl) {
// QR Dinâmico: mostra URL do QRRapido
finalUrlDisplay.textContent = `https://qrrapido.site/r/{ID_UNICO}`;
typeDisplay.textContent = "QR Code Dinâmico com Analytics ";
typeDisplay.className = "text-success fw-bold";
} else {
// QR Estático: mostra URL original
finalUrlDisplay.textContent = originalUrl || 'Digite uma URL...';
typeDisplay.textContent = "QR Code Estático";
typeDisplay.className = "text-muted";
}
}
// Método para integração com collectFormData()
getDynamicQRData() {
const dynamicToggle = document.getElementById('qr-dynamic-toggle');
const isDynamic = dynamicToggle && dynamicToggle.checked && this.isPremium;
return {
isDynamic: isDynamic,
originalUrl: document.getElementById('qr-content').value,
requiresPremium: !this.isPremium && isDynamic
};
}
}
class SMSQRGenerator {
constructor() {
this.initializeSMSInterface();
}
initializeSMSInterface() {
// Atualizar preview em tempo real
const fieldsToWatch = ['sms-number', 'sms-message'];
fieldsToWatch.forEach(fieldId => {
const element = document.getElementById(fieldId);
if (element) {
element.addEventListener('input', () => this.updatePreview());
element.addEventListener('change', () => this.updatePreview());
}
});
// Inicializar preview
this.updatePreview();
}
updatePreview() {
const smsString = this.generateSMSString();
const previewElement = document.getElementById('sms-preview-text');
if (previewElement) {
previewElement.textContent = smsString;
}
}
generateSMSString() {
const data = this.collectSMSData();
if (!data.number || !data.message) {
return 'SMSTO::';
}
return `SMSTO:${data.number}:${data.message}`;
}
collectSMSData() {
return {
number: document.getElementById('sms-number')?.value || '',
message: document.getElementById('sms-message')?.value || ''
};
}
validateSMSData() {
const data = this.collectSMSData();
const errors = [];
if (!data.number.trim()) {
errors.push('Número do celular é obrigatório');
}
if (!data.message.trim()) {
errors.push('Mensagem é obrigatória');
}
// Validação de telefone brasileiro básica
const phoneRegex = /^\d{10,11}$/;
if (data.number && !phoneRegex.test(data.number.replace(/\D/g, ''))) {
errors.push('Número deve ter 10 ou 11 dígitos (DDD + número)');
}
return errors;
}
}
class EmailQRGenerator {
constructor() {
this.initializeEmailInterface();
}
initializeEmailInterface() {
// Atualizar preview em tempo real
const fieldsToWatch = ['email-to', 'email-subject', 'email-body'];
fieldsToWatch.forEach(fieldId => {
const element = document.getElementById(fieldId);
if (element) {
element.addEventListener('input', () => this.updatePreview());
element.addEventListener('change', () => this.updatePreview());
}
});
// Inicializar preview
this.updatePreview();
}
updatePreview() {
const emailString = this.generateEmailString();
const previewElement = document.getElementById('email-preview-text');
if (previewElement) {
previewElement.textContent = emailString;
}
}
generateEmailString() {
const data = this.collectEmailData();
if (!data.to) {
return 'mailto:?subject=&body=';
}
let emailString = `mailto:${data.to}`;
const params = [];
if (data.subject) {
params.push(`subject=${encodeURIComponent(data.subject)}`);
}
if (data.body) {
params.push(`body=${encodeURIComponent(data.body)}`);
}
if (params.length > 0) {
emailString += '?' + params.join('&');
}
return emailString;
}
collectEmailData() {
return {
to: document.getElementById('email-to')?.value || '',
subject: document.getElementById('email-subject')?.value || '',
body: document.getElementById('email-body')?.value || ''
};
}
validateEmailData() {
const data = this.collectEmailData();
const errors = [];
if (!data.to.trim()) {
errors.push('Email destinatário é obrigatório');
}
if (!data.subject.trim()) {
errors.push('Assunto é obrigatório');
}
// Validação básica de email
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (data.to && !emailRegex.test(data.to)) {
errors.push('Email destinatário inválido');
}
return errors;
}
}
class WiFiQRGenerator {
constructor() {
this.initializeWiFiInterface();
}
initializeWiFiInterface() {
// Radio buttons: usar name para group
document.querySelectorAll('input[name="wifi-security"]').forEach(radio => {
radio.addEventListener('change', () => {
this.togglePasswordField();
this.updatePreview();
});
});
// Campos individuais: usar IDs únicos
const fieldsToWatch = ['wifi-ssid', 'wifi-password', 'wifi-hidden'];
fieldsToWatch.forEach(fieldId => {
const element = document.getElementById(fieldId);
if (element) {
element.addEventListener('input', () => this.updatePreview());
element.addEventListener('change', () => this.updatePreview());
}
});
const togglePassword = document.getElementById('toggle-password');
if (togglePassword) {
togglePassword.addEventListener('click', () => {
this.togglePasswordVisibility();
});
}
// Inicializar estado
this.togglePasswordField();
this.updatePreview();
}
togglePasswordField() {
const selectedRadio = document.querySelector('input[name="wifi-security"]:checked');
const securityType = selectedRadio ? selectedRadio.value : 'WPA';
const passwordGroup = document.getElementById('wifi-password-group');
const passwordInput = document.getElementById('wifi-password');
if (securityType === 'nopass') {
passwordGroup.style.display = 'none';
passwordInput.removeAttribute('required');
passwordInput.value = '';
} else {
passwordGroup.style.display = 'block';
passwordInput.setAttribute('required', 'required');
}
}
togglePasswordVisibility() {
const passwordInput = document.getElementById('wifi-password');
const toggleIcon = document.getElementById('toggle-password');
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
toggleIcon.className = 'fas fa-eye-slash';
} else {
passwordInput.type = 'password';
toggleIcon.className = 'fas fa-eye';
}
}
updatePreview() {
const wifiString = this.generateWiFiString();
const previewText = document.getElementById('wifi-preview-text');
if(previewText) {
previewText.textContent = wifiString;
}
}
generateWiFiString() {
const data = this.collectWiFiData();
// Validar dados mínimos
if (!data.ssid) {
return 'WIFI:T:WPA;S:;P:;H:false;;';
}
// Escapar caracteres especiais
const ssid = this.escapeWiFiString(data.ssid);
const password = this.escapeWiFiString(data.password);
// Construir string WiFi
return `WIFI:T:${data.security};S:${ssid};P:${password};H:${data.hidden};;`;
}
collectWiFiData() {
return {
ssid: document.getElementById('wifi-ssid').value,
security: document.querySelector('input[name="wifi-security"]:checked')?.value || 'WPA',
password: document.getElementById('wifi-password').value,
hidden: document.getElementById('wifi-hidden').checked.toString()
};
}
escapeWiFiString(str) {
if (!str) return '';
// Escapar caracteres especiais do formato WiFi
return str.replace(/[\\;,:"]/g, '\\escapeWiFiString(str) { if (!str) return; }');
// Escapar caracteres especiais do formato WiFi
//return str.replace(/[\\;,:""]/g, '\\document.addEventListener('DOMContentLoaded', () => {
// window.qrGenerator = new QRRapidoGenerator();
// window.vcardGenerator = new VCardGenerator();
// // Initialize AdSense if necessary
// if (window.adsbygoogle && document.querySelector('.adsbygoogle')) {
// (adsbygoogle = window.adsbygoogle || []).push({});
// }
//});
return str.replace(/[\\;,:"']/g, '\\$&');
// VCard Generator Class');
}
validateWiFiData() {
const data = this.collectWiFiData();
const errors = [];
// Validações obrigatórias
if (!data.ssid.trim()) {
errors.push('Nome da rede (SSID) é obrigatório');
}
// Validação de senha conforme tipo de segurança
if ((data.security === 'WPA' || data.security === 'WEP') && !data.password.trim()) {
errors.push('Senha é obrigatória para redes protegidas');
}
// Validação de comprimento
if (data.ssid.length > 32) {
errors.push('Nome da rede deve ter no máximo 32 caracteres');
}
if (data.password.length > 63) {
errors.push('Senha deve ter no máximo 63 caracteres');
}
// Validação WEP específica
if (data.security === 'WEP' && data.password) {
const validWEPLengths = [5, 10, 13, 26]; // WEP 64/128 bit
if (!validWEPLengths.includes(data.password.length)) {
errors.push('Senha WEP deve ter 5, 10, 13 ou 26 caracteres');
}
}
return errors;
}
}
// VCard Generator Class
class VCardGenerator {
constructor() {
this.initializeVCardInterface();
@ -1458,7 +2161,7 @@ class VCardGenerator {
encodeQuotedPrintable(text) {
if (!text) return '';
return text.replace(/[^\x20-\x7E]/g, (char) => {
return text.replace(/[^\u0020-\u007E]/g, (char) => {
// Para caracteres especiais comuns do português, usar codificação UTF-8
const utf8Bytes = new TextEncoder().encode(char);
return Array.from(utf8Bytes)
@ -1475,7 +2178,7 @@ class VCardGenerator {
if (!needsEncoding) return trimmedText;
// Verifica se há caracteres especiais que precisam de codificação
const hasSpecialChars = /[^\x20-\x7E]/.test(trimmedText);
const hasSpecialChars = /[^\u0020-\u007E]/.test(trimmedText);
if (hasSpecialChars) {
return `CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:${this.encodeQuotedPrintable(trimmedText)}`;
@ -1674,7 +2377,7 @@ class VCardGenerator {
}
isValidEmail(email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
return /^[^ @]+@[^ @]+\.[^ @]+$/.test(email);
}
isValidURL(url) {
@ -1717,4 +2420,22 @@ window.QRApp = {
ad.style.display = 'none';
});
}
};
// Google Analytics 4 Event Tracking
window.trackLanguageChange = function(from, to) {
if (typeof gtag !== 'undefined') {
gtag('event', 'language_change', {
'from_language': from,
'to_language': to
});
}
};
window.trackUpgradeClick = function(location) {
if (typeof gtag !== 'undefined') {
gtag('event', 'upgrade_click', {
'click_location': location
});
}
};