Prosta strona w html, która przechowuje dodane kody w pamięci przeglądarki.
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lista Kodów Kreskowych</title>
<script src="https://cdn.jsdelivr.net/npm/
[email protected]/dist/JsBarcode.all.min.js"></script>
<style>
:root {
--bg: #f4f6f8;
--primary: #1e88e5;
--danger: #e53935;
--text: #333;
--white: #fff;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', sans-serif;
background: var(--bg);
margin: 0;
padding: 0;
color: var(--text);
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1, h2 {
text-align: center;
}
.form {
display: flex;
flex-direction: column;
gap: 10px;
margin: 20px 0;
}
.form input {
padding: 12px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 6px;
width: 100%;
}
.form button {
padding: 12px;
background-color: var(--primary);
border: none;
color: var(--white);
font-size: 16px;
cursor: pointer;
border-radius: 6px;
transition: background 0.3s;
}
.form button:hover {
background-color: #1565c0;
}
.codes-list {
display: flex;
flex-direction: column;
gap: 20px;
}
.code-item {
background: var(--white);
padding: 15px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.05);
}
.code-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.code-text {
font-size: 18px;
font-weight: 500;
}
.code-item button {
background-color: var(--danger);
color: var(--white);
border: none;
padding: 8px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
transition: background 0.3s;
}
.code-item button:hover {
background-color: #b71c1c;
}
svg {
margin-top: 10px;
width: 100%;
}
@media (max-width: 600px) {
.code-text {
font-size: 16px;
}
.form button {
font-size: 15px;
}
.code-item {
padding: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Lista Kodów Kreskowych</h1>
<div class="form">
<input type="text" id="codeInput" placeholder="Wprowadź dokładnie 15 cyfr" maxlength="15" />
<button onclick="addCode()">Dodaj kod</button>
</div>
<h2>Dodane kody</h2>
<div id="codeList" class="codes-list"></div>
</div>
<script>
let codes = JSON.parse(localStorage.getItem('codes')) || [];
function saveToLocalStorage() {
localStorage.setItem('codes', JSON.stringify(codes));
}
function addCode() {
const input = document.getElementById('codeInput');
const value = input.value.trim();
if (/^\d{15}$/.test(value)) {
codes.push(value);
input.value = '';
saveToLocalStorage();
renderCodes();
} else {
alert('Wpisz dokładnie 15 cyfr!');
}
}
function deleteCode(index) {
if (confirm("Na pewno chcesz usunąć ten kod?")) {
codes.splice(index, 1);
saveToLocalStorage();
renderCodes();
}
}
function renderCodes() {
const list = document.getElementById('codeList');
list.innerHTML = '';
codes.forEach((code, index) => {
const item = document.createElement('div');
item.className = 'code-item';
const header = document.createElement('div');
header.className = 'code-header';
const text = document.createElement('div');
text.className = 'code-text';
text.textContent = code;
const delBtn = document.createElement('button');
delBtn.textContent = 'Usuń';
delBtn.onclick = () => deleteCode(index);
header.appendChild(text);
header.appendChild(delBtn);
const barcode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
JsBarcode(barcode, code, { format: "CODE128", width: 2, height: 50 });
item.appendChild(header);
item.appendChild(barcode);
list.appendChild(item);
});
}
renderCodes();
</script>
</body>
</html>
Jak będziesz potrzebował z zapisem do .txt lub .json to trzeba zbudować Prosty backend np. w php
@edit
musze zaczac patrzec na daty