Guest User

Untitled

a guest
Sep 1st, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. document.addEventListener("DOMContentLoaded", function() {
  2. // Create an object to keep track of datetime occurrences
  3. const datetimeOccurrences = {};
  4.  
  5. // Select all elements with the class 'entry-date'
  6. const timeElements = document.querySelectorAll('.entry-date');
  7.  
  8. // Loop through each element and count occurrences of each datetime
  9. timeElements.forEach(function(element) {
  10. const datetime = element.getAttribute('datetime');
  11. datetimeOccurrences[datetime] = (datetimeOccurrences[datetime] || 0) + 1;
  12. });
  13.  
  14. // Reset the occurrence count to use for tracking while hiding
  15. const datetimeTrack = {};
  16.  
  17. // Loop through again to set display style based on occurrences
  18. timeElements.forEach(function(element) {
  19. const datetime = element.getAttribute('datetime');
  20. datetimeTrack[datetime] = (datetimeTrack[datetime] || 0) + 1;
  21.  
  22. if (datetimeOccurrences[datetime] > 1 && datetimeTrack[datetime] > 1) {
  23. element.style.display = 'none';
  24. }
  25. });
  26. });
  27.  
Advertisement
Add Comment
Please, Sign In to add comment