Sort Mega.nz files by size

Add sortbysize button on mega.nz

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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;
  };
})();