Skip to content

Instantly share code, notes, and snippets.

@capjamesg
Created February 12, 2024 22:22
Show Gist options
  • Save capjamesg/ad99e628a7cab32855bd4c1ae641b01b to your computer and use it in GitHub Desktop.
Save capjamesg/ad99e628a7cab32855bd4c1ae641b01b to your computer and use it in GitHub Desktop.
// This script replaces all .seasonal_emoji elements with a specified emoji
// connected to the current date.
var seasonalEmoji = document.querySelectorAll('.seasonal_emoji');
var seasonalEmojiDict = {
'12-25': 'πŸŽ„',
'1-1': 'πŸŽ‰',
'2-14': 'πŸ’˜',
'2-9': '🏈', // Super Bowl 2025
'10-31': 'πŸŽƒ',
'11-5': 'πŸŽ‡',
'12-24': 'πŸŽ„',
'12-31': 'πŸŽ‰',
'12-26': 'πŸ“¦',
'10-1': 'πŸŽ‚',
'3-14': 'πŸ₯§',
'2-2': 'πŸƒ',
'11-30': '🏴󠁧󠁒󠁳󠁣󠁴󠁿',
'12-23': '|', // Festivus
'9-15': "πŸ›οΈ", // International Day of Democracy
'12-10': '🧍', // Human Rights Day
'5-12': '🍡', // International Tea Day
'11-30': '🧒' // Blue Beanie Day (web standards celebration. I couldn't find a blue beanie emoji; the cap was the closest I could find.)
};
var timeRanges = [['8-8', '8-18', '🌽']];
var today = new Date();
var month = today.getMonth() + 1;
var day = today.getDate();
var todayFormatted = month + '-' + day;
var monthLongSeasonalEmojis = {
"12": "❄️",
"10": "πŸŽƒ"
}
if (monthLongSeasonalEmojis[month.toString()]) {
for (var i = 0; i < seasonalEmoji.length; i++) {
seasonalEmoji[i].innerHTML = monthLongSeasonalEmojis[month.toString()];
}
} else if (timeRanges) {
for (var i = 0; i < timeRanges.length; i++) {
var timeRange = timeRanges[i];
if (timeRange[0] <= todayFormatted && todayFormatted <= timeRange[1]) {
for (var j = 0; j < seasonalEmoji.length; j++) {
seasonalEmoji[j].innerHTML = timeRange[2];
}
}
}
} else {
for (var i = 0; i < seasonalEmoji.length; i++) {
var emoji = seasonalEmojiDict[todayFormatted];
if (emoji) {
seasonalEmoji[i].innerHTML = emoji;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment