Small changes
This commit is contained in:
403
web/index.html
403
web/index.html
@@ -3,75 +3,353 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Ferurl - URL Shortener</title>
|
||||
<title>Ferurl - Modern URL Shortener</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap">
|
||||
<style>
|
||||
:root {
|
||||
--primary-color: #3b82f6;
|
||||
--primary-hover: #2563eb;
|
||||
--secondary-color: #f3f4f6;
|
||||
--text-color: #1f2937;
|
||||
--light-text: #6b7280;
|
||||
--success-color: #10b981;
|
||||
--error-color: #ef4444;
|
||||
--border-radius: 8px;
|
||||
--box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
background-color: #f9fafb;
|
||||
color: var(--text-color);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.container {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
margin-top: 20px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
|
||||
.app-container {
|
||||
width: 100%;
|
||||
max-width: 550px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
color: var(--primary-color);
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.logo span {
|
||||
color: var(--light-text);
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: white;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--box-shadow);
|
||||
padding: 2rem;
|
||||
margin-bottom: 1.5rem;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
label {
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
font-weight: 500;
|
||||
font-size: 0.875rem;
|
||||
color: var(--light-text);
|
||||
}
|
||||
|
||||
input[type="url"] {
|
||||
padding: 8px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: var(--border-radius);
|
||||
font-size: 1rem;
|
||||
transition: border-color 0.15s ease;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input[type="url"]:focus {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
|
||||
}
|
||||
|
||||
input[type="url"]::placeholder {
|
||||
color: #d1d5db;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #4CAF50;
|
||||
padding: 0.75rem 1.5rem;
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
padding: 10px 15px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
border-radius: var(--border-radius);
|
||||
font-weight: 500;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
transition: background-color 0.2s ease, transform 0.1s ease;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #45a049;
|
||||
background-color: var(--primary-hover);
|
||||
}
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
background-color: #f9f9f9;
|
||||
|
||||
button:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.btn-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.loader {
|
||||
display: none;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
border-top-color: white;
|
||||
animation: spin 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.result {
|
||||
display: none;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.result.visible {
|
||||
opacity: 1;
|
||||
animation: slideIn 0.5s ease forwards;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
transform: translateY(20px);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.result-card {
|
||||
background-color: white;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--box-shadow);
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.result-title {
|
||||
font-size: 1rem;
|
||||
color: var(--light-text);
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.url-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
background-color: var(--secondary-color);
|
||||
border-radius: var(--border-radius);
|
||||
padding: 0.75rem 1rem;
|
||||
margin-bottom: 1rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.short-url {
|
||||
font-weight: 500;
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-width: 80%;
|
||||
}
|
||||
|
||||
.short-url:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
background-color: transparent;
|
||||
color: var(--primary-color);
|
||||
border: 1px solid var(--primary-color);
|
||||
padding: 0.375rem 0.75rem;
|
||||
font-size: 0.875rem;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.copy-btn:hover {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.copy-btn.copied {
|
||||
background-color: var(--success-color);
|
||||
border-color: var(--success-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 0.75rem;
|
||||
background-color: var(--secondary-color);
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.75rem;
|
||||
color: var(--light-text);
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 2rem;
|
||||
text-align: center;
|
||||
font-size: 0.875rem;
|
||||
color: var(--light-text);
|
||||
}
|
||||
|
||||
.footer a {
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Error state */
|
||||
.error-message {
|
||||
display: none;
|
||||
color: var(--error-color);
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
border-radius: var(--border-radius);
|
||||
background-color: rgba(239, 68, 68, 0.1);
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.app-container {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.stats {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ferurl - URL Shortener</h1>
|
||||
<div class="app-container">
|
||||
<div class="logo">
|
||||
<h1>ferurl</h1>
|
||||
<span>Fast, simple URL shortening</span>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<form id="urlForm">
|
||||
<label for="longUrl">Enter your long URL:</label>
|
||||
<input type="url" id="longUrl" name="longUrl" required placeholder="https://example.com/your/very/long/url/goes/here">
|
||||
<button type="submit">Shorten URL</button>
|
||||
</form>
|
||||
<div class="card">
|
||||
<form id="urlForm">
|
||||
<div class="input-group">
|
||||
<label for="longUrl">Enter your long URL</label>
|
||||
<input
|
||||
type="url"
|
||||
id="longUrl"
|
||||
name="longUrl"
|
||||
required
|
||||
placeholder="https://example.com/your/very/long/url/goes/here"
|
||||
autocomplete="off"
|
||||
>
|
||||
</div>
|
||||
<div class="btn-container">
|
||||
<button type="submit">
|
||||
<span>Shorten URL</span>
|
||||
<span class="loader" id="submitLoader"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="error-message" id="errorMessage"></div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="result" class="result">
|
||||
<p>Your shortened URL: <a id="shortUrl" href="#" target="_blank"></a></p>
|
||||
<div class="result" id="result">
|
||||
<div class="result-card">
|
||||
<div class="result-title">Your shortened URL is ready!</div>
|
||||
<div class="url-container">
|
||||
<a id="shortUrl" class="short-url" href="#" target="_blank"></a>
|
||||
<button id="copyBtn" class="copy-btn">Copy</button>
|
||||
</div>
|
||||
<div class="stats">
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">100%</div>
|
||||
<div class="stat-label">Shorter</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">30</div>
|
||||
<div class="stat-label">Days valid</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<p>Made with ❤️ by <a href="https://github.com/ferdzo" target="_blank">ferdzo</a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -80,9 +358,19 @@
|
||||
e.preventDefault();
|
||||
|
||||
const longUrl = document.getElementById('longUrl').value;
|
||||
const submitBtn = document.querySelector('button[type="submit"]');
|
||||
const submitText = submitBtn.querySelector('span:not(.loader)');
|
||||
const loader = document.getElementById('submitLoader');
|
||||
const errorMessage = document.getElementById('errorMessage');
|
||||
|
||||
errorMessage.style.display = 'none';
|
||||
|
||||
submitText.style.display = 'none';
|
||||
loader.style.display = 'inline-block';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
try {
|
||||
const response = await fetch('http://localhost:8080/create', {
|
||||
const response = await fetch('/create', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -96,19 +384,44 @@
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Show the result
|
||||
const resultDiv = document.getElementById('result');
|
||||
const shortUrlLink = document.getElementById('shortUrl');
|
||||
|
||||
shortUrlLink.href = `http://localhost:8080/${data.shortCode}`;
|
||||
shortUrlLink.textContent = `http://localhost:8080/${data.shortCode}`;
|
||||
shortUrlLink.href = data.short_url;
|
||||
shortUrlLink.textContent = data.short_url;
|
||||
|
||||
resultDiv.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
resultDiv.classList.add('visible');
|
||||
}, 10);
|
||||
|
||||
document.getElementById('longUrl').value = '';
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
alert('Failed to shorten URL. Please try again.');
|
||||
errorMessage.textContent = 'Failed to shorten URL. Please try again.';
|
||||
errorMessage.style.display = 'block';
|
||||
} finally {
|
||||
submitText.style.display = 'inline';
|
||||
loader.style.display = 'none';
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('copyBtn').addEventListener('click', function() {
|
||||
const shortUrl = document.getElementById('shortUrl').href;
|
||||
const copyBtn = this;
|
||||
|
||||
navigator.clipboard.writeText(shortUrl).then(function() {
|
||||
copyBtn.textContent = 'Copied!';
|
||||
copyBtn.classList.add('copied');
|
||||
|
||||
setTimeout(() => {
|
||||
copyBtn.textContent = 'Copy';
|
||||
copyBtn.classList.remove('copied');
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user