Skip to content

Commit

Permalink
Merge pull request #15 from Sav22999/new-release
Browse files Browse the repository at this point in the history
2.2
  • Loading branch information
Sav22999 committed Oct 16, 2023
2 parents 42141d5 + 77a9850 commit b6ecd16
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
6 changes: 6 additions & 0 deletions css/style.css
Expand Up @@ -475,6 +475,11 @@ tr:hover {
border-radius: 0px;
}

.avg-time {
background-color: rgba(178, 178, 178, 0.27);
border-radius: 0px;
}

.yellow {
background-color: #ffd40044;
border-radius: 0px;
Expand Down Expand Up @@ -627,6 +632,7 @@ th {
background-color: #0080ff;
color: #ffffff;
border-radius: 0px;
white-space: normal;
}

td {
Expand Down
33 changes: 30 additions & 3 deletions js/all-websites.js
Expand Up @@ -242,7 +242,7 @@ function hideBackgroundOpacity() {

/**
* Sort by column!
* @param column it can be "website", "category", "status", "since-install", "date-N" (where N is 0, 1, 2, ...)
* @param column it can be "website", "category", "status", "since-install", "avg-time", "date-N" (where N is 0, 1, 2, ...)
* @param websites the dictionary to sort
* @param generate_ui true -> it "generates" also the UI, false -> otherwise it changes only the variable
*/
Expand Down Expand Up @@ -316,7 +316,7 @@ function getWebsitesToUse(websites_json) {

new_website["website"] = current_website;
new_website["status"] = websites_json[current_website]["enabled"];
new_website["category"] = websites_json[current_website]["category"];
new_website["category"] = checkCategory(current_website);

//since install
let number_of_days = all_dates.length;
Expand All @@ -329,6 +329,9 @@ function getWebsitesToUse(websites_json) {
}
new_website["since-install"] = sum_since_install;

let avg_time = 0;
if (number_of_days > 0) avg_time = sum_since_install / number_of_days;
new_website["avg-time"] = parseInt(avg_time.toString());

//days
for (let date in last_seven_days) {
Expand Down Expand Up @@ -462,6 +465,17 @@ function getTHeadTable(websites, last_seven_days) {
websites = sortByColumn("since-install", websites);
}
tableRowElement.append(tableHeaderElement);

tableHeaderElement = document.createElement("th");
tableHeaderElement.textContent = "Average";
tableHeaderElement.id = "th-avg-time";
tableHeaderElement.classList.add("th-sort-by-column");
if (sorted_by === "avg-time-asc") tableHeaderElement.classList.add("th-sort-by-column-sel", "sort-by-column-asc");
if (sorted_by === "avg-time-desc") tableHeaderElement.classList.add("th-sort-by-column-sel", "sort-by-column-desc");
tableHeaderElement.onclick = function () {
websites = sortByColumn("avg-time", websites);
}
tableRowElement.append(tableHeaderElement);
for (let date in last_seven_days) {

let date_to_show = last_seven_days[date];
Expand Down Expand Up @@ -569,7 +583,7 @@ function getTBodyTable(websites, last_seven_days) {
//since install
let number_of_days = all_dates.length;

let sum_since_install = websites[website]["since-install"]
let sum_since_install = websites[website]["since-install"];
let since_install = getTimeConverted(sum_since_install);
tableDataElement = document.createElement("td");
tableDataElement.textContent = since_install;
Expand All @@ -583,6 +597,19 @@ function getTBodyTable(websites, last_seven_days) {
}
tableRowElement.append(tableDataElement);

let avg_time = websites[website]["avg-time"];
let avg_time_to_show = getTimeConverted(avg_time);
tableDataElement = document.createElement("td");
tableDataElement.textContent = avg_time_to_show;
tableDataElement.classList.add("avg-time");
if (avg_time >= (60 * 30) * number_of_days && avg_time < (60 * 60) * number_of_days) {
tableDataElement.classList.add("yellow");
} else if (avg_time >= (60 * 60) * number_of_days && avg_time < (60 * 60 * 3) * number_of_days) {
tableDataElement.classList.add("orange");
} else if (avg_time >= (60 * 60 * 3) * number_of_days) {
tableDataElement.classList.add("red");
}
tableRowElement.append(tableDataElement);

//days
for (let date in last_seven_days) {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Limite",
"version": "2.1.2",
"version": "2.2",
"author": "Saverio Morelli (Sav22999)",
"description": "Check how much time you spend on each website every day.\nOptimise your productivity, your time and your life as well.\nDon't lose precious time!",
"icons": {
Expand Down

0 comments on commit b6ecd16

Please sign in to comment.