DEV Community

Cover image for Sort files Google Drive
David Lacarta
David Lacarta

Posted on

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)