DEV Community

Cover image for Sort files Google Drive
David Lacarta
David Lacarta

Posted on

5 1

Sort files Google Drive

Simple script to sort the google drive files by size

[...document.getElementsByClassName("a-t-J a-Wa-ka l-oi-cc l-t-Q a-t-J-yl")]
  .map(element => {
    const [
      size,
      unit
    ] = element.childNodes[3].childNodes[0].childNodes[1].childNodes[0].innerText.split(
      " "
    );
    const SIZES_KB = { MB: 1024, GB: 1048576, KB: 1 };
    return {
      size: Number(size) * SIZES_KB[unit],
      node: element
    };
  })
  .sort((elementA, elementB) => elementB.size - elementA.size)
  .forEach(element => {
    const files = document.getElementsByClassName("a-t-J-Rf")[0];
    files.appendChild(element.node);
  });
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay