-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
74 lines (63 loc) · 1.93 KB
/
content.js
File metadata and controls
74 lines (63 loc) · 1.93 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
const getAssignemntObjects = () => {
var obj = []
const table = document
.getElementById('assessmentsDiv1')
.getElementsByTagName('tbody')
for (i = 0; i < table.item(0).rows.length; i++) {
var objCells = table.item(0).rows.item(i)
obj.push(objCells)
}
return obj
}
const modifiedHtml = (content, color) => {
const contentHtml = content.getElementsByTagName('td')
// console.log(color)
contentHtml.item(0).style = `text-align:right; background-color: ${color}`
}
const getDateString = (dateObj) => {
const dateText = dateObj.getElementsByTagName('td')
return dateText.length > 3 ? dateText.item(4).innerHTML : null
}
const calulateUrgency = (date) => {
const now = new Date()
const diff = Math.ceil((date - now) / (1000 * 60 * 60 * 24))
// console.log(diff)
var urgencyRank = -1
if (diff <= 1) urgencyRank = 1
else if (diff <= 2) urgencyRank = 2
else if (diff >= 2) urgencyRank = 3
else urgencyRank = 4
// console.log(urgencyRank)
return urgencyRank - 1
}
const getColor = (urgencyRank) => {
const colors = ['#db4c42', '#d1d13f', '#5fd13f', '#f7f7f7', '#4fdee0']
return colors[urgencyRank]
}
const getEndDate = (datestr) => {
return datestr.substr(27,24)
}
const convertStringToDate = (dateString) => new Date(Date.parse(dateString))
const isSubmitted = (content) => {
const contentHtml = content.getElementsByTagName('td')
if (contentHtml.length > 1) {
const temp = contentHtml.item(6).getElementsByTagName('b').item(0)
.outerText
return temp == 'Submitted' ? true : false
}
return true
}
const main = () => {
const obj = getAssignemntObjects()
for (var i = 0; i < obj.length; i++) {
const dateStr = getDateString(obj[i])
// console.log(`datestr : ${dateStr}`)
if (dateStr && !isSubmitted(obj[i])) {
const deadline = convertStringToDate(getEndDate(dateStr))
const urgencyRank = calulateUrgency(deadline)
const color = getColor(urgencyRank)
modifiedHtml(obj[i], color)
}
}
}
setTimeout(main, 2000)