Sort Mega.nz files by size

Add sortbysize button on mega.nz

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

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