File size: 2,813 Bytes
00972a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const formIframe = document.getElementById('form-iframe');
const formStatus = document.getElementById('formStatus');
const currentTimeDisplay = document.getElementById('time');
const startTimeDisplay = document.getElementById('startTimeDisplay');
const endTimeDisplay = document.getElementById('endTimeDisplay');
const userNameDisplay = document.getElementById('userName');

// Display user's name
const userName = localStorage.getItem('userName') || 'User';
userNameDisplay.innerText = userName;

// Function to check if the form is open based on current time
function checkFormStatus() {
    const startTime = localStorage.getItem('startTime');
    const endTime = localStorage.getItem('endTime');

    if (startTime && endTime) {
        startTimeDisplay.innerText = startTime;
        endTimeDisplay.innerText = endTime;

        const now = new Date();
        const [startHours, startMinutes] = startTime.split(':').map(Number);
        const [endHours, endMinutes] = endTime.split(':').map(Number);
        
        const startDateTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), startHours, startMinutes);
        const endDateTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), endHours, endMinutes);

        if (now >= startDateTime && now <= endDateTime) {
            formStatus.innerText = 'Open';
            formIframe.style.display = 'block'; // Show the form
        } else {
            formStatus.innerText = 'Closed';
            formIframe.style.display = 'none'; // Hide the form
        }
    }
}

// Update current time display every second
setInterval(() => {
    const now = new Date();
    currentTimeDisplay.innerText = now.toLocaleTimeString();
    checkFormStatus();
}, 1000);

// Fullscreen functionality for the user
const fullscreenBtn = document.getElementById('fullscreen-btn');
if (fullscreenBtn) {
    fullscreenBtn.addEventListener('click', () => {
        if (!document.fullscreenElement) {
            document.documentElement.requestFullscreen().catch(err => {
                console.error("Error attempting to enable fullscreen mode:", err);
            });
        } else {
            document.exitFullscreen();
        }
    });

    // Track when the user exits fullscreen
    document.addEventListener('fullscreenchange', () => {
        if (!document.fullscreenElement) {
            // User exited fullscreen
            const exitedUsers = JSON.parse(localStorage.getItem('exitedUsers')) || [];
            exitedUsers.push(userName);
            localStorage.setItem('exitedUsers', JSON.stringify(exitedUsers));
            alert('You have exited fullscreen. Your name has been recorded.');
        }
    });
}

// Initialize status check
checkFormStatus();