-
Notifications
You must be signed in to change notification settings - Fork 9
/
popup.js
53 lines (44 loc) · 1.89 KB
/
popup.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
const STRIKES_STORAGE_KEY = 'strikes';
const loadStrikeData = () => {
// background.js should have already loaded strike data into our app cache
return new Promise(resolve => {
chrome.storage.local.get(STRIKES_STORAGE_KEY, items => {
if (!items || !items[STRIKES_STORAGE_KEY]) {
console.warn("No strike data in app cache! This is unexpected. Rendering an empty strike list for now.");
resolve({});
} else {
resolve(items[STRIKES_STORAGE_KEY]);
}
});
});
};
(async () => {
const currentDate = new Date();
const strikesByOrgName = await loadStrikeData();
const strikeList = document.getElementById('strike-list');
for (const [orgName, strike] of Object.entries(strikesByOrgName).sort((a, b) => a[0].toUpperCase().localeCompare(b[0].toUpperCase()))) {
if (strike.startTime) {
const startTimeDate = Date.parse(strike.startTime);
if (currentDate < startTimeDate) {
// bail; start time hasn't occurred yet
continue;
}
}
if (strike.endTime) {
const endTimeDate = Date.parse(strike.endTime);
if (endTimeDate <= currentDate) {
// bail; end time has already occurred or is occurring
continue;
}
}
const strikeListItemLinkText = document.createTextNode(orgName);
const strikeListItemLink = document.createElement('a');
strikeListItemLink.href = strike.moreInfoUrl;
strikeListItemLink.rel= "noopener noreferrer";
strikeListItemLink.target= "_blank";
strikeListItemLink.appendChild(strikeListItemLinkText);
const strikeListItem = document.createElement('li');
strikeListItem.appendChild(strikeListItemLink);
strikeList.appendChild(strikeListItem);
}
})();