-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontent.js
58 lines (46 loc) · 1.36 KB
/
content.js
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
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
'use strict';
if (msg.text === 'get_start_data') {
onGetStartData(sendResponse);
} else if (msg.text === 'get_stop_data') {
onGetStopData(sendResponse);
}
});
const onGetStartData = (sendResponse) => {
'use strict';
const error = (document.getElementsByClassName('day-desc').length === 0);
if (error) {
sendResponse({ error: true });
return;
}
const userName = getUserName();
if (!userName) {
sendResponse({ error: true });
return;
}
const part = (document.getElementById('part2') === null ? 1 : 2);
sendResponse({ userName, part });
};
const onGetStopData = (sendResponse) => {
'use strict';
const error = (document.getElementsByClassName('day-success').length === 0);
if (error) {
sendResponse({ error: true });
return;
}
const userName = getUserName();
if (!userName) {
sendResponse({ error: true });
return;
}
const part = (document.getElementsByClassName('share').length === 0 ? 1 : 2);
sendResponse({ userName, part });
};
const getUserName = () => {
'use strict';
const element = document.querySelector('header .user');
if (!element) {
return undefined;
}
return element.firstChild.textContent.trim();
};