-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
355 lines (305 loc) · 11.5 KB
/
script.js
File metadata and controls
355 lines (305 loc) · 11.5 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/**
* LAB NOTES — Document Navigation System
* Version 2.0.0
* Classification: INTERNAL
*/
const LAB = (() => {
let entries = [];
let currentIndex = 0;
let isIndex = true;
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
let animationsEnabled = localStorage.getItem('lab-notes-animations')
? localStorage.getItem('lab-notes-animations') !== 'off'
: !prefersReducedMotion;
const $ = (sel) => document.querySelector(sel);
const $$ = (sel) => document.querySelectorAll(sel);
function padId(n) {
return String(n).padStart(3, '0');
}
function formatDocNum(entry) {
return `LN-2026-${entry.day}`;
}
async function loadManifest() {
entries = [];
let id = 1;
while (true) {
try {
const resp = await fetch(`entries/${padId(id)}.md`);
if (!resp.ok) break;
const raw = await resp.text();
const entry = PARSE.parseEntry(raw);
if (!entry) break;
entries.push(entry);
id++;
} catch {
break;
}
}
return entries;
}
function renderIndex() {
isIndex = true;
const pageFrame = $('.page-frame');
const content = $('#content');
// Clean rot from previous entry
ROT.clean(pageFrame);
const listItems = entries.map((entry, i) => `
<li class="index-list__item" data-index="${i}" role="button" tabindex="0">
<span class="index-list__num">${padId(entry.id)}</span>
<span class="index-list__title">${entry.title}</span>
<span class="index-list__date">Day ${entry.day}</span>
</li>
`).join('');
content.innerHTML = `
<div class="doc-header">
<div class="doc-header__org">
Research Division<br>
Documentation Archive
</div>
<div class="doc-header__classification">Internal</div>
</div>
<div class="title-block">
<h1 class="title-block__title">Lab Notes</h1>
<div class="title-block__subtitle">Chronological Index — ${entries.length} ${entries.length === 1 ? 'Entry' : 'Entries'} Filed</div>
</div>
<hr class="ruler--heavy">
${entries.length > 0 ? `
<ul class="index-list">
${listItems}
</ul>
` : `
<div class="empty-state">
<div class="empty-state__icon">☐</div>
<div class="empty-state__text">No entries filed</div>
</div>
`}
<div class="doc-footer">
<span>(c) <a href="https://github.com/oatsandsugar" target="_blank" rel="noopener">@oatsandsugar</a> ${new Date().getFullYear()} — <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">CC BY-NC-SA 4.0</a></span>
<span><a href="https://far-horizons-co-op.itch.io/outliers" target="_blank" rel="noopener">Outliers</a> by Far Horizons Co-op</span>
</div>
`;
$$('.index-list__item').forEach(item => {
const handler = () => {
const idx = parseInt(item.dataset.index);
renderEntry(idx);
};
item.addEventListener('click', handler);
item.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
handler();
}
});
});
window.scrollTo(0, 0);
updateURL(null);
}
function renderEntry(index) {
isIndex = false;
currentIndex = index;
const entry = entries[index];
const pageFrame = $('.page-frame');
const content = $('#content');
// Clean previous rot
ROT.clean(pageFrame);
const sectionsHTML = entry.sections.map(section => `
<div class="section">
<h2 class="section__heading">${section.heading}</h2>
<div class="section__body">${section.content}</div>
</div>
`).join('');
const hasPrev = index > 0;
const hasNext = index < entries.length - 1;
content.innerHTML = `
<div class="doc-header">
<a href="#" class="doc-header__org" data-action="index">
Research Division<br>
Document No. ${formatDocNum(entry)}
</a>
<div class="doc-header__classification">Internal</div>
</div>
<div class="title-block">
<h1 class="title-block__title">${entry.title}</h1>
<div class="title-block__subtitle">Lab Note ${padId(entry.id)}</div>
</div>
<div class="meta-grid">
<div class="meta-grid__cell">
<span class="meta-grid__label">Day</span>
<span class="meta-grid__value">${entry.day}</span>
</div>
<div class="meta-grid__cell">
<span class="meta-grid__label">Specimen</span>
<span class="meta-grid__value">${entry.specimen}</span>
</div>
<div class="meta-grid__cell">
<span class="meta-grid__label">Protocol</span>
<span class="meta-grid__value">${entry.protocol}</span>
</div>
<div class="meta-grid__cell">
<span class="meta-grid__label">Status</span>
<span class="meta-grid__value">${entry.status}</span>
</div>
<div class="meta-grid__cell">
<span class="meta-grid__label">Budget Remaining</span>
<span class="meta-grid__value">${entry.budgetEnd}</span>
</div>
<div class="meta-grid__cell">
<span class="meta-grid__label">Researcher</span>
<span class="meta-grid__value meta-grid__value--redacted">REDACTED</span>
</div>
</div>
<div class="entry-content">
${sectionsHTML}
</div>
${entry.addendum ? `
<div class="addendum">
<span class="addendum__label">Addendum</span>
${entry.addendum}
</div>
` : ''}
<div class="signature-block">
<div class="signature-block__field">
<span class="signature-block__label">Researcher</span>
<div class="signature-block__line">${entry.signatures?.researcher || ''}</div>
</div>
<div class="signature-block__field">
<span class="signature-block__label">Reviewed By</span>
<div class="signature-block__line">${entry.signatures?.reviewer || ''}</div>
</div>
</div>
<nav class="doc-nav">
<div class="doc-nav__controls">
<button class="doc-nav__btn ${!hasPrev ? 'doc-nav__btn--disabled' : ''}"
${!hasPrev ? 'disabled' : ''} data-action="prev">◀</button>
<button class="doc-nav__btn" data-action="index">□</button>
<button class="doc-nav__btn ${!hasNext ? 'doc-nav__btn--disabled' : ''}"
${!hasNext ? 'disabled' : ''} data-action="next">▶</button>
</div>
</nav>
<div class="doc-footer">
<span>(c) <a href="https://github.com/oatsandsugar" target="_blank" rel="noopener">@oatsandsugar</a> ${new Date().getFullYear()} — <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">CC BY-NC-SA 4.0</a></span>
<span><a href="https://far-horizons-co-op.itch.io/outliers" target="_blank" rel="noopener">Outliers</a> by Far Horizons Co-op</span>
</div>
`;
// Bind nav
$$('[data-action]').forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
const action = btn.dataset.action;
if (action === 'prev' && hasPrev) renderEntry(index - 1);
if (action === 'next' && hasNext) renderEntry(index + 1);
if (action === 'index') renderIndex();
});
});
// Apply digital rot AFTER DOM is built
if (entry.rot > 0) {
ROT.apply(entry.id, entry.rot, pageFrame, { animate: animationsEnabled });
}
window.scrollTo(0, 0);
updateURL(entry.id);
}
function updateURL(entryId) {
const url = entryId ? `#entry-${entryId}` : '#';
history.replaceState(null, '', entryId ? url : window.location.pathname);
}
function handleHash() {
const hash = window.location.hash;
if (hash.startsWith('#entry-')) {
const id = hash.replace('#entry-', '');
const idx = entries.findIndex(e => e.id === id);
if (idx !== -1) {
renderEntry(idx);
return true;
}
}
return false;
}
document.addEventListener('keydown', (e) => {
if (isIndex) return;
if (e.key === 'ArrowLeft' && currentIndex > 0) {
renderEntry(currentIndex - 1);
} else if (e.key === 'ArrowRight' && currentIndex < entries.length - 1) {
renderEntry(currentIndex + 1);
} else if (e.key === 'Escape') {
renderIndex();
}
});
function renderSplash(onContinue) {
const content = $('#content');
content.innerHTML = `
<div class="splash">
<div class="doc-header">
<div class="doc-header__org">
Research Division<br>
Documentation Archive
</div>
<div class="doc-header__classification">Internal</div>
</div>
<div class="splash__body">
<h1 class="title-block__title">Lab Notes</h1>
<div class="title-block__subtitle" style="margin-bottom: 32px;">Horizon Labs — Research Documentation</div>
<hr class="ruler--heavy">
<div class="section" style="margin-top: 32px;">
<div class="section__body">
<p>This is <a href="https://github.com/oatsandsugar" style="color:var(--black);font-weight:600;">@oatsandsugar</a>'s playthrough of <a href="https://far-horizons-co-op.itch.io/outliers" style="color:var(--black);font-weight:600;">Outliers</a> by Far Horizons Co-op.</p>
<p><strong>Spoiler warning.</strong> These notes document an ongoing game. If you intend to play Outliers yourself, reading further may affect your experience.</p>
<p>This project contains animations and flashing effects that may be uncomfortable for some viewers.</p>
</div>
</div>
<div class="splash__controls">
<label class="splash__toggle">
<input type="checkbox" id="splash-animations" ${animationsEnabled ? 'checked' : ''}>
<span class="splash__toggle-label">Enable animations & effects</span>
</label>
</div>
<button class="doc-nav__btn splash__enter" id="splash-enter">
Enter Archive
</button>
</div>
<div class="splash__license">
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">CC BY-NC-SA 4.0</a>
</div>
<div class="doc-footer">
<span>Lab Notes Archive</span>
<span>${new Date().getFullYear()}</span>
</div>
</div>
`;
$('#splash-animations').addEventListener('change', (e) => {
animationsEnabled = e.target.checked;
localStorage.setItem('lab-notes-animations', animationsEnabled ? 'on' : 'off');
document.documentElement.classList.toggle('no-animations', !animationsEnabled);
});
$('#splash-enter').addEventListener('click', () => {
localStorage.setItem('lab-notes-seen', '1');
onContinue();
});
}
function proceed() {
if (!handleHash()) {
if (entries.length === 1) {
renderEntry(0);
} else {
renderIndex();
}
}
}
async function init() {
// Apply animation preference immediately
if (!animationsEnabled) {
document.documentElement.classList.add('no-animations');
}
await loadManifest();
const seen = localStorage.getItem('lab-notes-seen');
if (!seen) {
renderSplash(proceed);
} else {
proceed();
}
}
window.addEventListener('hashchange', () => {
if (!handleHash()) renderIndex();
});
return { init };
})();
document.addEventListener('DOMContentLoaded', LAB.init);