-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
163 lines (150 loc) · 7.92 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inactivity Detector</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css" rel="stylesheet" />
</head>
<body class="flex flex-col min-h-screen">
<header class="bg-blue-600 text-white py-4">
<div class="container mx-auto px-4 flex justify-between items-center">
<h1 id="inactivity-detector" class="text-2xl md:text-3xl font-bold">Inactivity Detector</h1>
<nav class="flex items-center">
<a href="#about" class="text-white hover:text-blue-200 mr-4">About</a>
<a href="#features" class="text-white hover:text-blue-200 mr-4">Features</a>
<a href="#api-reference" class="text-white hover:text-blue-200 mr-4">API</a>
<a href="https://github.com/lebmatter/inactivityDetector" class="text-white hover:text-blue-200 flex items-center">
<i data-lucide="github" class="w-5 h-5 mr-1"></i>
<span class="hidden md:inline">GitHub</span>
</a>
</nav>
</div>
</header>
<main class="flex-grow container mx-auto px-4 py-8 flex flex-col md:flex-row">
<div class="w-full md:w-1/2 pr-0 md:pr-4">
<section id="about" class="mb-8">
<h2 class="text-xl md:text-2xl font-semibold mb-4">About</h2>
<p>Inactivity Detector is a lightweight JavaScript library that helps you monitor user inactivity, tab changes, and monitor configuration changes. It's particularly useful for applications that require strict user attention, such as online exams or sensitive data entry forms.</p>
</section>
<section id="features" class="mb-8">
<h2 class="text-xl md:text-2xl font-semibold mb-4">Features</h2>
<ul class="list-disc pl-5">
<li>Detect user inactivity based on custom thresholds</li>
<li>Monitor tab changes and window focus</li>
<li>Detect monitor configuration changes</li>
<li>Customizable callbacks for various events</li>
<li>Easy integration with existing projects</li>
</ul>
</section>
<section id="usage" class="mb-8">
<h2 class="text-xl md:text-2xl font-semibold mb-4">Usage</h2>
<pre><code class="language-html"><script src="path/to/inactivityDetector.js"></script>
<script>
const detector = new InactivityDetector({
warningThreshold: 5, // 5 seconds
onInactivityStart: () => {
console.log("User inactivity detected");
},
onInactive: (inactiveStr, secondsInactive) => {
console.log(`User inactive: ${inactiveStr} for ${secondsInactive} seconds`);
},
onActive: () => {
console.log("User active again");
},
onMonitorChange: (lastScreens, currentScreens) => {
console.log(`Monitor changed from ${lastScreens} to ${currentScreens}`);
}
});
detector.init(); // Start detecting
// Later, when you want to stop detecting
detector.destroy();
</script></code></pre>
</section>
<section id="api-reference" class="mb-8">
<h2 class="text-xl md:text-2xl font-semibold mb-4">API Reference</h2>
<h3 class="text-lg md:text-xl font-semibold mb-2">Constructor Options</h3>
<ul class="list-disc pl-5">
<li><strong>warningThreshold</strong>: Number of seconds before considering user as inactive (default: 5)</li>
<li><strong>onInactivityStart()</strong>: Callback function when inactivity is first detected</li>
<li><strong>onInactive(inactiveStr, secondsInactive)</strong>: Callback function when user becomes inactive</li>
<li><strong>onActive()</strong>: Callback function when user becomes active again</li>
<li><strong>onMonitorChange(lastScreens, currentScreens)</strong>: Callback function when monitor configuration changes</li>
</ul>
<h3 class="text-lg md:text-xl font-semibold mb-2 mt-4">Methods</h3>
<ul class="list-disc pl-5">
<li><strong>init()</strong>: Start the inactivity detector</li>
<li><strong>destroy()</strong>: Stop the inactivity detector and clean up event listeners</li>
</ul>
</section>
</div>
<div class="w-full md:w-1/2 pl-0 md:pl-4">
<section id="live-demo" class="mb-8">
<h2 class="text-xl md:text-2xl font-semibold mb-4">Live Demo</h2>
<div class="bg-white p-4 md:p-6 rounded-lg shadow-md">
<div class="mb-4">
<button id="startDetector" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded mr-2">Start Detector</button>
<button id="stopDetector" class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded">Stop Detector</button>
</div>
<p>Try staying inactive for 2 seconds, switching tabs, minimizing the window, or changing your screen resolution to see the detector in action.</p>
<div id="demoOutput" class="mt-4 p-4 bg-gray-100 rounded-lg h-48 overflow-y-auto"></div>
</div>
</section>
</div>
</main>
<footer class="bg-gray-200 py-4">
<div class="container mx-auto px-4 text-center">
<p>© 2024 Inactivity Detector. All rights reserved.</p>
<div class="mt-2">
<a href="#" class="text-blue-600 hover:text-blue-800 mr-4">Privacy Policy</a>
<a href="#" class="text-blue-600 hover:text-blue-800 mr-4">Terms of Service</a>
<a href="https://github.com/lebmatter/inactivityDetector" class="text-blue-600 hover:text-blue-800">GitHub</a>
</div>
</div>
</footer>
<script src="inactivityDetector.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-javascript.min.js"></script>
<script>
lucide.createIcons();
// Demo implementation
const demoOutput = document.getElementById('demoOutput');
const startButton = document.getElementById('startDetector');
const stopButton = document.getElementById('stopDetector');
let detector;
function log(message) {
const logEntry = document.createElement('div');
logEntry.textContent = message;
demoOutput.appendChild(logEntry);
demoOutput.scrollTop = demoOutput.scrollHeight;
}
startButton.addEventListener('click', () => {
detector = new InactivityDetector({
warningThreshold: 2,
onInactivityStart: () => {
log("User inactivity detected");
},
onInactive: (inactiveStr, secondsInactive) => {
log(`User inactive: ${inactiveStr} for ${secondsInactive} seconds`);
},
onActive: () => {
log("User active again");
},
onMonitorChange: (lastScreens, currentScreens) => {
log(`Monitor changed from ${lastScreens} to ${currentScreens}`);
}
});
detector.init();
log("Detector started");
});
stopButton.addEventListener('click', () => {
if (detector) {
detector.destroy();
log("Detector stopped");
}
});
</script>
</body>
</html>