Skip to content

Instantly share code, notes, and snippets.

@davidkayce
Created July 13, 2021 14:29
Show Gist options
  • Save davidkayce/f8ef6b454126608225acc7177dc855ff to your computer and use it in GitHub Desktop.
Save davidkayce/f8ef6b454126608225acc7177dc855ff to your computer and use it in GitHub Desktop.
// This script progressively reduces the opacity of a site depending on a set number of days
// handly when you do a project and they refuse to pay you
(function () {
const dueDate = new Date('2020-02-12'); // Put in date of submission to client
const payDeadline = 30; // number of days as deadline for payment
const currentDate = new Date();
let utc1 = Date.UTC(dueDate.getFullYear(), dueDate.getMonth(), dueDate.getDate());
let utc2 = Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
const days = Math.floor((utc2 - utc1) / (1000 * 60 * 60 * 24));
if (days > 0) {
const daysLate = payDeadline - days;
let opacity = (daysLate * 100 / payDeadline) / 100;
opacity = (opacity < 0) ? 0 : opacity;
opacity = (opacity > 1) ? 1 : opacity;
if (opacity >= 0 && opacity <= 1) {
document.getElementsByTagName('BODY')[0].style.opacity = opacity;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment