forked from jokeri2222/KaHack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKaHack!.user.js
More file actions
1124 lines (1020 loc) · 46.5 KB
/
KaHack!.user.js
File metadata and controls
1124 lines (1020 loc) · 46.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
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
// ==UserScript==
// @name Kahoot Exploit (Mobile Friendly)
// @version 2.1.0
// @description Show-only Kahoot helper! Highlights correct answers and shows next question preview. No auto-answering - manual clicking only.
// @namespace https://github.com/johnweeky
// @match https://kahoot.it/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=kahoot.it
// @grant none
// ==/UserScript==
(function() {
const stripeLink = 'https://buy.stripe.com/00w7sEdnd3843cV9MO77O00'; // IMPORTANT: Replace with your actual Stripe link
var Version = '2.1.0';
var questions = [];
var info = {
numQuestions: 0,
questionNum: -1,
lastAnsweredQuestion: -1,
};
var showAnswers = false;
var isTrialMode = false;
// Helper: Finds an element by attribute value.
function FindByAttributeValue(attribute, value, element_type) {
element_type = element_type || "*";
var All = document.getElementsByTagName(element_type);
for (var i = 0; i < All.length; i++) {
if (All[i].getAttribute(attribute) == value) {
return All[i];
}
}
}
// Sanitize input: Trim whitespace; if it starts with "https//" (missing colon) fix it.
// If a full URL is provided, return only its last non-empty segment.
function sanitizeInput(val) {
val = val.trim();
if (val.indexOf("https//") === 0) {
val = val.replace("https//", "https://");
}
if (/^https?:\/\//i.test(val)) {
var parts = val.replace(/^https?:\/\//i, '').split('/');
return parts.filter(Boolean).pop();
}
return val;
}
// Reset UI function – clears input, color, questions array, etc.
function resetUI() {
inputBox.value = "";
inputBox.style.backgroundColor = 'white';
dropdown.style.display = 'none';
dropdownCloseButton.style.display = 'none';
questions = [];
info.numQuestions = 0;
info.questionNum = -1;
info.lastAnsweredQuestion = -1;
questionsLabel.textContent = 'Question 0 / 0';
// Reset next question preview
const nextQuestionDisplay = document.getElementById('nextQuestionDisplay');
if (nextQuestionDisplay) {
const nextQuestionContainer = nextQuestionDisplay.closest('div');
if (nextQuestionContainer) {
nextQuestionContainer.style.display = 'block';
}
if (isTrialMode) {
nextQuestionDisplay.textContent = 'Disabled in test mode';
nextQuestionDisplay.style.color = '#ffc107'; // Yellow color for disabled state
} else {
nextQuestionDisplay.textContent = 'Loading...';
nextQuestionDisplay.style.color = ''; // Reset color
}
}
}
// --- UI Creation ---
const uiElement = document.createElement('div');
uiElement.className = 'floating-ui';
uiElement.style.position = 'absolute';
uiElement.style.top = '10px';
uiElement.style.left = '10px';
uiElement.style.right = '10px';
uiElement.style.width = 'auto';
uiElement.style.maxWidth = '90%'; // More responsive max-width
uiElement.style.margin = '10px auto'; // Center the UI on larger screens
uiElement.style.height = 'auto';
uiElement.style.backgroundColor = 'rgba(44, 51, 58, 0.95)';
uiElement.style.backdropFilter = 'blur(10px)';
uiElement.style.border = '1px solid rgba(255, 255, 255, 0.1)';
uiElement.style.borderRadius = '1vw';
uiElement.style.boxShadow = '0px 0px 10px 0px rgba(0, 0, 0, 0.5)';
uiElement.style.zIndex = '9999';
const handle = document.createElement('div');
handle.className = 'handle';
handle.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
handle.style.fontSize = 'min(1.5rem, 5vw)';
// Changed top handle text
handle.textContent = 'KaHack';
handle.style.cursor = 'pointer'; // Make it clickable
handle.style.color = 'white';
handle.style.width = '97.5%';
handle.style.height = '2.5vw';
handle.style.backgroundColor = 'rgba(255, 255, 255, 0.1)';
handle.style.borderRadius = '1vw 1vw 0 0';
handle.style.cursor = 'grab';
handle.style.textAlign = 'left';
handle.style.paddingLeft = '2.5%';
handle.style.lineHeight = '2vw';
uiElement.appendChild(handle);
const closeButton = document.createElement('div');
closeButton.className = 'close-button';
closeButton.textContent = '✕';
closeButton.style.position = 'absolute';
closeButton.style.top = '0';
closeButton.style.right = '0';
closeButton.style.width = '12.5%';
closeButton.style.height = '2.5vw';
closeButton.style.backgroundColor = 'red';
closeButton.style.color = 'white';
closeButton.style.borderRadius = '0 1vw 0 0';
closeButton.style.display = 'flex';
closeButton.style.justifyContent = 'center';
closeButton.style.alignItems = 'center';
closeButton.style.cursor = 'pointer';
handle.appendChild(closeButton);
const minimizeButton = document.createElement('div');
minimizeButton.className = 'minimize-button';
minimizeButton.textContent = '─';
minimizeButton.style.color = 'white';
minimizeButton.style.position = 'absolute';
minimizeButton.style.top = '0';
minimizeButton.style.right = '12.5%';
minimizeButton.style.width = '12.5%';
minimizeButton.style.height = '2.5vw';
minimizeButton.style.backgroundColor = 'gray';
minimizeButton.style.borderRadius = '0 0 0 0';
minimizeButton.style.display = 'flex';
minimizeButton.style.justifyContent = 'center';
minimizeButton.style.alignItems = 'center';
minimizeButton.style.cursor = 'pointer';
handle.appendChild(minimizeButton);
// QUIZ ID/NAME
const headerText = document.createElement('h2');
headerText.textContent = 'QUIZ ID/NAME';
headerText.style.display = 'block';
headerText.style.margin = '1vw';
headerText.style.textAlign = 'center';
headerText.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
headerText.style.fontSize = '2vw';
headerText.style.color = 'white';
// headerText will be added to mainUIContent later
// Input container (relative for the dropdown)
const inputContainer = document.createElement('div');
inputContainer.style.display = 'flex';
inputContainer.style.flexDirection = 'column';
inputContainer.style.alignItems = 'center';
inputContainer.style.position = 'relative';
const inputBox = document.createElement('input');
inputBox.type = 'text';
inputBox.style.color = 'white';
inputBox.style.backgroundColor = 'rgba(0, 0, 0, 0.2)';
inputBox.style.border = '1px solid rgba(255, 255, 255, 0.2)';
inputBox.placeholder = 'Enter Quiz ID or Name...';
inputBox.style.width = '27.8vw';
inputBox.style.height = '2vw';
inputBox.style.margin = '0';
inputBox.style.padding = '0.5vw';
inputBox.style.boxSizing = 'border-box';
inputBox.style.borderRadius = '0.5vw';
inputBox.style.outline = 'none';
inputBox.style.textAlign = 'center';
inputBox.style.fontSize = '1.15vw';
inputContainer.appendChild(inputBox);
// If user manually clears input, reset
inputBox.addEventListener('input', function() {
if (inputBox.value.trim() === "") {
resetUI();
}
});
// Button container for Enter, Persist, Delete
const buttonContainer = document.createElement('div');
buttonContainer.style.display = 'flex';
buttonContainer.style.marginTop = '0.5vw';
buttonContainer.style.gap = '0.3vw';
buttonContainer.style.width = '27.8vw';
buttonContainer.style.justifyContent = 'space-between';
// Enter button with consistent font
const enterButton = document.createElement('button');
enterButton.textContent = 'Enter';
enterButton.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
enterButton.style.width = '45%';
enterButton.style.fontSize = '1.15vw';
enterButton.style.cursor = 'pointer';
enterButton.addEventListener('click', handleInputChange);
buttonContainer.appendChild(enterButton);
// Persist button
const persistButton = document.createElement('button');
persistButton.textContent = 'Persist';
persistButton.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
persistButton.style.width = '25%';
persistButton.style.fontSize = '1.15vw';
persistButton.style.cursor = 'pointer';
persistButton.style.backgroundColor = '#4CAF50';
persistButton.style.color = 'white';
persistButton.addEventListener('click', persistQuizId);
buttonContainer.appendChild(persistButton);
// Delete button
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Delete';
deleteButton.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
deleteButton.style.width = '25%';
deleteButton.style.fontSize = '1.15vw';
deleteButton.style.cursor = 'pointer';
deleteButton.style.backgroundColor = '#f44336';
deleteButton.style.color = 'white';
deleteButton.addEventListener('click', deletePersistedQuizId);
buttonContainer.appendChild(deleteButton);
inputContainer.appendChild(buttonContainer);
// Persistence functions
function persistQuizId() {
const quizId = sanitizeInput(inputBox.value);
if (quizId.trim() === "") {
alert("Please enter a Quiz ID first!");
return;
}
localStorage.setItem('kahoot_persisted_quiz', quizId);
persistButton.style.backgroundColor = '#45a049';
persistButton.textContent = 'Saved!';
setTimeout(() => {
persistButton.style.backgroundColor = '#4CAF50';
persistButton.textContent = 'Persist';
}, 2000);
console.log("Quiz ID persisted:", quizId);
}
function deletePersistedQuizId() {
localStorage.removeItem('kahoot_persisted_quiz');
deleteButton.style.backgroundColor = '#d32f2f';
deleteButton.textContent = 'Deleted!';
setTimeout(() => {
deleteButton.style.backgroundColor = '#f44336';
deleteButton.textContent = 'Delete';
}, 2000);
console.log("Persisted Quiz ID deleted");
}
function loadPersistedQuizId() {
const persistedQuiz = localStorage.getItem('kahoot_persisted_quiz');
if (persistedQuiz) {
inputBox.value = persistedQuiz;
inputBox.style.backgroundColor = '#e8f5e8';
console.log("Loaded persisted Quiz ID:", persistedQuiz);
// Auto-load the quiz
setTimeout(() => handleInputChange(), 1000); // Delay to ensure UI is ready
}
}
// Dropdown for fallback suggestions
const dropdown = document.createElement('div');
dropdown.style.position = 'absolute';
dropdown.style.top = 'calc(100% + 0.5vw)';
dropdown.style.left = '0';
dropdown.style.width = '27.8vw';
dropdown.style.backgroundColor = 'white';
dropdown.style.border = '.1vw solid black';
dropdown.style.borderRadius = '0.5vw';
dropdown.style.zIndex = '10000';
dropdown.style.maxHeight = '30vw';
dropdown.style.overflowY = 'auto';
dropdown.style.display = 'none';
inputContainer.appendChild(dropdown);
// X button to close dropdown & reset
const dropdownCloseButton = document.createElement('button');
dropdownCloseButton.textContent = 'X';
dropdownCloseButton.style.position = 'absolute';
dropdownCloseButton.style.top = '-2vw';
dropdownCloseButton.style.right = '0';
dropdownCloseButton.style.width = '2vw';
dropdownCloseButton.style.height = '2vw';
dropdownCloseButton.style.backgroundColor = 'red';
dropdownCloseButton.style.color = 'white';
dropdownCloseButton.style.border = 'none';
dropdownCloseButton.style.borderRadius = '50%';
dropdownCloseButton.style.cursor = 'pointer';
dropdownCloseButton.style.fontSize = '1vw';
dropdownCloseButton.style.display = 'none';
dropdownCloseButton.addEventListener('click', function() {
resetUI();
});
inputContainer.appendChild(dropdownCloseButton);
// inputContainer will be added to mainUIContent later
// SHOW ANSWERS
const header3 = document.createElement('h2');
header3.textContent = 'SHOW ANSWERS';
header3.style.display = 'block';
header3.style.margin = '1vw';
header3.style.textAlign = 'center';
header3.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
header3.style.fontSize = '2vw';
header3.style.color = 'white';
// header3 will be added to mainUIContent later
const showAnswersSwitchContainer = document.createElement('div');
showAnswersSwitchContainer.className = 'switch-container';
showAnswersSwitchContainer.style.display = 'flex';
showAnswersSwitchContainer.style.alignItems = 'center';
showAnswersSwitchContainer.style.justifyContent = 'center';
// showAnswersSwitchContainer will be added to mainUIContent later
const showAnswersLabel = document.createElement('span');
showAnswersLabel.textContent = 'Show Answers';
showAnswersLabel.className = 'switch-label';
showAnswersLabel.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
showAnswersLabel.style.fontSize = '1.5vw';
showAnswersLabel.style.color = 'white';
showAnswersLabel.style.margin = '2.5vw';
showAnswersSwitchContainer.appendChild(showAnswersLabel);
const showAnswersSwitch = document.createElement('label');
showAnswersSwitch.className = 'switch';
showAnswersSwitchContainer.appendChild(showAnswersSwitch);
const showAnswersInput = document.createElement('input');
showAnswersInput.type = 'checkbox';
showAnswersInput.addEventListener('change', function() {
showAnswers = this.checked;
});
showAnswersSwitch.appendChild(showAnswersInput);
const showAnswersSlider = document.createElement('span');
showAnswersSlider.className = 'slider';
showAnswersSwitch.appendChild(showAnswersSlider);
// NEXT QUESTION PREVIEW
const nextQuestionContainer = document.createElement('div');
nextQuestionContainer.style.margin = '1vw';
nextQuestionContainer.style.padding = '1vw';
nextQuestionContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.1)';
nextQuestionContainer.style.borderRadius = '0.5vw';
nextQuestionContainer.style.textAlign = 'center';
// nextQuestionContainer will be added to mainUIContent later
const nextQuestionLabel = document.createElement('h3');
nextQuestionLabel.textContent = 'NEXT QUESTION PREVIEW';
nextQuestionLabel.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
nextQuestionLabel.style.fontSize = '1.5vw';
nextQuestionLabel.style.color = 'white';
nextQuestionLabel.style.margin = '0.5vw 0';
nextQuestionContainer.appendChild(nextQuestionLabel);
const nextQuestionDisplay = document.createElement('div');
nextQuestionDisplay.id = 'nextQuestionDisplay';
nextQuestionDisplay.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
nextQuestionDisplay.style.fontSize = '1.8vw';
nextQuestionDisplay.style.color = '#00ff00';
nextQuestionDisplay.style.fontWeight = 'bold';
nextQuestionDisplay.style.margin = '0.5vw 0';
nextQuestionDisplay.style.textShadow = '0 0 5px rgba(0, 255, 0, 0.5)';
nextQuestionDisplay.textContent = 'Loading...';
nextQuestionContainer.appendChild(nextQuestionDisplay);
// CSS style including media queries for mobile
const style = document.createElement('style');
style.textContent = `
.custom-slider {
background: white;
border: none;
outline: none;
cursor: ew-resize;
appearance: none;
height: 0;
}
.custom-slider::-webkit-slider-thumb {
appearance: none;
width: 1.75vw;
height: 1.75vw;
background-color: rgb(47, 47, 47);
border-radius: 50%;
cursor: ew-resize;
margin-top: -0.5vw;
}
.custom-slider::-webkit-slider-runnable-track {
width: 100%;
height: 0.75vw;
background-color: white;
cursor: ew-resize;
border-radius: 1vw;
background: linear-gradient(to right, red, yellow, limegreen);
}
:root {
--switch-width: 5.9vw;
--switch-height: 3.3vw;
--slider-size: 2.5vw;
--slider-thumb-size: 1.3vw;
}
.switch {
position: relative;
display: inline-block;
width: var(--switch-width);
height: var(--switch-height);
margin: 2.5vw;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0; left: 0; right: 0; bottom: 0;
background-color: red;
transition: 0.8s;
border-radius: .5vw;
}
.slider:before {
position: absolute;
content: "";
height: var(--slider-size);
width: var(--slider-size);
left: calc(var(--slider-thumb-size) / 3);
bottom: calc(var(--slider-thumb-size) / 3);
background-color: rgb(43, 43, 43);
transition: 0.8s;
border-radius: .5vw;
}
input:checked + .slider {
background-color: green;
}
input:focus + .slider {
box-shadow: 0 0 1px green;
}
input:checked + .slider:before {
transform: translateX(calc(var(--slider-size)));
}
/* MEDIA QUERY for narrower screens (phones, small tablets). */
@media (max-width: 768px) {
.floating-ui {
width: 80vw !important;
left: 10vw !important;
top: 5vh !important;
border-radius: 3vw !important;
}
.handle {
font-size: 4vw !important;
height: 8vw !important;
line-height: 6vw !important;
border-radius: 3vw 3vw 0 0 !important;
}
.minimize-button, .close-button {
width: 10vw !important;
height: 8vw !important;
font-size: 4vw !important;
}
.floating-ui h2 {
font-size: 4vw !important;
margin: 2vw !important;
}
.floating-ui input[type="text"] {
font-size: 3vw !important;
width: 60vw !important;
height: 6vw !important;
border-radius: 2vw !important;
}
.floating-ui button {
font-family: "Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif !important;
font-size: 3vw !important;
height: 7vw !important;
border-radius: 2vw !important;
}
/* Button container on mobile */
.floating-ui div[style*="display: flex"][style*="gap: 0.3vw"] {
width: 60vw !important;
gap: 1vw !important;
}
.floating-ui div[style*="display: flex"][style*="gap: 0.3vw"] button {
font-size: 2.5vw !important;
}
.floating-ui .custom-slider::-webkit-slider-thumb {
width: 4vw !important;
height: 4vw !important;
margin-top: -1.3vw !important;
}
.floating-ui .custom-slider::-webkit-slider-runnable-track {
height: 2vw !important;
}
:root {
--switch-width: 12vw;
--switch-height: 6vw;
--slider-size: 4vw;
--slider-thumb-size: 2vw;
}
.switch {
margin: 3vw !important;
}
.floating-ui h1,
.floating-ui h2,
.floating-ui span {
font-size: 3vw !important;
}
/* For the dropdown on mobile, let's make it wider. */
.floating-ui div[style*="position: absolute;"][style*="z-index: 10000"] {
width: 60vw !important;
}
/* Adjust X button position on mobile */
.floating-ui button[style*="position: absolute;"][style*="background-color: red"] {
top: -3vw !important;
right: -3vw !important;
width: 6vw !important;
height: 6vw !important;
font-size: 3vw !important;
}
}
`;
document.head.appendChild(style);
// INFO
const header4 = document.createElement('h2');
header4.textContent = 'INFO';
header4.style.display = 'block';
header4.style.margin = '1vw';
header4.style.textAlign = 'center';
header4.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
header4.style.fontSize = '2vw';
header4.style.color = 'white';
// header4 will be added to mainUIContent later
// questionsLabel
const questionsLabel = document.createElement('span');
questionsLabel.textContent = 'Question 0 / 0';
questionsLabel.style.display = 'block';
questionsLabel.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
questionsLabel.style.fontSize = '1.5vw';
questionsLabel.style.textAlign = 'center';
questionsLabel.style.margin = '1vw';
questionsLabel.style.marginLeft = '1vw';
questionsLabel.style.marginRight = '1vw';
questionsLabel.style.color = 'white';
// questionsLabel will be added to mainUIContent later
// Removed input lag text from the UI entirely
// Version label removed
closeButton.addEventListener('click', () => {
document.body.removeChild(uiElement);
showAnswers = false;
});
let isMinimized = false;
minimizeButton.addEventListener('click', () => {
isMinimized = !isMinimized;
if (isMinimized) {
// Hide main UI elements
headerText.style.display = 'none';
header3.style.display = 'none';
header4.style.display = 'none';
inputContainer.style.display = 'none';
questionsLabel.style.display = 'none';
showAnswersSwitchContainer.style.display = 'none';
nextQuestionContainer.style.display = 'none';
uiElement.style.height = '2.5vw';
handle.style.height = '100%';
closeButton.style.height = '100%';
minimizeButton.style.height = '100%';
} else {
// Show main UI elements
headerText.style.display = 'block';
header3.style.display = 'block';
header4.style.display = 'block';
inputContainer.style.display = 'flex';
questionsLabel.style.display = 'block';
showAnswersSwitchContainer.style.display = 'flex';
nextQuestionContainer.style.display = 'block';
handle.style.height = '2.5vw';
uiElement.style.height = 'auto';
closeButton.style.height = '2.5vw';
minimizeButton.style.height = '2.5vw';
}
});
// Add click handler to handle title for hiding UI
handle.addEventListener('click', function(e) {
// Only hide if clicking on the text part, not the buttons
if (e.target === handle) {
uiElement.style.display = 'none';
langSelector.style.display = 'block';
}
});
let isDragging = false;
let offsetX, offsetY;
handle.addEventListener('mousedown', (e) => {
// Prevent hiding when dragging
if (e.target === handle) {
isDragging = true;
offsetX = e.clientX - uiElement.getBoundingClientRect().left;
offsetY = e.clientY - uiElement.getBoundingClientRect().top;
}
});
document.addEventListener('mousemove', (e) => {
if (isDragging) {
const x = e.clientX - offsetX;
const y = e.clientY - offsetY;
uiElement.style.left = x + 'px';
uiElement.style.top = y + 'px';
}
});
document.addEventListener('mouseup', (e) => {
if (isDragging) {
isDragging = false;
// Prevent click event from firing if we were dragging
e.stopPropagation();
}
});
// --- Fallback Dropdown Search ---
function searchPublicUUID(searchTerm) {
const searchUrl = 'https://damp-leaf-16aa.johnwee.workers.dev/rest/kahoots/?query=' + encodeURIComponent(searchTerm);
console.log("Fallback search URL:", searchUrl);
fetch(searchUrl)
.then(response => response.json())
.then(data => {
console.log("Fallback search data:", data);
let results = (data.entities && data.entities.length > 0) ? data.entities : [];
dropdown.innerHTML = "";
if (Array.isArray(results) && results.length > 0) {
results.forEach(entity => {
let card = entity.card || {};
let displayTitle = card.title || card.name || "No title";
let displayCover = card.cover || card.image || 'https://dummyimage.com/50x50/ccc/fff.png&text=No+Image';
let quizUUID = card.uuid || card.id || "";
const item = document.createElement('div');
item.style.display = 'flex';
item.style.alignItems = 'center';
item.style.padding = '0.5vw';
item.style.cursor = 'pointer';
item.addEventListener('mouseover', function() {
item.style.backgroundColor = '#ddd';
});
item.addEventListener('mouseout', function() {
item.style.backgroundColor = 'white';
});
const img = document.createElement('img');
img.src = displayCover;
img.alt = displayTitle;
img.style.width = '3vw';
img.style.height = '3vw';
img.style.marginRight = '1vw';
const text = document.createElement('span');
text.textContent = displayTitle;
text.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
item.appendChild(img);
item.appendChild(text);
item.addEventListener('click', function() {
console.log("Selected entity:", card);
inputBox.value = quizUUID;
dropdown.style.display = 'none';
dropdownCloseButton.style.display = 'none';
handleInputChange();
});
dropdown.appendChild(item);
});
dropdown.style.display = 'block';
dropdownCloseButton.style.display = 'block';
} else {
dropdown.style.display = 'none';
dropdownCloseButton.style.display = 'none';
}
})
.catch(err => {
console.error("Fallback search error:", err);
dropdown.style.display = 'none';
dropdownCloseButton.style.display = 'none';
});
}
// --- Lookup Function ---
function handleInputChange() {
var rawInput = inputBox.value;
var quizID = sanitizeInput(rawInput);
const url = 'https://damp-leaf-16aa.johnwee.workers.dev/api-proxy/' + encodeURIComponent(quizID);
console.log("Direct lookup URL:", url);
if (quizID !== "") {
fetch(url)
.then(response => {
if (!response.ok) { throw new Error('Direct lookup failed'); }
return response.json();
})
.then(data => {
console.log("Direct lookup data:", data);
inputBox.style.backgroundColor = 'green';
dropdown.style.display = 'none';
dropdownCloseButton.style.display = 'none';
questions = parseQuestions(data.questions);
info.numQuestions = questions.length;
})
.catch(error => {
console.error("Direct lookup error:", error);
inputBox.style.backgroundColor = 'red';
info.numQuestions = 0;
// Fallback: offer public search suggestions.
searchPublicUUID(quizID);
});
} else {
inputBox.style.backgroundColor = 'white';
info.numQuestions = 0;
}
}
// Main UI content container
const mainUIContent = document.createElement('div');
mainUIContent.id = 'mainUIContent';
// Move all existing UI elements into mainUIContent
mainUIContent.appendChild(headerText);
mainUIContent.appendChild(inputContainer);
mainUIContent.appendChild(header3);
mainUIContent.appendChild(showAnswersSwitchContainer);
mainUIContent.appendChild(nextQuestionContainer);
mainUIContent.appendChild(header4);
mainUIContent.appendChild(questionsLabel);
function showMainUI() {
// Append main UI
uiElement.appendChild(mainUIContent);
// Add test mode indicator if in trial mode
if (isTrialMode) {
const testModeIndicator = document.createElement('div');
testModeIndicator.style.textAlign = 'center';
testModeIndicator.style.marginBottom = '10px';
testModeIndicator.style.padding = '8px';
testModeIndicator.style.background = 'rgba(255, 193, 7, 0.2)';
testModeIndicator.style.borderRadius = '4px';
testModeIndicator.style.borderLeft = '3px solid #ffc107';
const testModeText = document.createElement('div');
testModeText.textContent = 'Test Mode';
testModeText.style.fontWeight = 'bold';
testModeText.style.color = '#ffc107';
testModeText.style.marginBottom = '4px';
testModeText.style.fontSize = '1.2em';
const testModeDesc = document.createElement('div');
testModeDesc.textContent = '1.5s answer delay';
testModeDesc.style.color = '#ffeb3b';
testModeDesc.style.fontSize = '0.9em';
testModeIndicator.appendChild(testModeText);
testModeIndicator.appendChild(testModeDesc);
// Insert test mode indicator at the top of the UI
uiElement.insertBefore(testModeIndicator, mainUIContent);
// Change unlock button text if it exists
const unlockBtn = document.querySelector('#unlockButton');
if (unlockBtn) {
unlockBtn.textContent = 'Unlock Full Features for $5';
}
}
// Load persisted quiz ID after main UI is shown
setTimeout(() => loadPersistedQuizId(), 500);
}
function createPaywallUI() {
const paywallContainer = document.createElement('div');
paywallContainer.id = 'paywallContainer';
paywallContainer.style.display = 'flex';
paywallContainer.style.flexDirection = 'column';
paywallContainer.style.alignItems = 'center';
paywallContainer.style.padding = '3vw 1vw'; // Reduced padding for more space
paywallContainer.style.textAlign = 'center';
paywallContainer.style.width = '100%';
paywallContainer.style.boxSizing = 'border-box';
const titleContainer = document.createElement('div');
titleContainer.id = 'titleContainer';
titleContainer.style.width = '100%';
titleContainer.style.marginBottom = '3vw'; // Reduced margin for better spacing
titleContainer.style.padding = '0 1vw'; // Reduced padding for more space
const paywallTitle = document.createElement('h2');
paywallTitle.textContent = 'Hack Kahoot → Get Answers Instantly';
paywallTitle.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
// Responsive font size
paywallTitle.style.fontSize = 'min(2rem, 7vw)'; // Slightly smaller for better fit
paywallTitle.style.lineHeight = '1.2';
paywallTitle.style.fontWeight = 'bold';
paywallTitle.style.color = 'white';
paywallTitle.style.margin = '0 auto';
paywallTitle.style.padding = 'min(2vw, 15px) min(4vw, 20px)';
paywallTitle.style.background = 'rgba(0, 0, 0, 0.6)';
paywallTitle.style.borderRadius = '0.5vw';
paywallTitle.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)';
paywallTitle.style.textShadow = '2px 2px 4px rgba(0, 0, 0, 0.5)';
paywallTitle.style.transition = 'all 0.3s ease';
titleContainer.appendChild(paywallTitle);
paywallContainer.appendChild(titleContainer);
const paywallDescription = document.createElement('p');
paywallDescription.id = 'paywallDescription';
paywallDescription.textContent = 'Unlock lifetime access to instant answers and next question previews for just $5.';
paywallDescription.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
paywallDescription.style.fontSize = 'min(1.2rem, 4.5vw)'; // Slightly larger for better readability
paywallDescription.style.color = 'white';
paywallDescription.style.margin = '0 0 4vw 0';
paywallDescription.style.padding = '0 2vw'; // Reduced side padding for more space
paywallDescription.style.textAlign = 'center';
paywallDescription.style.lineHeight = '1.6'; // Increased line height for better readability
paywallDescription.style.whiteSpace = 'normal'; // Allow text to wrap
paywallDescription.style.wordBreak = 'break-word'; // Break long words if needed
paywallDescription.style.transition = 'all 0.3s ease';
paywallContainer.appendChild(paywallDescription);
const unlockButton = document.createElement('button');
unlockButton.textContent = isTrialMode ? 'Unlock Full Features for $5' : 'Unlock Now for $5';
unlockButton.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
unlockButton.style.width = '90%';
unlockButton.style.maxWidth = '300px';
unlockButton.style.height = 'auto';
unlockButton.style.minHeight = '45px';
unlockButton.style.fontSize = 'min(1.3rem, 4.2vw)'; // Slightly smaller font for better fit
unlockButton.style.whiteSpace = 'normal'; // Allow text to wrap
unlockButton.style.height = 'auto'; // Allow button to grow with text
unlockButton.style.padding = '8px 12px'; // Adjusted padding for better fit
unlockButton.style.padding = '10px 20px';
unlockButton.style.cursor = 'pointer';
unlockButton.style.background = 'linear-gradient(90deg, #ff8a00, #e52e71)';
unlockButton.style.transition = 'transform 0.2s ease';
unlockButton.addEventListener('mouseover', () => { unlockButton.style.transform = 'scale(1.05)'; });
unlockButton.addEventListener('mouseout', () => { unlockButton.style.transform = 'scale(1)'; });
unlockButton.style.color = 'white';
unlockButton.style.border = 'none';
unlockButton.style.borderRadius = '8px';
unlockButton.style.margin = '1.5vw 0'; // Reduced margin for better spacing
unlockButton.style.whiteSpace = 'nowrap';
unlockButton.style.overflow = 'hidden';
unlockButton.style.textOverflow = 'ellipsis';
unlockButton.addEventListener('click', () => {
window.location.href = stripeLink;
});
paywallContainer.appendChild(unlockButton);
const trialButton = document.createElement('button');
trialButton.id = 'trialButton';
trialButton.textContent = 'Test Features (Free)';
trialButton.style.fontFamily = '"Montserrat", "Noto Sans Arabic", "Helvetica Neue", Helvetica, Arial, sans-serif';
trialButton.style.width = '90%';
trialButton.style.maxWidth = '300px';
trialButton.style.height = 'auto';
trialButton.style.minHeight = '40px';
trialButton.style.fontSize = 'min(1.1rem, 4vw)'; // Slightly smaller font for better fit
trialButton.style.whiteSpace = 'normal'; // Allow text to wrap
trialButton.style.height = 'auto'; // Allow button to grow with text
trialButton.style.padding = '6px 10px'; // Adjusted padding for better fit
trialButton.style.padding = '8px 16px';
trialButton.style.cursor = 'pointer';
trialButton.style.backgroundColor = 'rgba(255, 255, 255, 0.1)';
trialButton.style.color = 'white';
trialButton.style.border = '1px solid rgba(255, 255, 255, 0.2)';
trialButton.style.borderRadius = '8px';
trialButton.style.margin = '1vw 0'; // Keep consistent margin
trialButton.style.maxWidth = '90%'; // Ensure button doesn't touch screen edges
trialButton.style.whiteSpace = 'nowrap';
trialButton.style.overflow = 'hidden';
trialButton.style.textOverflow = 'ellipsis';
trialButton.style.transition = 'all 0.3s ease';
trialButton.addEventListener('click', () => {
// Hide title, description, and trial button
const titleContainer = document.getElementById('titleContainer');
const paywallDescription = document.querySelector('#paywallContainer > p');
if (titleContainer) titleContainer.style.display = 'none';
if (paywallDescription) paywallDescription.style.display = 'none';
trialButton.style.display = 'none';
// Enable trial mode
isTrialMode = true;
showMainUI();
});
// Add the trial button to a separate container for better control
const buttonContainer = document.createElement('div');
buttonContainer.style.display = 'flex';
buttonContainer.style.flexDirection = 'column';
buttonContainer.style.alignItems = 'center';
buttonContainer.style.width = '100%';
buttonContainer.appendChild(trialButton);
paywallContainer.appendChild(buttonContainer);
// Make sure unlock button is always visible and properly positioned
unlockButton.id = 'unlockButton';
unlockButton.style.margin = '1vw auto 0';
unlockButton.style.display = 'block';
return paywallContainer;
}
function showPaywallUI() {
uiElement.innerHTML = ''; // Clear existing content
uiElement.appendChild(handle);
uiElement.appendChild(createPaywallUI());
// If in trial mode, hide the title and description
if (isTrialMode) {
const titleContainer = document.getElementById('titleContainer');
const paywallDescription = document.querySelector('#paywallContainer > p');
const trialButton = document.getElementById('trialButton');
if (titleContainer) titleContainer.style.display = 'none';
if (paywallDescription) paywallDescription.style.display = 'none';
if (trialButton) trialButton.style.display = 'none';
}
}
function initialize() {
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('paid') === 'unlock_3f9xQ7mJ29dK8hPwR1') {
localStorage.setItem('kahoot_unlocked', 'true');
// Clean the URL
window.history.replaceState({}, document.title, window.location.pathname);
}
const isUnlocked = localStorage.getItem('kahoot_unlocked') === 'true';
if (isUnlocked) {
showMainUI();
} else {
showPaywallUI();
}
}
// Initialize UI
initialize();
// Create language selector (hidden UI state)
const langSelector = document.createElement('div');
langSelector.style.position = 'absolute';
langSelector.style.top = '10px';
langSelector.style.right = '10px';
langSelector.style.width = '40px';
langSelector.style.height = '20px';
langSelector.style.backgroundColor = '#f0f0f0';
langSelector.style.border = '1px solid #ccc';
langSelector.style.borderRadius = '3px';
langSelector.style.cursor = 'pointer';
langSelector.style.fontSize = '10px';
langSelector.style.textAlign = 'center';
langSelector.style.lineHeight = '20px';
langSelector.style.color = '#666';
langSelector.style.zIndex = '9998';
langSelector.style.display = 'none'; // Hidden by default
langSelector.textContent = 'EN';
langSelector.title = 'Language Selector';
// Add click handler to show UI
langSelector.addEventListener('click', function() {
uiElement.style.display = 'block';
langSelector.style.display = 'none';
});
document.body.appendChild(langSelector);
document.body.appendChild(uiElement);
// Quiz loading will be handled after authentication
function parseQuestions(questionsJson){
let questions = [];