-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
79 lines (68 loc) · 2.66 KB
/
script.js
File metadata and controls
79 lines (68 loc) · 2.66 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
document.addEventListener('DOMContentLoaded', () => {
const generateBtn = document.getElementById('generate');
const printBtn = document.getElementById('print');
const qrcodeDiv = document.getElementById('qrcode');
const qrOutput = document.querySelector('.qr-output');
let qrcode = null;
generateBtn.addEventListener('click', () => {
const ssid = document.getElementById('ssid').value;
const password = document.getElementById('password').value;
const encryption = document.getElementById('encryption').value;
const showSsid = document.getElementById('showSsid').checked;
const showPassword = document.getElementById('showPassword').checked;
const additionalText = document.getElementById('additionalText').value;
if (!ssid) {
alert('Please enter a network name (SSID)');
return;
}
if (encryption !== 'nopass' && !password) {
alert('Please enter a password');
return;
}
const qrContent = `WIFI:T:${encryption};S:${ssid};P:${password};;`;
// Clear previous QR code and details
qrcodeDiv.innerHTML = '';
qrOutput.classList.add('visible');
// Determine QR code colors based on color scheme
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
const qrColors = isDarkMode ? {
colorDark: "#ffffff",
colorLight: "#2d2d2d"
} : {
colorDark: "#000000",
colorLight: "#ffffff"
};
// Generate new QR code
qrcode = new QRCode(qrcodeDiv, {
text: qrContent,
width: 256,
height: 256,
...qrColors,
correctLevel: QRCode.CorrectLevel.H
});
// Add details text if any options are selected
if (showSsid || showPassword || additionalText) {
const detailsDiv = document.createElement('div');
detailsDiv.className = 'details-text';
let details = '';
if (showSsid) {
details += `Network: ${ssid}\n`;
}
if (showPassword) {
details += `Password: ${password}\n`;
}
if (additionalText) {
details += `\n${additionalText}`;
}
detailsDiv.textContent = details.trim();
qrcodeDiv.appendChild(detailsDiv);
}
});
printBtn.addEventListener('click', () => {
if (qrcodeDiv.innerHTML) {
window.print();
} else {
alert('Please generate a QR code first');
}
});
});