Gradient color script added to goal difference column

This commit is contained in:
Lucas Patenaude
2024-04-14 17:37:28 -06:00
parent e4b44e05e3
commit f60bbe00a6
3 changed files with 25 additions and 12 deletions

View File

@@ -1,14 +1,29 @@
// script.js
document.addEventListener("DOMContentLoaded", function() {
var goalDifferenceCells = document.querySelectorAll("#standings-table tbody td:nth-child(8)"); // Selecting the cells in the goal_difference column
var goalDifferenceCells = document.querySelectorAll("#goal-difference-column"); // Selecting the cells in the goal_difference column
goalDifferenceCells.forEach(function(cell) {
var goalDifference = parseInt(cell.textContent);
var color;
if (goalDifference < 0) {
cell.style.color = "red"; // Change text color to red for negative goal difference
} else if (goalDifference > 0) {
cell.style.color = "green"; // Change text color to green for positive goal difference
} // If goal difference is 0, leave text color unchanged
if (goalDifference < 0)
{
// Gradually darken the text color for negative goal differences
var darkenFactor = Math.ceil(goalDifference / -10); // Calculate the darken factor
var shade = Math.max(0, 255 - darkenFactor * 25); // Calculate the shade of red
color = "rgb(" + shade + ", 0, 0)"; // Create the color value
}
else if (goalDifference > 0)
{
// Gradually darken the text color for positive goal differences
var darkenFactor = Math.floor(goalDifference / 10); // Calculate the darken factor
var shade = Math.max(0, 155 - darkenFactor * 15); // Adjusted the starting point to make greens darker
color = "rgb(0, " + shade + ", 0)"; // Create the color value
}
else
{
color = "inherit"; // If goal difference is 0, leave text color unchanged
}
cell.style.color = color; // Apply the calculated color
});
});