Skip to content

Instantly share code, notes, and snippets.

@edjw
Last active August 25, 2023 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edjw/353548e9c0d810fe6aebf6a100c06ad9 to your computer and use it in GitHub Desktop.
Save edjw/353548e9c0d810fe6aebf6a100c06ad9 to your computer and use it in GitHub Desktop.
ist-js-gist
console.log("hello from a github gist");
const title = document.querySelector(`h1#page-title`);
// Function to get the current time in HH:MM:SS format
function getCurrentTime() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
}
// Function to update the title
function updateTime() {
const originalTitle = title.textContent.split(' - ')[0]; // Assumes original title doesn't have ' - ' in it. If not, you might want to store the original title outside of this function.
const currentTime = getCurrentTime();
title.textContent = `${originalTitle} - ${currentTime}`;
}
// Call updateTime initially to set the time immediately
updateTime();
// Then set an interval to update it every second
setInterval(updateTime, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment