-
-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathtooltip.js
More file actions
75 lines (71 loc) · 2.8 KB
/
tooltip.js
File metadata and controls
75 lines (71 loc) · 2.8 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
import moment from 'moment';
import { seconds_to_duration } from './time';
import DOMPurify from 'dompurify';
import _ from 'lodash';
const sanitize = DOMPurify.sanitize;
export function buildTooltip(bucket, e) {
// WARNING: XSS risk, make sure to sanitize properly
// FIXME: Not actually tested against XSS attacks, implementation needs to be verified in tests.
let inner = 'Unknown bucket type';
// if same day, don't show date
let start = moment(e.timestamp);
let stop = moment(e.timestamp).add(e.duration, 'seconds');
if (start.isSame(stop, 'day')) {
start = start.format('HH:mm:ss');
stop = stop.format('HH:mm:ss');
} else {
start = start.format('YYYY-MM-DD HH:mm:ss');
stop = stop.format('YYYY-MM-DD HH:mm:ss');
}
if (bucket.type == 'currentwindow') {
inner = `
<tr><th>App</th><td>${sanitize(e.data.app)}</td></tr>
<tr><th>Title</th><td>${sanitize(e.data.title)}</td></tr>
`;
} else if (bucket.type == 'web.tab.current') {
inner = `
<tr><th>Title</th><td>${sanitize(e.data.title)}</td></tr>
<tr><th>URL</th><td><a href=${sanitize(e.data.url)}>${sanitize(e.data.url)}</a></td></tr>
`;
if (e.data.gmail_activity) {
inner += `<tr><th>Gmail Activity</th><td>${sanitize(e.data.gmail_activity)}</td></tr>`;
if (e.data.from)
inner += `<tr><th>From</th><td>${sanitize(e.data.from)}</td></tr>`;
if (e.data.subject)
inner += `<tr><th>Subject</th><td>${sanitize(e.data.subject)}</td></tr>`;
if (e.data.to && e.data.to.length > 0)
inner += `<tr><th>To</th><td>${sanitize(
Array.isArray(e.data.to) ? e.data.to.join(', ') : e.data.to
)}</td></tr>`;
if (e.data.cc && e.data.cc.length > 0)
inner += `<tr><th>CC</th><td>${sanitize(
Array.isArray(e.data.cc) ? e.data.cc.join(', ') : e.data.cc
)}</td></tr>`;
if (e.data.bcc && e.data.bcc.length > 0)
inner += `<tr><th>BCC</th><td>${sanitize(
Array.isArray(e.data.bcc) ? e.data.bcc.join(', ') : e.data.bcc
)}</td></tr>`;
}
} else if (bucket.type.startsWith('app.editor')) {
inner = `
<tr><th>Filename</th><td>${sanitize(_.last(e.data.file.split('/')))}</td></tr>
<tr><th>Path</th><td>${sanitize(e.data.file)}</td></tr>
<tr><th>Language</th><td>${sanitize(e.data.language)}</td></tr>
`;
} else if (bucket.type.startsWith('general.stopwatch')) {
inner = `
<tr><th>Label</th><td>${sanitize(e.data.label)}</td></tr>
`;
} else {
inner = `
<tr><th>Data</th><td>${sanitize(JSON.stringify(e.data))}</td></tr>
`;
}
return `<table>
<tr></tr>
<tr><th>Start</th><td>${start}</td></tr>
<tr><th>Stop</th><td>${stop}</td></tr>
<tr><th>Duration </th><td>${seconds_to_duration(e.duration)}</td></tr>
${inner}
</table>`;
}