Sort Mega.nz files by size

Add sortbysize button on mega.nz

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Sort Mega.nz files by size
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Add sortbysize button on mega.nz
// @author       JethaLal_420
// @match        https://mega.nz/folder/*
// @icon         https://www.google.com/s2/favicons?domain=mega.nz
// @grant        none
// ==/UserScript==

(function () {
  "use strict";
  var listViewBtn, blockViewBtn;

  const createBtn = (btnName) => {
    var button = document.createElement("BUTTON");
    button.innerHTML = btnName;
    button.id = "sortbysize";
    return button;
  };

  const checkDataLoaded = () => {
    listViewBtn = document.getElementsByClassName("listing-view")[0];
    blockViewBtn = document.getElementsByClassName("block-view")[0];
  };

  const sortBySize = () => {
    listViewBtn.click();
    console.log("List View btn Clicked");
    var sizeBtn = document.getElementsByClassName("size")[0];
    setTimeout(() => {
      sizeBtn.click();
      sizeBtn.click();
    }, 500);
    blockViewBtn.click();
    console.log("Block View btn Clicked");
  };

  let intervalId = setInterval(() => {
    checkDataLoaded();

    if (listViewBtn && blockViewBtn) {
      insertBtn();
    }
  }, 1000);

  const insertBtn = () => {
    clearInterval(intervalId);

    var parentNode = document.getElementsByClassName(
      "fm-breadcrumbs-wrapper"
    )[0];
    var childNode = document.getElementsByClassName("fm-breadcrumbs-block")[0];
    var btn = createBtn("Sort_By_Size");
    parentNode.insertBefore(btn, childNode);

    btn.onclick = sortBySize;
  };
})();