-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogUnfocus.js
More file actions
executable file
·61 lines (56 loc) · 1.54 KB
/
LogUnfocus.js
File metadata and controls
executable file
·61 lines (56 loc) · 1.54 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
var EnforceUnfocus = false;
async function LogDeltaVisibility(ComingOrGoing) {
try {
// Set the data to send
var Data = {
SubjectId: SubjectId,
Href: window.location.href
};
// Send the data
var Daddy;
if (ComingOrGoing === 'Going') {
Daddy = './LogUnfocus.php';
} else {
Daddy = './LogRefocus.php';
}
// Unpack the Result
var Result = await PostJson(Daddy, Data);
var {
Bool: Bool = false,
TargetUrl: TargetUrl = '',
Notice: Notice = '',
Reason: Reason = ''
} = Result || {};
// Branch depending on the Result
if (!Bool) {
if (Notice) {
alert(Notice);
}
} else {
TaskIO.Sent2Coventry = Reason;
await WriteTaskIO();
if (TargetUrl) {
window.location.replace(TargetUrl);
}
}
} catch (Err) {
console.error('LogDeltaVisibility failed:', Err);
alert(
"An error has occurred.\n" +
"Please report error code #005 " +
"to Sophie (sj483@sussex.ac.uk)."
);
}
return;
}
document.addEventListener("visibilitychange", () => {
if (!(Boolean(SubjectId) && EnforceUnfocus)) {
return;
}
if (document.visibilityState === "hidden") {
void LogDeltaVisibility('Going');
} else {
void LogDeltaVisibility('Coming');
}
return;
});