@DownPW I’ve done something similar here on Sudonix, but using the welcome message at the top of the screen. It’s been modified to include an icon from FA based on the time of day. Here’s the code
$(window).on('action:ajaxify.end', function (data) {
function updateUsername() {
$('.getUsername .username').text(app.user.username);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', updateUsername);
} else {
updateUsername();
}
var thehours = new Date().getHours();
var themessage;
var morning = ('Good morning');
var afternoon = ('Good afternoon');
var evening = ('Good evening');
var matched = false;
if (thehours >= 0 && thehours < 12) {
themessage = morning;
theicon = "fa-solid fa-sunrise";
} else if (thehours >= 12 && thehours < 17) {
themessage = afternoon;
theicon = "fa-solid fa-sun";
} else if (thehours >= 17 && thehours < 24) {
themessage = evening;
theicon = "fa-solid fa-moon";
}
if (window.location.href.indexOf("topic") > -1) {
console.log("This is a topic, so hide the user welcome message");
$('#thisuser').hide();
}
else {
$('.getUsername').prepend("<i id='thisicon' class='" + theicon + "'></i>" + themessage);
}
});
You’ll also need this CSS block
i#thisicon {
font-family: "Font Awesome 5 Free";
font-style: normal;
margin-right: 10px;
}
The icon being delivered is defined here
$('.getUsername').prepend("<i id='thisicon' class='" + theicon + "'></i>" + themessage);
So, theicon
is the FA class, and themessage
is the text you want to deliver.
We use prepend
to add this before the remainder of the class target of .getUsername
. The overall result is this
It’s also possible to “fake” the current time by placing thehours
just after var matched = false;
, so if you add thehours = 6
then this will be 6am, and so on. By overriding this, you won’t have to wait until the system clock changes to see if your code actually works or not
Using the example code above, you should be able to finish your own - let me know if you need any help.