Created repository again
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
## [Сайт](https://iliamiheev.github.io/practicum/) на котором можно генерировать QR коды
|
||||
|
||||
##### Вводите текст и генерируете. Всё просто
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Генератор QR-кодов</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/qrcode/build/qrcode.min.js"></script>
|
||||
<link rel="stylesheet" href="./style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Генератор QR-кодов</h1>
|
||||
<input type="text" id="text-input" placeholder="Введите текст">
|
||||
<br>
|
||||
<button id="generate-btn">Сгенерировать QR-код</button>
|
||||
<button id="download-qr-btn">Скачать QR-код</button>
|
||||
<button id="del-qr-btn">Очистить поля</button>
|
||||
<p id="error"></p>
|
||||
<div id="qr-code"></div>
|
||||
|
||||
<script src="./script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,67 @@
|
||||
const textInput = document.getElementById('text-input');
|
||||
const generateBtn = document.getElementById('generate-btn');
|
||||
const downloadQrBtn = document.getElementById('download-qr-btn');
|
||||
const qrCodeDiv = document.getElementById('qr-code');
|
||||
const delBtn = document.getElementById('del-qr-btn');
|
||||
const textError = document.getElementById('error');
|
||||
|
||||
function logMessage(message, color = 'red') {
|
||||
textError.innerText = message;
|
||||
textError.style.color = color;
|
||||
}
|
||||
|
||||
// Генерация QR-кода
|
||||
function generateQRCode() {
|
||||
const text = textInput.value.trim();
|
||||
if (!text) {
|
||||
logMessage('Введите текст для генерации QR-кода!');
|
||||
return;
|
||||
}
|
||||
qrCodeDiv.innerHTML = '';
|
||||
QRCode.toCanvas(text, (error, canvas) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
logMessage('Ошибка при генерации QR-кода.');
|
||||
return;
|
||||
}
|
||||
qrCodeDiv.appendChild(canvas);
|
||||
logMessage('');
|
||||
});
|
||||
}
|
||||
|
||||
// Обработчик клика по кнопке "Сгенерировать"
|
||||
generateBtn.addEventListener('click', generateQRCode);
|
||||
|
||||
// Обработчик нажатия клавиши "Enter" в поле ввода
|
||||
textInput.addEventListener('keypress', (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
generateQRCode();
|
||||
}
|
||||
});
|
||||
|
||||
// Скачивание QR-кода
|
||||
downloadQrBtn.addEventListener('click', () => {
|
||||
text = textInput.value.slice(0, 20)
|
||||
const canvas = qrCodeDiv.querySelector('canvas');
|
||||
if (!canvas) {
|
||||
logMessage('QR-код не сгенерирован!');
|
||||
return;
|
||||
}
|
||||
if (!text) {
|
||||
logMessage('Отсутствует текст в поле для ввода');
|
||||
return;
|
||||
}
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.href = canvas.toDataURL('image/png');
|
||||
link.download = `qr-code-${text}.png`;
|
||||
link.click();
|
||||
logMessage('QR-код скачан!', 'green');
|
||||
});
|
||||
|
||||
// Удаление данных
|
||||
delBtn.addEventListener('click', () => {
|
||||
textInput.value = '';
|
||||
qrCodeDiv.innerHTML = '';
|
||||
textError.innerText = '';
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 20px;
|
||||
padding: 0;
|
||||
background-color: #f9f9f9;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
input, button {
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 5px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #007bff;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
#qr-code {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
#qr-code img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
Reference in New Issue
Block a user