From f45bab7bd06bfa59678cb36b1d25e92ad56bfd46 Mon Sep 17 00:00:00 2001 From: Ahmed Elsherif <119296268+0xelsherif@users.noreply.github.com> Date: Wed, 3 Apr 2024 03:57:36 +0200 Subject: [PATCH] sort by date --- app.js | 46 ++++++++++++++++++++++------------------------ index.html | 2 +- test.html | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 test.html diff --git a/app.js b/app.js index cff8ddf..b232467 100644 --- a/app.js +++ b/app.js @@ -43,30 +43,7 @@ window.addEventListener("focus", () => { }, 5000); }); - -// document.addEventListener('DOMContentLoaded', function () { -// const toggleSwitch = document.querySelector('#themeToggle'); - -// // Check the current theme on load -// if (localStorage.getItem('theme') === 'dark') { -// document.body.classList.add('dark-mode'); -// toggleSwitch.checked = true; -// } else { -// document.body.classList.remove('dark-mode'); -// toggleSwitch.checked = false; -// } - -// // Switch theme dynamically -// toggleSwitch.addEventListener('change', function () { -// if (this.checked) { -// document.body.classList.add('dark-mode'); -// localStorage.setItem('theme', 'dark'); -// } else { -// document.body.classList.remove('dark-mode'); -// localStorage.setItem('theme', 'light'); -// } -// }); -// }); +// Dark mode document.addEventListener('DOMContentLoaded', function () { const toggleSwitch = document.querySelector('#themeToggle'); @@ -98,4 +75,25 @@ document.addEventListener('DOMContentLoaded', function () { toggleDarkMode(isDarkMode); localStorage.setItem('theme', isDarkMode ? 'dark' : 'light'); }); +}); + +// Sort by Date +// Get all card elements +const cards = document.querySelectorAll('.leftcolumn .card'); + +// Convert NodeList to Array +const cardsArray = Array.from(cards); + +// Sort cards based on the creation date +cardsArray.sort((a, b) => { + const dateA = new Date(a.querySelector('h5').textContent.replace('Created on, ', '')); + const dateB = new Date(b.querySelector('h5').textContent.replace('Created on, ', '')); + return dateB - dateA; +}); + +// Re-append sorted cards to the leftcolumn +const leftColumn = document.querySelector('.leftcolumn'); +leftColumn.innerHTML = ''; // Clear previous content +cardsArray.forEach(card => { + leftColumn.appendChild(card); }); \ No newline at end of file diff --git a/index.html b/index.html index 3c6c2b9..7523692 100644 --- a/index.html +++ b/index.html @@ -104,7 +104,7 @@
Created on, MARCH 27, 2024

URL QR Code Generator

-
Created on, MARCH 27, 2024
+
Created on, MARCH 30, 2024

See the Pen Time-based Greeting by Ahmed Hamza El-Sherif (@0xelsherif) diff --git a/test.html b/test.html new file mode 100644 index 0000000..8826c11 --- /dev/null +++ b/test.html @@ -0,0 +1,42 @@ + + + + + + Clarity API Data + + + +

Clarity API Data

+ +
+

Loading...

+
+ + + + +