-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
1692 lines (1452 loc) · 66.8 KB
/
Copy pathapp.js
File metadata and controls
1692 lines (1452 loc) · 66.8 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Javascript Operations - The Chronicles of Celibacy */
document.addEventListener('DOMContentLoaded', () => {
// State Variables
let investigatorName = '';
let isAuthorized = false;
let currentSectionId = 'cover';
let foodCounterInterval = null;
let foodCount = 52410; // Base number
let hasStamped = false;
let isInvestigatorMode = false;
let currentCaseId = '';
// Dynamic dossier settings
let subjectName = 'Japheth "JayOnChain" Adamu';
let subjectShort = 'JayOnChain';
let primarySchool = 'Hekan Women School';
let higherSchool = 'Kaduna Polytechnic';
// Synthetic Audio Synthesizer Class using Web Audio API
class SyntheticAudioPack {
constructor() {
this.ctx = null;
this.muted = false;
}
init() {
if (this.ctx) return;
const AudioCtx = window.AudioContext || window.webkitAudioContext;
this.ctx = new AudioCtx();
}
toggleMute() {
this.muted = !this.muted;
const btn = document.getElementById('btn-toggle-audio');
if (btn) {
if (this.muted) {
btn.classList.add('muted');
} else {
btn.classList.remove('muted');
}
}
return this.muted;
}
playClick() {
if (this.muted) return;
this.init();
if (this.ctx.state === 'suspended') this.ctx.resume();
// Synthesize click noise
const bufferSize = this.ctx.sampleRate * 0.01;
const buffer = this.ctx.createBuffer(1, bufferSize, this.ctx.sampleRate);
const data = buffer.getChannelData(0);
for (let i = 0; i < bufferSize; i++) {
data[i] = Math.random() * 2 - 1;
}
const noiseNode = this.ctx.createBufferSource();
noiseNode.buffer = buffer;
const filter = this.ctx.createBiquadFilter();
filter.type = 'highpass';
filter.frequency.value = 1200;
const gain = this.ctx.createGain();
gain.gain.setValueAtTime(0.08, this.ctx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.001, this.ctx.currentTime + 0.006);
noiseNode.connect(filter);
filter.connect(gain);
gain.connect(this.ctx.destination);
noiseNode.start();
}
playSlide() {
if (this.muted) return;
this.init();
if (this.ctx.state === 'suspended') this.ctx.resume();
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
osc.type = 'sine';
osc.frequency.setValueAtTime(250, this.ctx.currentTime);
osc.frequency.exponentialRampToValueAtTime(450, this.ctx.currentTime + 0.15);
gain.gain.setValueAtTime(0.001, this.ctx.currentTime);
gain.gain.linearRampToValueAtTime(0.06, this.ctx.currentTime + 0.04);
gain.gain.exponentialRampToValueAtTime(0.001, this.ctx.currentTime + 0.15);
osc.connect(gain);
gain.connect(this.ctx.destination);
osc.start();
osc.stop(this.ctx.currentTime + 0.15);
}
playBeep(freq = 600, duration = 0.08) {
if (this.muted) return;
this.init();
if (this.ctx.state === 'suspended') this.ctx.resume();
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
osc.type = 'sine';
osc.frequency.setValueAtTime(freq, this.ctx.currentTime);
gain.gain.setValueAtTime(0.04, this.ctx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.001, this.ctx.currentTime + duration);
osc.connect(gain);
gain.connect(this.ctx.destination);
osc.start();
osc.stop(this.ctx.currentTime + duration);
}
playStamp() {
if (this.muted) return;
this.init();
if (this.ctx.state === 'suspended') this.ctx.resume();
// Low frequency thud
const osc = this.ctx.createOscillator();
const oscGain = this.ctx.createGain();
osc.type = 'triangle';
osc.frequency.setValueAtTime(120, this.ctx.currentTime);
osc.frequency.exponentialRampToValueAtTime(30, this.ctx.currentTime + 0.25);
oscGain.gain.setValueAtTime(0.35, this.ctx.currentTime);
oscGain.gain.exponentialRampToValueAtTime(0.001, this.ctx.currentTime + 0.25);
osc.connect(oscGain);
oscGain.connect(this.ctx.destination);
osc.start();
osc.stop(this.ctx.currentTime + 0.25);
// Mid frequency paper clap noise
const bufferSize = this.ctx.sampleRate * 0.12;
const buffer = this.ctx.createBuffer(1, bufferSize, this.ctx.sampleRate);
const data = buffer.getChannelData(0);
for (let i = 0; i < bufferSize; i++) {
data[i] = Math.random() * 2 - 1;
}
const noise = this.ctx.createBufferSource();
noise.buffer = buffer;
const filter = this.ctx.createBiquadFilter();
filter.type = 'bandpass';
filter.frequency.value = 500;
const noiseGain = this.ctx.createGain();
noiseGain.gain.setValueAtTime(0.15, this.ctx.currentTime);
noiseGain.gain.exponentialRampToValueAtTime(0.001, this.ctx.currentTime + 0.1);
noise.connect(filter);
filter.connect(noiseGain);
noiseGain.connect(this.ctx.destination);
noise.start();
}
playFanfare() {
if (this.muted) return;
this.init();
if (this.ctx.state === 'suspended') this.ctx.resume();
// Ascending arpeggio: a little triumphant "case closed" flourish
const notes = [523.25, 659.25, 783.99, 1046.5]; // C5 E5 G5 C6
const step = 0.11;
notes.forEach((freq, i) => {
const t = this.ctx.currentTime + i * step;
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
osc.type = 'triangle';
osc.frequency.setValueAtTime(freq, t);
gain.gain.setValueAtTime(0.001, t);
gain.gain.linearRampToValueAtTime(0.12, t + 0.02);
gain.gain.exponentialRampToValueAtTime(0.001, t + 0.28);
osc.connect(gain);
gain.connect(this.ctx.destination);
osc.start(t);
osc.stop(t + 0.3);
});
}
}
const audioPack = new SyntheticAudioPack();
// Elements
const investigatorInput = document.getElementById('investigator-input');
const btnAuthorize = document.getElementById('btn-authorize');
const authMeta = document.getElementById('auth-meta');
const caseIdValue = document.getElementById('case-id-value');
const btnStart = document.getElementById('btn-start');
const navInvestigatorName = document.getElementById('nav-investigator-name');
const navItems = document.querySelectorAll('.nav-item');
const sections = document.querySelectorAll('.dossier-section');
const prevButtons = document.querySelectorAll('.btn-prev');
const nextButtons = document.querySelectorAll('.btn-next');
// Core Navigation Setup
const navigationMap = {
'cover': 'sec-cover',
'chapter1': 'sec-chapter1',
'chapter2': 'sec-chapter2',
'chapter3': 'sec-chapter3',
'chapter4': 'sec-chapter4',
'verdict': 'sec-verdict'
};
// 1. PARTICLES CANVAS SYSTEM
setupParticles();
// 2. GENERATE CASE ID
generateCaseID();
// Check for Investigator Mode parameters
checkURLParams();
// Setup dynamic accordions
setupReportCardAccordions();
// Setup Chapter IV Polygraph Analyzer
setupPolygraphAnalyzer();
// Setup Chapter V Appeals modal
setupAppealsProcess();
// Setup Chapter V Print certificate
setupPrintAction();
setupDownloadAction();
// Setup Most Wanted leaderboard
setupMostWanted();
// Toggle mute switch
const btnToggleAudio = document.getElementById('btn-toggle-audio');
if (btnToggleAudio) {
btnToggleAudio.addEventListener('click', () => {
audioPack.toggleMute();
});
}
// Capture global clicks to play synthesized typewriter clicks
document.body.addEventListener('click', (e) => {
const target = e.target;
if (target.closest('.btn, .sim-trigger, .sim-scenario-btn, .nav-item, .accordion-header, .btn-audio-icon')) {
audioPack.playClick();
}
});
// 3. AUTHORIZATION ACTION
btnAuthorize.addEventListener('click', authorizeInvestigator);
investigatorInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') authorizeInvestigator();
});
btnStart.addEventListener('click', () => {
switchSection('chapter1');
});
// Copy Shareable Link Action
const btnCopy = document.getElementById('btn-copy-link');
if (btnCopy) {
btnCopy.addEventListener('click', () => {
const shareInput = document.getElementById('share-link-input');
if (shareInput) {
shareInput.select();
shareInput.setSelectionRange(0, 99999);
navigator.clipboard.writeText(shareInput.value).then(() => {
const toast = document.getElementById('copy-toast-msg');
if (toast) {
toast.classList.remove('hidden');
setTimeout(() => toast.classList.add('hidden'), 3000);
}
});
}
});
}
// Social Share Buttons
function getShareUrl() {
const shareInput = document.getElementById('share-link-input');
return (shareInput && shareInput.value) ? shareInput.value : window.location.href;
}
function getShareText() {
const who = subjectShort || subjectName || 'this person';
const score = computeSinglenessScore(subjectName);
const tier = getVerdictTier(score);
return `🕵️ Global Bureau of Celibacy don rate ${who}: ${score}% ${tier.label}. Abeg help confirm — dem dey single or dem dey lie? Check the evidence:`;
}
const btnShareWhatsapp = document.getElementById('btn-share-whatsapp');
if (btnShareWhatsapp) {
btnShareWhatsapp.addEventListener('click', () => {
const url = `https://wa.me/?text=${encodeURIComponent(getShareText() + ' ' + getShareUrl())}`;
window.open(url, '_blank', 'noopener,noreferrer');
});
}
const btnShareTwitter = document.getElementById('btn-share-twitter');
if (btnShareTwitter) {
btnShareTwitter.addEventListener('click', () => {
const url = `https://twitter.com/intent/tweet?text=${encodeURIComponent(getShareText())}&url=${encodeURIComponent(getShareUrl())}`;
window.open(url, '_blank', 'noopener,noreferrer');
});
}
const btnShareFacebook = document.getElementById('btn-share-facebook');
if (btnShareFacebook) {
btnShareFacebook.addEventListener('click', () => {
const url = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(getShareUrl())}"e=${encodeURIComponent(getShareText())}`;
window.open(url, '_blank', 'noopener,noreferrer');
});
}
// Native mobile share sheet (Web Share API) — only shown when supported
const btnShareNative = document.getElementById('btn-share-native');
if (btnShareNative && navigator.share) {
btnShareNative.classList.remove('hidden');
btnShareNative.addEventListener('click', async () => {
try {
await navigator.share({
title: 'The Single Files',
text: getShareText(),
url: getShareUrl()
});
} catch (err) {
// user cancelled or share failed — no action needed
}
});
}
// 4. NAVIGATION CONTROLS
navItems.forEach(item => {
item.addEventListener('click', () => {
if (item.classList.contains('disabled')) return;
const target = item.getAttribute('data-target');
switchSection(target);
});
});
prevButtons.forEach(btn => {
btn.addEventListener('click', () => {
const target = btn.getAttribute('data-target');
switchSection(target);
});
});
nextButtons.forEach(btn => {
btn.addEventListener('click', () => {
const target = btn.getAttribute('data-target');
switchSection(target);
});
});
// 5. CHAPTER II: OBLIVIOUS ENGINE SIMULATOR
setupObliviousEngine();
// 6. CHAPTER IV: FLIRT SIMULATOR
setupFlirtSimulator();
// 7. VERDICT SIGNATURE & STAMP
setupAffidavitStamp();
// --- FUNCTION DEFINITIONS ---
// Particles Setup
function setupParticles() {
const canvas = document.getElementById('particles-canvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let particles = [];
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resize);
resize();
// Particle Class
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.size = Math.random() * 1.5 + 0.5;
this.speedX = Math.random() * 0.2 - 0.1;
this.speedY = Math.random() * -0.3 - 0.1; // Float upwards
this.color = Math.random() > 0.5 ? 'rgba(212, 175, 55, 0.15)' : 'rgba(168, 85, 247, 0.15)';
}
update() {
this.x += this.speedX;
this.y += this.speedY;
if (this.y < 0) {
this.y = canvas.height;
this.x = Math.random() * canvas.width;
}
if (this.x < 0 || this.x > canvas.width) {
this.speedX *= -1;
}
}
draw() {
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
// Initialize particles
for (let i = 0; i < 60; i++) {
particles.push(new Particle());
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(p => {
p.update();
p.draw();
});
requestAnimationFrame(animate);
}
animate();
}
// Generate Case ID
function generateCaseID() {
const hex = '0123456789ABCDEF';
let segment = '';
for (let i = 0; i < 5; i++) {
segment += hex.charAt(Math.floor(Math.random() * hex.length));
}
const year = new Date().getFullYear();
currentCaseId = `GBC-${year}-${segment}`;
caseIdValue.textContent = currentCaseId;
// Mirror onto the certificate + set the issue date
const certNumEl = document.getElementById('cert-number');
if (certNumEl) certNumEl.textContent = currentCaseId;
const certDateEl = document.getElementById('cert-date');
if (certDateEl) {
certDateEl.textContent = new Date().toLocaleDateString('en-GB', {
day: '2-digit', month: 'short', year: 'numeric'
});
}
}
// Authorize Investigator
function authorizeInvestigator() {
const inputVal = investigatorInput.value.trim();
if (!inputVal) {
investigatorInput.classList.add('error-shake');
setTimeout(() => investigatorInput.classList.remove('error-shake'), 500);
return;
}
investigatorName = inputVal;
isAuthorized = true;
if (!isInvestigatorMode) {
subjectName = document.getElementById('subject-input').value.trim();
primarySchool = document.getElementById('primary-school-input').value.trim();
higherSchool = document.getElementById('higher-school-input').value.trim();
if (!subjectName) {
subjectName = 'Japheth "JayOnChain" Adamu';
}
// Extract short subject name
const quoteMatch = subjectName.match(/["']([^"']+)["']/);
if (quoteMatch) {
subjectShort = quoteMatch[1];
} else {
subjectShort = subjectName.split(' ')[0];
}
// Generate customized link for Lead Investigator
generateShareLink();
}
// Update Text across elements dynamically
navInvestigatorName.textContent = investigatorName.toUpperCase();
document.querySelectorAll('.investigator-placeholder').forEach(el => {
el.textContent = investigatorName;
});
updatePlaceholders();
// Toggle UI states
document.getElementById('auth-form-card').classList.add('hidden');
authMeta.classList.remove('hidden');
// Enable Navigation Items
navItems.forEach(item => {
item.classList.remove('disabled');
});
// Enable Stamp, Appeal, and Print Button states
document.getElementById('btn-stamp-action').removeAttribute('disabled');
document.getElementById('btn-appeal-action').removeAttribute('disabled');
document.getElementById('btn-print-action').removeAttribute('disabled');
document.getElementById('btn-download-action').removeAttribute('disabled');
document.getElementById('investigator-signature-display').textContent = investigatorName;
}
// Check URL parameters for Investigator Mode
function checkURLParams() {
const urlParams = new URLSearchParams(window.location.search);
const paramC = urlParams.get('c');
let paramSubject = urlParams.get('subject');
let paramPrimary = urlParams.get('primary');
let paramHigher = urlParams.get('higher');
// Parse Base64 configuration if present
if (paramC) {
try {
const decodedJson = decodeURIComponent(escape(atob(paramC)));
const config = JSON.parse(decodedJson);
paramSubject = config.s;
paramPrimary = config.p;
paramHigher = config.h;
} catch (e) {
console.error("Failed to parse base64 config", e);
}
}
if (window.location.search) {
isInvestigatorMode = true;
subjectName = paramSubject || 'Japheth "JayOnChain" Adamu';
primarySchool = paramPrimary !== null && paramPrimary !== undefined ? paramPrimary : '';
higherSchool = paramHigher !== null && paramHigher !== undefined ? paramHigher : '';
// Show the main subtitle element in Investigator Mode
const subtitleEl = document.getElementById('main-subtitle-element');
if (subtitleEl) subtitleEl.classList.remove('hidden');
// Extract short subject name
const quoteMatch = subjectName.match(/["']([^"']+)["']/);
if (quoteMatch) {
subjectShort = quoteMatch[1];
} else {
subjectShort = subjectName.split(' ')[0];
}
// Hide compiler specific inputs from investigator form
document.getElementById('group-subject').classList.add('hidden');
document.getElementById('group-primary').classList.add('hidden');
document.getElementById('group-higher').classList.add('hidden');
// Set grid template for single column input field (investigator name)
document.querySelector('.config-grid').style.gridTemplateColumns = '1fr';
// Adjust headers for Investigator Mode
document.getElementById('auth-card-title').textContent = 'Investigator, Sign In';
document.getElementById('auth-card-desc').innerHTML = `Dem give you the file of <strong>${subjectName}</strong> make you check am. Put your name make we start.`;
btnAuthorize.textContent = 'OPEN THE FILE, START AUDIT';
// Populate all labels immediately
updatePlaceholders();
}
}
// Update variables dynamically in document placeholders
function updatePlaceholders() {
document.querySelectorAll('.subject-placeholder').forEach(el => {
el.textContent = subjectName || '[No Name]';
});
document.querySelectorAll('.subject-short-placeholder').forEach(el => {
el.textContent = subjectShort || 'The Person';
});
document.querySelectorAll('.primary-school-placeholder').forEach(el => {
el.textContent = primarySchool || '[N/A]';
});
document.querySelectorAll('.higher-school-placeholder').forEach(el => {
el.textContent = higherSchool || '[N/A]';
});
// Seed the score meter / tier / conclusion for the current subject (no animation yet)
renderScoreMeter(false);
applyDynamicVisibility();
}
// Apply visibility overrides based on empty institutions
function applyDynamicVisibility() {
const primaryReport = document.getElementById('primary-report-card');
const primaryHeaders = document.querySelectorAll('#sec-chapter1 .academic-record-header');
if (!primarySchool) {
if (primaryReport) primaryReport.classList.add('hidden');
primaryHeaders.forEach(el => el.classList.add('hidden'));
} else {
if (primaryReport) primaryReport.classList.remove('hidden');
primaryHeaders.forEach(el => el.classList.remove('hidden'));
}
const higherReport = document.getElementById('higher-report-card');
const higherHeaders = document.querySelectorAll('#sec-chapter3 .academic-record-header');
if (!higherSchool) {
if (higherReport) higherReport.classList.add('hidden');
higherHeaders.forEach(el => el.classList.add('hidden'));
} else {
if (higherReport) higherReport.classList.remove('hidden');
higherHeaders.forEach(el => el.classList.remove('hidden'));
}
updateAffidavitText();
}
// Update Affidavit text dynamically based on which schools are present
function updateAffidavitText() {
const textEl = document.getElementById('affidavit-declaration-text');
if (!textEl) return;
textEl.innerHTML = `Having been thoroughly investigated across all official records right from <strong class="gold-text">childbirth till now</strong>, <span class="subject-placeholder">${subjectName}</span> is hereby confirmed by the Global Bureau of Celibacy to be of <strong class="gold-text">verified single status.</strong>`;
}
// Global JSONP callback for is.gd link shortener
window.handleShortenedUrl = function(response) {
if (response.shorturl) {
const shareInput = document.getElementById('share-link-input');
if (shareInput) {
shareInput.value = response.shorturl;
}
}
};
// Generate Shareable Link with Search Query Params
function generateShareLink() {
const baseUrl = window.location.origin + window.location.pathname;
const queryParams = new URLSearchParams();
// Compile config into a compact object
const config = {
s: subjectName,
p: primarySchool,
h: higherSchool
};
try {
const jsonStr = JSON.stringify(config);
const encoded = btoa(unescape(encodeURIComponent(jsonStr)));
queryParams.set('c', encoded);
} catch (e) {
console.error("Failed to encode link config", e);
if (subjectName) queryParams.set('subject', subjectName);
if (primarySchool) queryParams.set('primary', primarySchool);
if (higherSchool) queryParams.set('higher', higherSchool);
}
const connector = baseUrl.endsWith('/') ? '' : '/';
const shareUrl = `${baseUrl}${connector}?${queryParams.toString()}`;
const shareInput = document.getElementById('share-link-input');
if (shareInput) {
// Set long URL as fallback instantly
shareInput.value = shareUrl;
}
// Show compiler share link panel
const sharePanel = document.getElementById('compiler-share-panel');
if (sharePanel) {
sharePanel.classList.remove('hidden');
}
// Automatically shorten the link client-side using is.gd JSONP API
try {
const existingScript = document.getElementById('isgd-shortener-script');
if (existingScript) existingScript.remove();
const script = document.createElement('script');
script.id = 'isgd-shortener-script';
script.src = `https://is.gd/create.php?format=json&url=${encodeURIComponent(shareUrl)}&callback=handleShortenedUrl`;
document.body.appendChild(script);
} catch (err) {
console.error("Link shortener error:", err);
}
}
// Switch Dossier Section
function switchSection(targetId) {
if (!isAuthorized && targetId !== 'cover') return;
currentSectionId = targetId;
// Play page turn sound sweep
audioPack.playSlide();
// Update Navigation selection state
navItems.forEach(item => {
if (item.getAttribute('data-target') === targetId) {
item.classList.add('active');
} else {
item.classList.remove('active');
}
});
// Transition Sections
sections.forEach(sec => {
sec.classList.remove('active');
});
const activeSection = document.getElementById(navigationMap[targetId]);
if (activeSection) {
activeSection.classList.add('active');
// Scroll section back to top
const scrollContainer = activeSection.querySelector('.section-scroll');
if (scrollContainer) scrollContainer.scrollTop = 0;
}
// Special Section Activation Events
if (targetId === 'chapter3') {
triggerStatsCountUp();
} else {
stopFoodCounter();
}
if (targetId === 'verdict') {
renderScoreMeter(true);
}
}
// Chapter II Engine Simulator Logs
function setupObliviousEngine() {
const triggers = document.querySelectorAll('.sim-trigger');
const outputTerminal = document.getElementById('engine-terminal-output');
const logsData = {
pencil: [
{ type: 'action', text: '[EVENT] Girl for class wan borrow pencil.' },
{ type: 'system', text: '[PROCESSING] E dey calculate how near she dey...' },
{ type: 'system', text: '[DEFENSE ON] E stretch hand far far give am the pencil.' },
{ type: 'success', text: '[RESULT] Pencil don change hand. Eye no meet. Status: Safe.' }
],
crush: [
{ type: 'action', text: '[EVENT] Person ask am: "Who you like?"' },
{ type: 'system', text: '[DANGER] Serious matter. Im mind fit open.' },
{ type: 'system', text: '[PLAN] E don ready one funny answer.' },
{ type: 'success', text: '[RESULT] E talk "Optimus Prime". Matter close. Status: Safe.' }
],
partner: [
{ type: 'action', text: '[EVENT] Dem sit am near one girl.' },
{ type: 'system', text: '[DEFENSE] E dey build boundary for mind.' },
{ type: 'system', text: '[WALL] E arrange 3 fat chemistry textbook for middle.' },
{ type: 'success', text: '[RESULT] Space secure. Na only Calculus dem talk. Status: Safe.' }
],
valentines: [
{ type: 'action', text: '[EVENT] Val Day card exchange don start.' },
{ type: 'system', text: '[PATROL] E don begin plan how to run.' },
{ type: 'system', text: '[ACTION] E close curtain, play Minecraft for 14 hours.' },
{ type: 'success', text: '[RESULT] E lock imself inside. Chop one full pack biscuit. Status: Safe.' }
]
};
triggers.forEach(trigger => {
trigger.addEventListener('click', () => {
const eventKey = trigger.getAttribute('data-event');
const logLines = logsData[eventKey];
// Clear terminal content
outputTerminal.innerHTML = '';
// Append lines sequentially simulating typing
logLines.forEach((line, index) => {
setTimeout(() => {
const lineEl = document.createElement('div');
lineEl.className = `terminal-line ${line.type}`;
lineEl.textContent = line.text;
outputTerminal.appendChild(lineEl);
outputTerminal.scrollTop = outputTerminal.scrollHeight;
}, index * 400);
});
});
});
}
// Chapter III Stats Count Up
function triggerStatsCountUp() {
// Zero counters stay zero, but let's run animation effect
animateValue('stat-dates', 0, 0, 1000);
animateValue('stat-walks', 0, 0, 1000);
animateValue('stat-situationships', 0, 0, 1000);
// Food count counter
animateValue('stat-food', 0, foodCount, 1500, () => {
// Once base count-up is finished, tick up periodically
startFoodCounter();
});
}
function animateValue(id, start, end, duration, callback) {
const obj = document.getElementById(id);
if (!obj) return;
if (start === end) {
obj.textContent = end.toLocaleString();
if (callback) callback();
return;
}
const range = end - start;
let current = start;
const increment = end > start ? Math.ceil(range / (duration / 16)) : -1;
const stepTime = 16; // approx 60fps
const timer = setInterval(() => {
current += increment;
if ((increment > 0 && current >= end) || (increment < 0 && current <= end)) {
current = end;
clearInterval(timer);
if (callback) callback();
}
obj.textContent = current.toLocaleString();
}, stepTime);
}
function startFoodCounter() {
stopFoodCounter();
foodCounterInterval = setInterval(() => {
foodCount += Math.floor(Math.random() * 3) + 1;
const foodObj = document.getElementById('stat-food');
if (foodObj) {
foodObj.textContent = foodCount.toLocaleString();
}
}, 1500);
}
function stopFoodCounter() {
if (foodCounterInterval) {
clearInterval(foodCounterInterval);
foodCounterInterval = null;
}
}
// Chapter IV Flirt Simulator Logic
function setupFlirtSimulator() {
const scenarios = {
1: {
prompt: "One classmate talk: \"Cold dey catch me today, I for get jacket.\"",
options: [
{
text: "Give am jacket quiet quiet, stand for cold.",
reply: "*e give am the jacket, turn back, stand for the cold breeze*",
report: "BIG FAIL. E give the jacket but e no talk one word. E come catch small cold, spend weekend dey drink hot lemon water alone. No love."
},
{
text: "Start to explain how body dey warm.",
reply: "Na your body dey shake to make heat by itself. You for wear thick sweater na.",
report: "GRAMMAR PROBLEM. E waste 12 minutes dey teach science of heat. The gist die. E return back to single mode."
},
{
text: "Agree and comot sharp sharp.",
reply: "Same o. My hand don freeze. I dey go house go sleep under three blanket. See you tomorrow.",
report: "SHARP EXIT. E comot the area sharp sharp. No gist continue. Still single."
}
]
},
2: {
prompt: "One colleague message am: \"Wetin you dey do this weekend? I free.\"",
options: [
{
text: "Talk say na keyboard e wan repair.",
reply: "I wan open my keyboard, oil the switch, and clean up CSS for my repo.",
report: "BACK TO DEFAULT. Keyboard clean. Code clean. People level: 0.0%. E spend the weekend alone."
},
{
text: "Propose to play chess.",
reply: "Nothing. We fit play 10-minute chess for chess.com. I go send lobby link, I dey use white.",
report: "MATTER STALL. The person no sabi chess. Game no start. E spend weekend dey study Sicilian Defense."
},
{
text: "Acknowledge and close the chat.",
reply: "Nice! Enjoy your free time. Make sure say you rest well.",
report: "CHAT DONE. E go offline go watch video essay. Signal lost finish. Love index: 0.0."
}
]
},
3: {
prompt: "Classmate talk: \"You fine today o, you do something to your hair?\"",
options: [
{
text: "Suspect am, deny hygiene.",
reply: "No o, na wash I forget to wash am this morning. Dirt dey show for am?",
report: "WRONG TURN. E take the praise as say dem dey check whether e wash head. The gist die sharp sharp."
},
{
text: "Give am mathematics of hair.",
reply: "This hair be the same since past 74 days. E hard make you notice any change.",
report: "TOO MUCH ANALYSIS. The person stop to chat. E log out go continue im database work."
},
{
text: "Blame the wind.",
reply: "Na the wind wey blow me for road. Na breeze arrange the hair like this.",
report: "RESULT: NEUTRAL. E give the wind full credit for im look. Zero toasting energy show."
}
]
}
};
const scenarioButtons = document.querySelectorAll('.sim-scenario-btn');
const simPrompt = document.getElementById('sim-prompt');
const simFeedback = document.getElementById('sim-feedback');
const simOutcome = document.getElementById('sim-outcome');
const simOutcomeText = document.getElementById('sim-outcome-text');
const optionsWrapper = document.getElementById('sim-options-wrapper');
const optionsGrid = document.getElementById('sim-options-grid');
scenarioButtons.forEach(btn => {
btn.addEventListener('click', () => {
// Clear active states on buttons
scenarioButtons.forEach(b => b.classList.remove('btn-accent'));
btn.classList.add('btn-accent');
const scNum = btn.getAttribute('data-scenario');
const data = scenarios[scNum];
// Load prompt
simPrompt.textContent = `Test Gist: "${data.prompt}"`;
// Clear feed & outcome
simFeedback.innerHTML = '<div class="placeholder-text">Pick wetin e go do...</div>';
simOutcome.classList.add('hidden');
// Render options
optionsGrid.innerHTML = '';
data.options.forEach((opt, idx) => {
const optBtn = document.createElement('button');
optBtn.className = 'btn btn-secondary';
optBtn.textContent = opt.text;
optBtn.addEventListener('click', () => {
executeSimulationStep(data.prompt, opt.reply, opt.report);
});
optionsGrid.appendChild(optBtn);
});
optionsWrapper.classList.remove('hidden');
});
});
function executeSimulationStep(promptText, replyText, reportText) {
// Render dialog bubbles
simFeedback.innerHTML = `
<div class="feedback-dialog">
<div class="bubble crush-prompt"><strong>The Person:</strong> "${promptText}"</div>
<div class="bubble subject-reply"><strong>Am (${subjectShort}):</strong> "${replyText}"</div>
</div>
`;
// Render lab outcome report
simOutcomeText.textContent = reportText;
simOutcome.classList.remove('hidden');
}
}
// ===== Singleness Score, Verdict Tiers & Most Wanted Leaderboard =====
// Stable string hash so the same name always yields the same numbers
function hashString(str) {
let h = 2166136261;
for (let i = 0; i < str.length; i++) {
h ^= str.charCodeAt(i);
h = Math.imul(h, 16777619);
}
return Math.abs(h >>> 0);
}
// Deterministic "Certified Single" score in the 87–99 range, seeded by name
function computeSinglenessScore(name) {
const seed = hashString((name || 'unknown').toLowerCase().trim());
return 87 + (seed % 13); // 87..99
}
// Map a score to a bragging-rights tier
function getVerdictTier(score) {
if (score >= 97) return { label: 'UNTOUCHABLE', level: 'Legendary' };
if (score >= 93) return { label: 'CHRONICALLY SINGLE', level: 'Elite' };
return { label: 'CERTIFIED SINGLE', level: 'Confirmed' };
}
// Rotating closing lines, stable per subject
const CONCLUSION_LINES = [
'This certified subject don dey single from day one till now. No break, no ex, no hidden bae anywhere.',
'The Bureau confirm say this one never hold hand, never send love text. The record clean pass hospital floor.',
'This subject dey collect "we fit be friends" since primary school. Solid single streak, no dulling.',
'Relationship history: 404 Not Found. This subject get PhD for dodging toaster since primary school.'
];
function getConclusionLine(name) {
const seed = hashString((name || 'unknown').toLowerCase().trim());
return CONCLUSION_LINES[seed % CONCLUSION_LINES.length];
}
// Render the score meter + tier badge into the affidavit and animate it
function renderScoreMeter(animate) {
const score = computeSinglenessScore(subjectName);
const tier = getVerdictTier(score);
const pctEl = document.getElementById('score-percent');
const barEl = document.getElementById('score-bar-fill');
const tierEl = document.getElementById('verdict-tier-badge');
const concEl = document.querySelector('.declaration-conclusion');
if (!pctEl || !barEl || !tierEl) return;