Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save risyomei/cdd23e1b523b54062a1ac7eb87f7f0e4 to your computer and use it in GitHub Desktop.
Save risyomei/cdd23e1b523b54062a1ac7eb87f7f0e4 to your computer and use it in GitHub Desktop.
let timeBox = document.getElementsByClassName('c-timestamp');
let i = 0;
while(i < timeBox.length) {
    var date = new Date( timeBox[i].getAttribute('data-ts') * 1000);
    var dateFormate = date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate();
    dateFormate = dateFormate + '-' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();   
    var currentText = timeBox[i].getElementsByClassName('c-timestamp__label')[0].innerHTML;
    if (! currentText.includes(dateFormate)){
        timeBox[i].getElementsByClassName('c-timestamp__label')[0].innerHTML = currentText + ' (' + dateFormate + ')';
    }
    i = i + 1;
}
function myLoop() {
    setTimeout(function() {
        let timeBox = document.getElementsByClassName('c-timestamp');
        let i = 0;
        while(i < timeBox.length) {
            var date = new Date( timeBox[i].getAttribute('data-ts') * 1000);
            var dateFormate = date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate();
            dateFormate = dateFormate + '-' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
            
            var currentText = timeBox[i].getElementsByClassName('c-timestamp__label')[0].innerHTML;
        
            if (! currentText.includes(dateFormate)){
                timeBox[i].getElementsByClassName('c-timestamp__label')[0].innerHTML = currentText + ' (' + dateFormate + ')';
            }
            i = i + 1;
        }
      myLoop();
    }, 15000)
  }

(function() {
    myLoop();
})();
@robatron
Copy link

robatron commented Aug 1, 2023

This is exactly what I was looking for! Thank you, @risyomei!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment