Skip to content

Instantly share code, notes, and snippets.

@rmdes
Created March 19, 2025 20:34
Show Gist options
  • Save rmdes/a3f07810523a33184a4f25897b872cab to your computer and use it in GitHub Desktop.
Save rmdes/a3f07810523a33184a4f25897b872cab to your computer and use it in GitHub Desktop.
Countdown Trump
// JavaScript code for N8N to calculate and post daily countdowns with a graphical loading bar
// Define the reference start date (Trump's 2025 inauguration)
const startOfMandate = new Date('2025-01-20T00:00:00Z');
// Define the target dates
const midtermsDate = new Date('2026-11-03T00:00:00Z'); // Next USA Midterms
const presidentialElectionDate = new Date('2028-11-07T00:00:00Z'); // Next Presidential Election
const inaugurationDate = new Date('2029-01-20T00:00:00Z'); // Next Inauguration Day
// Get the current date
const currentDate = new Date();
// Function to calculate correct progress
function calculateProgress(targetDate) {
const totalDays = Math.ceil((targetDate - startOfMandate) / (1000 * 60 * 60 * 24));
const elapsedDays = Math.ceil((currentDate - startOfMandate) / (1000 * 60 * 60 * 24));
return Math.min(100, Math.max(0, Math.floor((elapsedDays / totalDays) * 100)));
}
// Calculate days remaining
const daysUntilMidterms = Math.ceil((midtermsDate - currentDate) / (1000 * 60 * 60 * 24));
const daysUntilPresidentialElection = Math.ceil((presidentialElectionDate - currentDate) / (1000 * 60 * 60 * 24));
const daysUntilInauguration = Math.ceil((inaugurationDate - currentDate) / (1000 * 60 * 60 * 24));
// Calculate accurate progress percentages
const midtermsProgress = calculateProgress(midtermsDate);
const presidentialProgress = calculateProgress(presidentialElectionDate);
const inaugurationProgress = calculateProgress(inaugurationDate);
// Create a graphical loading bar function
function createLoadingBar(percentage) {
const totalBars = 10; // Length of the loading bar
const filledBars = Math.floor((percentage / 100) * totalBars);
const emptyBars = totalBars - filledBars;
return `${'█'.repeat(filledBars)}${'▒'.repeat(emptyBars)} ${percentage}%`;
}
// Generate the loading bars
const midtermsLoadingBar = createLoadingBar(midtermsProgress);
const presidentialLoadingBar = createLoadingBar(presidentialProgress);
const inaugurationLoadingBar = createLoadingBar(inaugurationProgress);
// Generate the message
const message = `There are ${daysUntilMidterms} days until the Midterms, ${daysUntilPresidentialElection} days until the next Presidential Election, and ${daysUntilInauguration} days until the next Inauguration Day.\n\n` +
`Midterms Progress: \n${midtermsLoadingBar}\n\n` +
`Presidential Election Progress: \n${presidentialLoadingBar}\n\n` +
`Inauguration Progress: \n${inaugurationLoadingBar}`;
// Output the message
return [{
json: {
message,
},
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment