<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Font Organizer</title>
<!-- JSZip Library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.0/jszip.min.js"></script>
<style>
/* Resetting default styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
background-color: #f5f5f5;
color: #333;
height: 100vh;
display: flex;
flex-direction: column;
}
header {
background-color: #fff;
padding: 20px 40px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
display: flex;
align-items: center;
justify-content: space-between;
}
header h1 {
font-size: 24px;
color: #111;
}
main {
flex: 1;
display: flex;
overflow: hidden;
}
/* Sidebar Styles */
.sidebar {
width: 250px;
background-color: #fff;
border-right: 1px solid #ddd;
padding: 20px;
overflow-y: auto;
}
.sidebar h2 {
font-size: 18px;
margin-bottom: 10px;
}
.sidebar ul {
list-style: none;
}
.sidebar li {
padding: 10px;
margin-bottom: 5px;
background-color: #f0f0f0;
cursor: pointer;
border-radius: 4px;
display: flex;
justify-content: space-between;
align-items: center;
}
.sidebar li.active {
background-color: #d0d0d0;
}
.sidebar li:hover {
background-color: #e0e0e0;
}
.sidebar button {
background-color: #007bff;
color: #fff;
border: none;
padding: 8px 12px;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
width: 100%;
}
.sidebar button:hover {
background-color: #0056b3;
}
/* Content Area Styles */
.content {
flex: 1;
padding: 20px;
overflow-y: auto;
}
.upload-section {
margin-bottom: 20px;
padding: 20px;
background-color: #fff;
border: 2px dashed #ccc;
border-radius: 6px;
text-align: center;
cursor: pointer;
transition: background-color 0.3s;
}
.upload-section.dragover {
background-color: #e6f7ff;
border-color: #1890ff;
}
.upload-section input {
display: none;
}
.fonts-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 15px;
}
.font-card {
background-color: #fff;
padding: 10px;
border-radius: 4px;
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
word-break: break-word;
}
.font-card.dragging {
opacity: 0.5;
}
.collections {
margin-bottom: 20px;
}
.collections h3 {
margin-bottom: 10px;
font-size: 16px;
color: #555;
}
.collections ul {
list-style: none;
}
.collections li {
padding: 6px 10px;
background-color: #f9f9f9;
margin-bottom: 5px;
border-radius: 4px;
display: flex;
justify-content: space-between;
align-items: center;
}
.collections li span {
flex: 1;
}
.collections li button {
background: none;
border: none;
color: #888;
cursor: pointer;
margin-left: 5px;
}
.download-section {
padding: 20px;
background-color: #fff;
border-top: 1px solid #ddd;
text-align: center;
}
.download-section button {
background-color: #28a745;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.download-section button:hover {
background-color: #218838;
}
.instructions {
margin-top: 10px;
font-size: 14px;
color: #555;
}
/* Modal Styles */
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
display: none;
align-items: center;
justify-content: center;
padding: 20px;
}
.modal-content {
background-color: #fff;
padding: 20px;
width: 100%;
max-width: 400px;
border-radius: 6px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.modal-content h3 {
margin-bottom: 15px;
font-size: 18px;
}
.modal-content input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
}
.modal-content button {
background-color: #007bff;
color: #fff;
border: none;
padding: 10px 16px;
border-radius: 4px;
cursor: pointer;
}
.modal-content button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<header>
<h1>Font Organizer</h1>
</header>
<main>
<!-- Sidebar -->
<div class="sidebar">
<h2>Collections</h2>
<ul id="collection-list">
<!-- Dynamic Collections -->
</ul>
<button id="add-collection-btn">+ Add Collection</button>
</div>
<!-- Content Area -->
<div class="content">
<div class="upload-section" id="upload-section">
<p>Drag & Drop Fonts Here or Click to Upload</p>
<input type="file" id="font-input" multiple accept=".ttf,.otf,.woff,.woff2,.eot,.svg">
</div>
<div class="collections" id="current-collection">
<h3>Select a collection to organize fonts</h3>
</div>
<div class="fonts-grid" id="fonts-grid">
<!-- Uploaded Fonts -->
</div>
</div>
</main>
<!-- Download Section -->
<div class="download-section">
<button id="download-zip-btn">Download Organized Fonts as ZIP</button>
<div class="instructions" id="instructions" style="display: none;">
<p>After downloading, right-click the ZIP file and select "Extract All" or use your preferred unzipping tool.</p>
</div>
</div>
<!-- Modal for Adding Collection -->
<div class="modal" id="modal">
<div class="modal-content">
<h3>Add New Collection</h3>
<input type="text" id="collection-name-input" placeholder="Collection Name">
<button id="save-collection-btn">Save</button>
</div>
</div>
<script>
// JavaScript Code for Functionality
// DOM Elements
const uploadSection = document.getElementById('upload-section');
const fontInput = document.getElementById('font-input');
const fontsGrid = document.getElementById('fonts-grid');
const addCollectionBtn = document.getElementById('add-collection-btn');
const modal = document.getElementById('modal');
const saveCollectionBtn = document.getElementById('save-collection-btn');
const collectionNameInput = document.getElementById('collection-name-input');
const collectionList = document.getElementById('collection-list');
const currentCollection = document.getElementById('current-collection');
const downloadZipBtn = document.getElementById('download-zip-btn');
const instructions = document.getElementById('instructions');
let collections = {};
let currentColl = null;
let fonts = [];
// Initialize with Default Collection
collections['Uncategorized'] = [];
currentColl = 'Uncategorized';
renderCollections();
// Event Listeners for Upload
uploadSection.addEventListener('click', () => {
fontInput.click();
});
fontInput.addEventListener('change', (e) => {
handleFiles(e.target.files);
});
// Drag & Drop Events
uploadSection.addEventListener('dragover', (e) => {
e.preventDefault();
uploadSection.classList.add('dragover');
});
uploadSection.addEventListener('dragleave', (e) => {
e.preventDefault();
uploadSection.classList.remove('dragover');
});
uploadSection.addEventListener('drop', (e) => {
e.preventDefault();
uploadSection.classList.remove('dragover');
if (e.dataTransfer.files) {
handleFiles(e.dataTransfer.files);
}
});
// Handle Uploaded Files
function handleFiles(files) {
[...files].forEach(file => {
if (isFontFile(file)) {
const reader = new FileReader();
reader.onload = (e) => {
const fontData = {
name: file.name,
file: file,
data: e.target.result,
collection: currentColl
};
fonts.push(fontData);
collections[currentColl].push(fontData);
renderFonts();
};
reader.readAsArrayBuffer(file);
} else {
alert(`${file.name} is not a supported font file.`);
}
});
}
function isFontFile(file) {
const fontExtensions = ['.ttf', '.otf', '.woff', '.woff2', '.eot', '.svg'];
return fontExtensions.some(ext => file.name.toLowerCase().endsWith(ext));
}
// Render Collections in Sidebar
function renderCollections() {
collectionList.innerHTML = '';
for (let coll in collections) {
const li = document.createElement('li');
li.textContent = coll;
if (coll === currentColl) {
li.classList.add('active');
}
// Switch Collection on Click
li.addEventListener('click', () => {
currentColl = coll;
renderCollections();
renderFonts();
renderCurrentCollection();
});
collectionList.appendChild(li);
}
}
// Render Fonts in Content Area
function renderFonts() {
fontsGrid.innerHTML = '';
collections[currentColl].forEach((font, index) => {
const card = document.createElement('div');
card.classList.add('font-card');
card.draggable = true;
card.textContent = font.name;
// Drag Events
card.addEventListener('dragstart', (e) => {
e.dataTransfer.setData('text/plain', font.name);
setTimeout(() => {
card.classList.add('dragging');
}, 0);
});
card.addEventListener('dragend', () => {
card.classList.remove('dragging');
});
fontsGrid.appendChild(card);
});
}
// Render Current Collection Info
function renderCurrentCollection() {
currentCollection.innerHTML = '';
if (currentColl === 'Uncategorized') {
currentCollection.innerHTML = '<h3>Uncategorized Fonts</h3>';
} else {
const heading = document.createElement('h3');
heading.textContent = `Collection: ${currentColl}`;
currentCollection.appendChild(heading);
}
}
// Add Collection
addCollectionBtn.addEventListener('click', () => {
modal.style.display = 'flex';
collectionNameInput.value = '';
collectionNameInput.focus();
});
saveCollectionBtn.addEventListener('click', () => {
const name = collectionNameInput.value.trim();
if (name && !collections[name]) {
collections[name] = [];
currentColl = name;
renderCollections();
renderFonts();
renderCurrentCollection();
modal.style.display = 'none';
} else if (collections[name]) {
alert('Collection name already exists.');
} else {
alert('Please enter a valid collection name.');
}
});
// Close Modal when clicking outside
window.addEventListener('click', (e) => {
if (e.target === modal) {
modal.style.display = 'none';
}
});
// Download ZIP
downloadZipBtn.addEventListener('click', async () => {
if (fonts.length === 0) {
alert('No fonts to download.');
return;
}
const zip = new JSZip();
for (let coll in collections) {
if (collections[coll].length > 0) {
const folder = zip.folder(coll);
collections[coll].forEach(font => {
folder.file(font.name, font.file);
});
}
}
const content = await zip.generateAsync({ type: "blob" });
const a = document.createElement('a');
a.href = URL.createObjectURL(content);
a.download = "organized_fonts.zip";
a.click();
instructions.style.display = 'block';
});
// Initial Render
renderFonts();
renderCurrentCollection();
</script>
</body>
</html>