Something went wrong. Try again.
A fork of https://github.com/crosspoint-reader/crosspoint-reader
Something went wrong. Try again.
11 kB · 323 lines
HTML
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324<!DOCTYPE html><html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>CrossPoint Reader - Fonts</title> <style> :root { --font-color: #333; --bg: #f5f5f5; --title-color: #2c3e50; --card-bg: #FFF; --label-color: #7f8c8d; --border-color: #eee; --accent-color: rgb(110, 154, 130); --accent-hover-color: #5a8c73; --danger-color: #e74c3c; --danger-hover: #c0392b; } @media (prefers-color-scheme: dark) { :root { --font-color: #f5f5f5; --bg: #333; --title-color: #ecf0f1; --card-bg: #444; --label-color: #bdc3c7; --border-color: #555; color-scheme: dark; } } body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; background-color: var(--bg); color: var(--font-color); } h1 { color: var(--title-color); border-bottom: 2px solid var(--accent-color); padding-bottom: 10px; } h2 { color: var(--title-color); margin-top: 0; } h3 { margin: 0 0 8px 0; } .card { background: var(--card-bg); border-radius: 8px; padding: 20px; margin: 15px 0; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .nav-links { margin: 20px 0; display: flex; gap: 10px; } .nav-links a { padding: 10px 20px; color: var(--font-color); text-decoration: none; border-radius: 4px; } .nav-links a.active { background-color: var(--accent-color); color: white; } .nav-links a:not(.active):hover { background-color: var(--accent-hover-color); color: white; } .family { border-bottom: 1px solid var(--border-color); padding: 12px 0; display: flex; justify-content: space-between; align-items: center; } .family:last-child { border-bottom: none; } .family-info { flex: 1; } .family-meta { color: var(--label-color); font-size: 0.9em; } .btn { padding: 6px 16px; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9em; } .btn-danger { background: var(--danger-color); color: white; } .btn-danger:hover { background: var(--danger-hover); } .btn-primary { background: var(--accent-color); color: white; } .btn-primary:hover { background: var(--accent-hover-color); } .upload-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .upload-form input[type="text"] { padding: 6px 10px; border: 1px solid var(--border-color); border-radius: 4px; background: var(--bg); color: var(--font-color); } .upload-form input[type="file"] { flex: 1; min-width: 200px; } #status { margin-top: 10px; padding: 8px; border-radius: 4px; display: none; } .status-ok { background: #d4edda; color: #155724; display: block !important; } .status-err { background: #f8d7da; color: #721c24; display: block !important; } .empty { color: var(--label-color); text-align: center; padding: 20px; } </style> </head> <body> <h1>📚 CrossPoint Reader</h1>
<div class="nav-links"> <a href="/">Home</a> <a href="/files">File Manager</a> <a href="/settings">Settings</a> <a href="/fonts" class="active">Fonts</a> </div>
<div class="card"> <h2>Installed Fonts</h2> <div id="families"><p class="empty">Loading...</p></div> </div>
<div class="card"> <h2>Upload Font</h2> <form class="upload-form" id="uploadForm"> <input type="file" id="fontFiles" webkitdirectory directory multiple required /> <button type="submit" class="btn btn-primary">Upload</button> </form> <p id="pickedInfo" class="family-meta" style="margin: 8px 0 0;"></p> <div id="status"></div> </div>
<script> function formatSize(bytes) { if (bytes >= 1048576) return (bytes / 1048576).toFixed(1) + ' MB'; if (bytes >= 1024) return (bytes / 1024).toFixed(0) + ' KB'; return bytes + ' B'; }
async function loadFonts() { const el = document.getElementById('families'); try { const res = await fetch('/api/fonts'); const data = await res.json(); // Build rows with DOM APIs and textContent so on-device family names // (which can contain arbitrary characters) cannot break markup or // execute script via innerHTML / inline onclick interpolation. el.replaceChildren(); if (!data.families || data.families.length === 0) { const p = document.createElement('p'); p.className = 'empty'; p.textContent = 'No fonts installed'; el.appendChild(p); return; } for (const f of data.families) { const row = document.createElement('div'); row.className = 'family';
const info = document.createElement('div'); info.className = 'family-info'; const h3 = document.createElement('h3'); h3.textContent = f.name; info.appendChild(h3); const meta = document.createElement('span'); meta.className = 'family-meta'; const sizes = (f.sizes || []).join(', '); const filesSizes = (f.files || []).map(fi => formatSize(fi.size)).join(' + '); meta.textContent = sizes + 'pt · ' + filesSizes; info.appendChild(meta);
const btn = document.createElement('button'); btn.className = 'btn btn-danger'; btn.textContent = 'Delete'; // Capture name in the closure rather than interpolating into onclick. const familyName = f.name; btn.addEventListener('click', () => deleteFamily(familyName));
row.appendChild(info); row.appendChild(btn); el.appendChild(row); } } catch (e) { el.replaceChildren(); const p = document.createElement('p'); p.className = 'empty'; p.textContent = 'Failed to load font list'; el.appendChild(p); } }
async function deleteFamily(name) { if (!confirm('Delete font family "' + name + '"?')) return; const status = document.getElementById('status'); status.className = ''; status.style.display = 'block'; status.textContent = 'Deleting ' + name + '...'; try { const res = await fetch('/api/fonts/delete', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({family: name}) }); if (res.ok) { status.className = 'status-ok'; status.textContent = 'Deleted "' + name + '".'; } else { status.className = 'status-err'; status.textContent = 'Failed to delete "' + name + '".'; } } catch (err) { status.className = 'status-err'; status.textContent = 'Delete error: ' + err.message; } await loadFonts(); }
// Derive family name from a .cpfont filename: take everything before the // last '-' or '_' (that separator precedes the size suffix, e.g. Bookerly_12.cpfont). function familyFromFilename(name) { const stem = name.replace(/\.cpfont$/i, ''); const cut = Math.max(stem.lastIndexOf('-'), stem.lastIndexOf('_')); return cut > 0 ? stem.slice(0, cut) : stem; }
// Sanitize to match firmware's [A-Za-z0-9_-]+ pattern. function sanitizeFamily(raw) { return raw.replace(/[^A-Za-z0-9_-]/g, '_'); }
function cpfontFilesOnly(fileList) { return Array.from(fileList).filter(f => /\.cpfont$/i.test(f.name)); }
document.getElementById('fontFiles').addEventListener('change', function() { const info = document.getElementById('pickedInfo'); const files = cpfontFilesOnly(this.files); if (files.length === 0) { info.textContent = 'No .cpfont files found in the selected folder.'; return; } const family = sanitizeFamily(familyFromFilename(files[0].name)); info.textContent = files.length + ' file' + (files.length === 1 ? '' : 's') + ' → family "' + family + '"'; });
document.getElementById('uploadForm').addEventListener('submit', async function(e) { e.preventDefault(); const status = document.getElementById('status'); const files = cpfontFilesOnly(document.getElementById('fontFiles').files); if (files.length === 0) { status.className = 'status-err'; status.style.display = 'block'; status.textContent = 'No .cpfont files selected.'; return; }
// A directory picker may include files from multiple family subfolders. // Reject that up front — otherwise files[0]'s family is silently reused // for every upload, corrupting the install layout. const families = [...new Set(files.map(f => sanitizeFamily(familyFromFilename(f.name))))]; if (families.length !== 1) { status.className = 'status-err'; status.style.display = 'block'; status.textContent = 'Please select files from a single font family.'; return; } const family = families[0];
status.className = ''; status.style.display = 'block';
let uploaded = 0; for (const file of files) { status.textContent = 'Uploading ' + (uploaded + 1) + '/' + files.length + ': ' + file.name; const formData = new FormData(); formData.append('family', family); formData.append('file', file, file.name); try { const res = await fetch('/api/fonts/upload', { method: 'POST', body: formData }); const data = await res.json(); if (!data.ok) { status.className = 'status-err'; status.textContent = 'Failed on ' + file.name + ': ' + (data.error || 'unknown error'); await loadFonts(); return; } } catch (err) { status.className = 'status-err'; status.textContent = 'Upload error on ' + file.name + ': ' + err.message; await loadFonts(); return; } uploaded++; }
status.className = 'status-ok'; status.textContent = 'Uploaded ' + uploaded + ' file' + (uploaded === 1 ? '' : 's') + ' to family "' + family + '".'; await loadFonts(); });
loadFonts(); </script> </body></html>