@rcnr/lockdown 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -4
- package/dist/index.mjs +10 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -147,15 +147,17 @@ function useLockdown({
|
|
|
147
147
|
"Final warning: leave this window again and your work will be auto-submitted."
|
|
148
148
|
);
|
|
149
149
|
setTimeout(() => setWarning(null), WARNING_DISPLAY_MS);
|
|
150
|
+
startCountdown();
|
|
150
151
|
} else {
|
|
151
152
|
setWarning(
|
|
152
153
|
`Warning: you left the writing window. You have ${remaining} chance${remaining > 1 ? "s" : ""} left.`
|
|
153
154
|
);
|
|
154
155
|
setTimeout(() => setWarning(null), WARNING_DISPLAY_MS);
|
|
156
|
+
startCountdown();
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
},
|
|
158
|
-
[triggerAutoSubmit]
|
|
160
|
+
[triggerAutoSubmit, startCountdown]
|
|
159
161
|
);
|
|
160
162
|
const enterFullscreen = (0, import_react.useCallback)(async () => {
|
|
161
163
|
try {
|
|
@@ -198,9 +200,6 @@ function useLockdown({
|
|
|
198
200
|
} else if (!graceRef.current && hasEnteredFullscreenRef.current) {
|
|
199
201
|
lastFsExitRef.current = Date.now();
|
|
200
202
|
addViolation("fullscreen_exit");
|
|
201
|
-
if (fullscreenExitCountRef.current <= MAX_FULLSCREEN_EXITS) {
|
|
202
|
-
startCountdown();
|
|
203
|
-
}
|
|
204
203
|
}
|
|
205
204
|
}
|
|
206
205
|
function handleVisibilityChange() {
|
|
@@ -280,9 +279,15 @@ function useLockdown({
|
|
|
280
279
|
function handleContextMenu(e) {
|
|
281
280
|
e.preventDefault();
|
|
282
281
|
}
|
|
282
|
+
function handleFocus() {
|
|
283
|
+
if (countdownIntervalRef.current) {
|
|
284
|
+
clearCountdown();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
283
287
|
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
284
288
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
285
289
|
window.addEventListener("blur", handleBlur);
|
|
290
|
+
window.addEventListener("focus", handleFocus);
|
|
286
291
|
document.addEventListener("paste", handlePaste);
|
|
287
292
|
document.addEventListener("copy", handleCopy);
|
|
288
293
|
document.addEventListener("cut", handleCut);
|
|
@@ -296,6 +301,7 @@ function useLockdown({
|
|
|
296
301
|
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
297
302
|
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
298
303
|
window.removeEventListener("blur", handleBlur);
|
|
304
|
+
window.removeEventListener("focus", handleFocus);
|
|
299
305
|
document.removeEventListener("paste", handlePaste);
|
|
300
306
|
document.removeEventListener("copy", handleCopy);
|
|
301
307
|
document.removeEventListener("cut", handleCut);
|
package/dist/index.mjs
CHANGED
|
@@ -120,15 +120,17 @@ function useLockdown({
|
|
|
120
120
|
"Final warning: leave this window again and your work will be auto-submitted."
|
|
121
121
|
);
|
|
122
122
|
setTimeout(() => setWarning(null), WARNING_DISPLAY_MS);
|
|
123
|
+
startCountdown();
|
|
123
124
|
} else {
|
|
124
125
|
setWarning(
|
|
125
126
|
`Warning: you left the writing window. You have ${remaining} chance${remaining > 1 ? "s" : ""} left.`
|
|
126
127
|
);
|
|
127
128
|
setTimeout(() => setWarning(null), WARNING_DISPLAY_MS);
|
|
129
|
+
startCountdown();
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
},
|
|
131
|
-
[triggerAutoSubmit]
|
|
133
|
+
[triggerAutoSubmit, startCountdown]
|
|
132
134
|
);
|
|
133
135
|
const enterFullscreen = useCallback(async () => {
|
|
134
136
|
try {
|
|
@@ -171,9 +173,6 @@ function useLockdown({
|
|
|
171
173
|
} else if (!graceRef.current && hasEnteredFullscreenRef.current) {
|
|
172
174
|
lastFsExitRef.current = Date.now();
|
|
173
175
|
addViolation("fullscreen_exit");
|
|
174
|
-
if (fullscreenExitCountRef.current <= MAX_FULLSCREEN_EXITS) {
|
|
175
|
-
startCountdown();
|
|
176
|
-
}
|
|
177
176
|
}
|
|
178
177
|
}
|
|
179
178
|
function handleVisibilityChange() {
|
|
@@ -253,9 +252,15 @@ function useLockdown({
|
|
|
253
252
|
function handleContextMenu(e) {
|
|
254
253
|
e.preventDefault();
|
|
255
254
|
}
|
|
255
|
+
function handleFocus() {
|
|
256
|
+
if (countdownIntervalRef.current) {
|
|
257
|
+
clearCountdown();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
256
260
|
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
257
261
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
258
262
|
window.addEventListener("blur", handleBlur);
|
|
263
|
+
window.addEventListener("focus", handleFocus);
|
|
259
264
|
document.addEventListener("paste", handlePaste);
|
|
260
265
|
document.addEventListener("copy", handleCopy);
|
|
261
266
|
document.addEventListener("cut", handleCut);
|
|
@@ -269,6 +274,7 @@ function useLockdown({
|
|
|
269
274
|
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
270
275
|
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
271
276
|
window.removeEventListener("blur", handleBlur);
|
|
277
|
+
window.removeEventListener("focus", handleFocus);
|
|
272
278
|
document.removeEventListener("paste", handlePaste);
|
|
273
279
|
document.removeEventListener("copy", handleCopy);
|
|
274
280
|
document.removeEventListener("cut", handleCut);
|