Discussions » Creation Requests
"Sort by size" button keeps repeating (MEGA.NZ)
This is for MEGA.NZ
Hi! I found this script that seems to work as intended, though when using it the "Sort by size" button keeps repeating itself over and over. Does anyone know of a fix for this?
"// ==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
// @downloadURL https://update.greasyfork.org/scripts/437430/Sort%20Meganz%20files%20by%20size.user.js
// @updateURL https://update.greasyfork.org/scripts/437430/Sort%20Meganz%20files%20by%20size.meta.js
// ==/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;
};
})();"
try
// ==UserScript==
// @name Sort Mega.nz files by size
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Add sort by size button on mega.nz
// @author JethaLal_420 (Modified by RenjiYuusei user)
// @match https://mega.nz/folder/*
// @icon https://www.google.com/s2/favicons?domain=mega.nz
// @grant none
// ==/UserScript==
(function () {
'use strict';
let listViewBtn, blockViewBtn, sortBtn;
const createBtn = () => {
let button = document.createElement("BUTTON");
button.innerHTML = "Sort By Size";
button.id = "sortbysize";
return button;
};
const sortBySize = () => {
listViewBtn.click();
let sizeBtn = document.querySelector('.size'); // Use querySelector for better performance
if (sizeBtn) { // Check if sizeBtn exists before clicking
setTimeout(() => {
sizeBtn.click();
sizeBtn.click(); // Click twice to ensure descending order
}, 500);
} else {
console.error("Size button not found.");
}
blockViewBtn.click();
};
const checkAndInsertBtn = () => {
listViewBtn = document.querySelector('.listing-view');
blockViewBtn = document.querySelector('.block-view');
if (listViewBtn && blockViewBtn && !sortBtn) { // Check if the button already exists
let parentNode = document.querySelector('.fm-breadcrumbs-wrapper');
let childNode = document.querySelector('.fm-breadcrumbs-block');
sortBtn = createBtn(); // Create the button only once
if (parentNode && childNode) { // Make sure parent and child nodes exist
parentNode.insertBefore(sortBtn, childNode);
sortBtn.onclick = sortBySize;
} else {
console.error("Parent or child node for button insertion not found.");
}
}
};
// Observe changes to the DOM to handle dynamic content loading
const observer = new MutationObserver(checkAndInsertBtn);
observer.observe(document.body, { childList: true, subtree: true });
// Initial check in case the elements are already loaded
checkAndInsertBtn();
})();
That works perfectly. Thank you sir! You should release that script onto the forums because you made it! It's really good.
That works perfectly. Thank you sir! You should release that script onto the forums because you made it! It's really good.
It's good that it works and is useful to you and I think there's no need to post this script on the forum
That works perfectly. Thank you sir! You should release that script onto the forums because you made it! It's really good.
It's good that it works and is useful to you and I think there's no need to post this script on the forum
That's ok. Thanks again, just wondering if you have time and the knowledge do you know how to add to this script? I was wondering if there could be another button like "Sort by Size" but it's called "Sort by Type" and it'll be beside the "Sort by Size" button? It can sort from videos, images, folders, executable or just whatever the file type is?
Thanks, Sara
This is for MEGA.NZ
Hi! I found this script that seems to work as intended, though when using it the "Sort by size" button keeps repeating itself over and over. Does anyone know of a fix for this?
"// ==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
// @downloadURL https://update.greasyfork.org/scripts/437430/Sort%20Meganz%20files%20by%20size.user.js
// @updateURL https://update.greasyfork.org/scripts/437430/Sort%20Meganz%20files%20by%20size.meta.js
// ==/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;
};
})();"try
// ==UserScript==
// @name Sort Mega.nz files by size
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Add sort by size button on mega.nz
// @author JethaLal_420 (Modified by RenjiYuusei user)
// @match https://mega.nz/folder/*
// @icon https://www.google.com/s2/favicons?domain=mega.nz
// @grant none
// ==/UserScript==
(function () {
'use strict';
let listViewBtn, blockViewBtn, sortBtn;
const createBtn = () => {
let button = document.createElement("BUTTON");
button.innerHTML = "Sort By Size";
button.id = "sortbysize";
return button;
};
const sortBySize = () => {
listViewBtn.click();
let sizeBtn = document.querySelector('.size'); // Use querySelector for better performance
if (sizeBtn) { // Check if sizeBtn exists before clicking
setTimeout(() => {
sizeBtn.click();
sizeBtn.click(); // Click twice to ensure descending order
}, 500);
} else {
console.error("Size button not found.");
}
blockViewBtn.click();
};
const checkAndInsertBtn = () => {
listViewBtn = document.querySelector('.listing-view');
blockViewBtn = document.querySelector('.block-view');
if (listViewBtn && blockViewBtn && !sortBtn) { // Check if the button already exists
let parentNode = document.querySelector('.fm-breadcrumbs-wrapper');
let childNode = document.querySelector('.fm-breadcrumbs-block');
sortBtn = createBtn(); // Create the button only once
if (parentNode && childNode) { // Make sure parent and child nodes exist
parentNode.insertBefore(sortBtn, childNode);
sortBtn.onclick = sortBySize;
} else {
console.error("Parent or child node for button insertion not found.");
}
}
};
// Observe changes to the DOM to handle dynamic content loading
const observer = new MutationObserver(checkAndInsertBtn);
observer.observe(document.body, { childList: true, subtree: true });
// Initial check in case the elements are already loaded
checkAndInsertBtn();
})();
That works perfectly. Thank you sir! You should release that script onto the forums because you made it! It's really good.
It's good that it works and is useful to you and I think there's no need to post this script on the forum
That's ok. Thanks again, just wondering if you have time and the knowledge do you know how to add to this script? I was wondering if there could be another button like "Sort by Size" but it's called "Sort by Type" and it'll be beside the "Sort by Size" button? It can sort from videos, images, folders, executable or just whatever the file type is?
Thanks, Sara
That works perfectly. Thank you sir! You should release that script onto the forums because you made it! It's really good.
It's good that it works and is useful to you and I think there's no need to post this script on the forum
That's ok. Thanks again, just wondering if you have time and the knowledge do you know how to add to this script? I was wondering if there could be another button like "Sort by Size" but it's called "Sort by Type" and it'll be beside the "Sort by Size" button? It can sort from videos, images, folders, executable or just whatever the file type is?
Thanks, Sara
try
// ==UserScript==
// @name Mega.nz File Sorter (Size & Type)
// @namespace http://tampermonkey.net/
// @version 0.5
// @description Adds sort by size and type buttons on mega.nz
// @author JethaLal_420 (Modified by RenjiYuusei user)
// @match https://mega.nz/folder/*
// @icon https://www.google.com/s2/favicons?domain=mega.nz
// @grant none
// ==/UserScript==
(function() {
'use strict';
let listViewBtn, blockViewBtn, sortBySizeBtn, sortByTypeBtn;
const createBtn = (text, id, onClick) => {
let button = document.createElement("BUTTON");
button.innerHTML = text;
button.id = id;
button.addEventListener('click', onClick); //Use addEventListener for better event handling
return button;
};
const sortBySize = () => {
listViewBtn.click();
let sizeBtn = document.querySelector('.size');
if (sizeBtn) {
setTimeout(() => {
sizeBtn.click();
sizeBtn.click(); // Click twice to ensure descending order
}, 500);
} else {
console.error("Size button not found.");
}
blockViewBtn.click();
};
const sortByType = () => {
listViewBtn.click();
let typeBtn = document.querySelector('.type'); // Assumes Mega has a 'type' class for sorting by type
if (typeBtn) {
setTimeout(() => {
typeBtn.click();
}, 500); //Added small delay for better reliability
} else {
console.error("Type button not found. Check Mega.nz's DOM structure for the type column.");
}
blockViewBtn.click();
};
const checkAndInsertBtns = () => {
listViewBtn = document.querySelector('.listing-view');
blockViewBtn = document.querySelector('.block-view');
if (listViewBtn && blockViewBtn && !sortBySizeBtn) {
let parentNode = document.querySelector('.fm-breadcrumbs-wrapper');
let childNode = document.querySelector('.fm-breadcrumbs-block');
sortBySizeBtn = createBtn("Sort By Size", "sortbysize", sortBySize);
sortByTypeBtn = createBtn("Sort By Type", "sortbytype", sortByType);
if (parentNode && childNode) {
parentNode.insertBefore(sortBySizeBtn, childNode);
parentNode.insertBefore(sortByTypeBtn, childNode); // Insert Sort By Type before Sort By Size
} else {
console.error("Parent or child node for button insertion not found.");
}
}
};
const observer = new MutationObserver(checkAndInsertBtns);
observer.observe(document.body, { childList: true, subtree: true });
checkAndInsertBtns();
})();
Perfect! You are amazing my friend! With your permission can I post this script here and I'll credit you?
Perfect! You are amazing my friend! With your permission can I post this script here and I'll credit you?
maybe.
This is for MEGA.NZ
Hi! I found this script that seems to work as intended, though when using it the "Sort by size" button keeps repeating itself over and over. Does anyone know of a fix for this?
"// ==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
// @downloadURL https://update.greasyfork.org/scripts/437430/Sort%20Meganz%20files%20by%20size.user.js
// @updateURL https://update.greasyfork.org/scripts/437430/Sort%20Meganz%20files%20by%20size.meta.js
// ==/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;
};
})();"