Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QoL 2 - sort #1126

Open
rslgp opened this issue Mar 13, 2024 · 1 comment
Open

QoL 2 - sort #1126

rslgp opened this issue Mar 13, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@rslgp
Copy link
Contributor

rslgp commented Mar 13, 2024

i manage to sort the cards, by subscribers, with js
will be nice to be able to sort things

let enum_type = {
views: 1,
subscribers: 2,
favorites: 3,
}
const gridElement = document.querySelector("body > div > section > div > div.grid.grid-cols-1");
const sortTextSelector = `.card .my-2 .flex.justify-center:nth-child(1) h5:nth-child(${enum_type.subscribers})`;


function reorderCards(gridElement, sortTextSelector) {
  // 1. Get all cards as an array
  const cards = Array.from(gridElement.children);

  // 2. Extract sort text for each card
  const cardsWithText = cards.map(card => {
    let sortTextElement = card.querySelector(sortTextSelector);
      sortTextElement = sortTextElement.textContent.trim().replaceAll(",","")
    return {
      card: card,
      text: sortTextElement ? sortTextElement : "",
    };
  });

  // 3. Sort the cards based on the extracted text (assuming numeric sort)
  cardsWithText.sort((a, b) => {
    const numberA = parseFloat(a.text);
    const numberB = parseFloat(b.text);
    return numberB - numberA;
  });

  // 4. Update the grid element with the reordered cards
  gridElement.innerHTML = "";
  cardsWithText.forEach(cardObj => gridElement.appendChild(cardObj.card));
}

reorderCards(gridElement, sortTextSelector);


@thejaviertc thejaviertc added the enhancement New feature or request label Mar 16, 2024
@thejaviertc
Copy link
Owner

It will be done some day. Is a planned feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants