Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
94 lines (82 loc) · 4.22 KB
/
Copy pathindex.html
File metadata and controls
94 lines (82 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Downloads</title>
<style>
:root { --bg:#0f172a; --card:#111827; --text:#e5e7eb; --muted:#9ca3af; --accent:#22d3ee; }
html,body{height:100%}
body{margin:0;font-family:system-ui,-apple-system,Segoe UI,Roboto,Inter,Ubuntu,Arial,sans-serif;background:var(--bg);color:var(--text);display:flex;align-items:center;justify-content:center}
.wrap{max-width:860px;width:100%;padding:24px}
h1{margin:0 0 12px;font-weight:700;letter-spacing:.2px}
p.desc{margin:0 0 24px;color:var(--muted)}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:14px}
.card{background:linear-gradient(180deg,rgba(255,255,255,.06),transparent 60%),var(--card);border:1px solid rgba(255,255,255,.08);border-radius:16px;padding:16px;display:flex;flex-direction:column;gap:10px}
.title{font-weight:600}
.meta{font-size:.9rem;color:var(--muted)}
.btn{appearance:none;border:none;background:var(--accent);color:#0a0a0a;font-weight:700;padding:10px 12px;border-radius:12px;cursor:pointer;transition:transform .04s ease,filter .2s ease}
.btn:hover{filter:brightness(1.1)}
.btn:active{transform:translateY(1px)}
footer{margin-top:18px;color:var(--muted);font-size:.9rem}
a.inline{color:var(--accent);text-decoration:none}
</style>
</head>
<body>
<main class="wrap">
<h1>Downloads</h1>
<p class="desc">Click a button to download a file. Edit the <code>documents</code> list in the script to add your own.</p>
<section id="list" class="grid" aria-live="polite" aria-busy="true"></section>
<footer>
<span>Tip: For best results, host files on the same domain/folder.</span>
</footer>
</main>
<script>
const documents = [
{ name: "Multivariate models of animal sex", type: "PDF", size: "1.05 MB", url: "files/Multivariate_models_of_animal_sex.pdf" },
{ name: "Sex Spectrum", type: "PNG", size: "4.29 MB", url: "files/sex-as-a-spectrum-enhanced_2x_clean.png" },
{ name: "Sex Spectrum (different format)", type: "WEBP", size: "216 KB", url: "files/sex-as-a-spectrum-enhanced_2x_clean.webp" },
{ name: "Sex Spectrum - Plus", type: "PNG", size: "16 KB", url: "files/sex-as-a-spectrum-plus-enhanced_2x_sharpened.png" }
];
const list = document.getElementById('list');
function filenameFromUrl(url) {
try { return new URL(url, location.href).pathname.split('/').pop() || 'download'; }
catch { return 'download'; }
}
function downloadFile(url, suggestedName){
const a = document.createElement('a');
const u = new URL(url, location.href);
a.href = u.href;
// Only set download for same-origin; otherwise many browsers ignore it.
if (u.origin === location.origin) {
a.setAttribute('download', suggestedName || filenameFromUrl(url));
} else {
a.target = '_blank'; // open cross-origin in a new tab as a fallback
a.rel = 'noopener';
}
document.body.appendChild(a);
a.click();
a.remove();
}
function createCard(doc){
const card = document.createElement('article'); card.className = 'card';
const title = Object.assign(document.createElement('div'), { className: 'title', textContent: doc.name });
const meta = Object.assign(document.createElement('div'), { className: 'meta', textContent: [doc.type, doc.size].filter(Boolean).join(' • ') });
const btn = Object.assign(document.createElement('button'), { className: 'btn', type: 'button', textContent: 'Download' });
btn.setAttribute('aria-label', `Download ${doc.name}${doc.type?(' '+doc.type):''}`);
btn.addEventListener('click', () => downloadFile(doc.url, filenameFromUrl(doc.url)));
card.append(title, meta, btn);
return card;
}
function render(){
list.innerHTML = '';
documents.forEach(doc => list.appendChild(createCard(doc)));
list.setAttribute('aria-busy','false');
}
render();
</script>
<noscript>
Enable JavaScript to see the download buttons.
</noscript>
</body>
</html>