Skip to content

Commit

Permalink
add task sum
Browse files Browse the repository at this point in the history
  • Loading branch information
keombre committed Dec 18, 2019
1 parent 5db6d09 commit 885517e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/content/end.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ class Course extends Logged {
container.classList.add('course_container')

this.writeContainers(container)
this.writeContainerSum()
document.body.replaceChild(container, document.querySelector('center'))

document.addEventListener('keydown', e => {
Expand All @@ -617,6 +618,24 @@ class Course extends Logged {
document.head.appendChild(styleSheet)
}

writeContainerSum() {
this.getContainerNames().forEach(e => {
if (e == "results") return
const text = eval(`this.${e}`)
if (text.childElementCount <= 1) return
let sum = 0
text.querySelectorAll('.course_link_score').forEach(e => {
let score = parseFloat(e.innerText)
if (!isNaN(score)) sum += score
})
let sumElem = document.createElement("span")
sumElem.innerText = sum.toFixed(2)
sumElem.classList.add("course_link")
sumElem.classList.add("course_link_score_sum")
text.appendChild(sumElem)
})
}

createSpanningStylesheet(container) {
let stylesheet = ""
for (let elm of container.children)
Expand Down
10 changes: 10 additions & 0 deletions src/themes/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,16 @@ span.course_title {
font-weight: 500;
}

span.course_link_score_sum:before {
content: "Σ = ";
}

span.course_link_score_sum {
text-align: right;
padding-right: 15px;
background: rgba(0, 0, 0, 0.05);
}

.course_link.course_disabled {
font-weight: 400;
}
Expand Down
5 changes: 5 additions & 0 deletions src/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ span span.course_link_score {
background: #394145;
}

span.course_link_score_sum {
color: #eae4ef !important;
border-top: thin solid rgba(255, 255, 255, 0.3) !important;
}

a.course_link:hover {
background-color: rgba(0, 0, 0, 0.2);
}
Expand Down
5 changes: 5 additions & 0 deletions src/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ span span.course_link_score {
background: #B0BEC5;
}

span.course_link_score_sum {
color: #807a85 !important;
border-top: thin solid rgba(0, 0, 0, 0.1) !important;
}

a.course_link:hover {
background-color: rgba(0, 0, 0, 0.1);
}
Expand Down

0 comments on commit 885517e

Please sign in to comment.