-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
210 lines (175 loc) · 6.57 KB
/
script.js
File metadata and controls
210 lines (175 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Theme Handling
const themeToggle = document.getElementById('theme-toggle');
const htmlElement = document.documentElement;
const themeIcon = themeToggle.querySelector('.icon');
// Check local storage or system preference
const savedTheme = localStorage.getItem('theme');
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
if (savedTheme) {
htmlElement.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
} else {
htmlElement.setAttribute('data-theme', systemTheme);
updateThemeIcon(systemTheme);
}
themeToggle.addEventListener('click', () => {
const currentTheme = htmlElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
htmlElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
});
function updateThemeIcon(theme) {
themeIcon.textContent = theme === 'dark' ? '☀️' : '🌙';
}
// QR Code Initialization
const qrCode = new QRCodeStyling({
width: 300,
height: 300,
type: "canvas",
data: "https://www.instagram.com/piyush_kadam96k",
image: "",
dotsOptions: {
color: "#000000",
type: "square"
},
backgroundOptions: {
color: "#ffffff",
},
imageOptions: {
crossOrigin: "anonymous",
margin: 10
}
});
let currentType = 'url';
let currentShape = 'square';
let currentDotsColor = '#000000';
let currentBgColor = '#ffffff';
// Render Initial QR
qrCode.append(document.getElementById("qr-code-container"));
// Data Handlers
function getQRData() {
switch (currentType) {
case 'url':
return document.getElementById('text').value.trim();
case 'text':
return document.getElementById('text_content').value.trim();
case 'wifi':
const ssid = document.getElementById('wifi_ssid').value.trim();
const pass = document.getElementById('wifi_password').value.trim();
return ssid ? `WIFI:S:${ssid};T:WPA;P:${pass};;` : '';
case 'contact':
const n = document.getElementById('contact_name').value.trim();
const p = document.getElementById('contact_phone').value.trim();
const e = document.getElementById('contact_email').value.trim();
return (n || p || e) ? `BEGIN:VCARD\nVERSION:3.0\nN:${n}\nTEL:${p}\nEMAIL:${e}\nEND:VCARD` : '';
case 'email':
const mail = document.getElementById('email_to').value.trim();
const subj = document.getElementById('email_subject').value.trim();
return mail ? `mailto:${mail}?subject=${encodeURIComponent(subj)}` : '';
case 'phone':
const tel = document.getElementById('phone_number').value.trim();
return tel ? `tel:${tel}` : '';
default:
return '';
}
}
function getShapeOptions(shape) {
const map = {
'square': 'square',
'rounded': 'rounded',
'circle': 'dots',
'classy': 'classy',
'diamond': 'classy-rounded',
'dot': 'extra-rounded'
};
return { type: map[shape] || 'square' };
}
function updateQR() {
const data = getQRData();
if (!data) return;
const dotsOptions = getShapeOptions(currentShape);
dotsOptions.color = currentDotsColor;
qrCode.update({
data: data,
dotsOptions: dotsOptions,
backgroundOptions: {
color: currentBgColor
}
});
}
// Event Listeners
// Type Tabs
document.querySelectorAll('.qr-type-tab').forEach(tab => {
tab.addEventListener('click', () => {
// Toggle Active Classes
document.querySelectorAll('.qr-type-tab').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// Show/Hide Sections
document.querySelectorAll('.qr-section').forEach(s => s.classList.add('hidden'));
currentType = tab.dataset.type;
const section = document.getElementById(`${currentType}-section`);
if (section) section.classList.remove('hidden');
updateQR();
});
});
// Design Tabs
document.querySelectorAll('.design-tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('.design-tab').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
document.querySelectorAll('.design-section').forEach(s => s.classList.add('hidden'));
const target = document.getElementById(`${tab.dataset.tab}-section`);
if (target) target.classList.remove('hidden');
});
});
// Shape Options
document.querySelectorAll('.shape-option').forEach(opt => {
opt.addEventListener('click', () => {
document.querySelectorAll('.shape-option').forEach(o => o.classList.remove('active'));
opt.classList.add('active');
currentShape = opt.dataset.shape;
updateQR();
});
});
// Color Inputs
function handleColorUpdate(id, isBg) {
const input = document.getElementById(id);
const val = input.value;
document.getElementById(id.replace('color', 'hex')).textContent = val.toUpperCase();
if (isBg) currentBgColor = val;
else currentDotsColor = val;
updateQR();
}
document.getElementById('border-color').addEventListener('input', () => handleColorUpdate('border-color', false));
document.getElementById('background-color').addEventListener('input', () => handleColorUpdate('background-color', true));
// Text Inputs
document.querySelectorAll('input, textarea').forEach(el => {
el.addEventListener('input', updateQR);
});
// Download
window.downloadQR = () => {
qrCode.download({ name: "qr-code-pro", extension: "png" });
};
// Initial run
updateQR();
// Visitor Counter
function updateVisitorCount() {
const counterElement = document.getElementById('visitor-count');
if (!counterElement) return;
// Get current count from local storage or start at 500
let count = parseInt(localStorage.getItem('visitorCount')) || 500;
// Increment count
count++;
// Save new count
localStorage.setItem('visitorCount', count);
// Update display with comma formatting
// Update display with formatting
if (count >= 1000) {
counterElement.textContent = (count / 1000).toFixed(1) + 'k';
} else {
counterElement.textContent = count.toLocaleString();
}
}
// Initialize counter
document.addEventListener('DOMContentLoaded', updateVisitorCount);