From 747f876e2f50520d7e09a0cb3018137eb4044c0d Mon Sep 17 00:00:00 2001 From: xscreach Date: Sat, 29 Jul 2023 01:07:03 +0200 Subject: [PATCH] Alphabetical sorting of all plugin links under the portal details panel --- core/code/boot.js | 25 +++++++++++++++++++++++++ core/code/utils_misc.js | 19 +++++++++++++++++++ core/total-conversion-build.js | 1 + 3 files changed, 45 insertions(+) diff --git a/core/code/boot.js b/core/code/boot.js index 8c4cd23ac..c3c03b173 100644 --- a/core/code/boot.js +++ b/core/code/boot.js @@ -205,6 +205,29 @@ function prepPluginsToLoad () { }; } +function setupToolboxSort() { + var toolboxElement = $('#toolbox')[0]; + + function sortToolbox() { + var children = Array.prototype.slice.call(toolboxElement.children); + var sortedChildren = children.slice().sort(function (x, y) { + return x.innerText.localeCompare(y.innerText); + }); + if ( + sortedChildren.some(function (item, index) { + return item !== children[index]; + }) + ) { + sortedChildren.forEach(function (child) { + toolboxElement.removeChild(child); + toolboxElement.appendChild(child); + }); + } + } + sortToolbox(); + window.observeDOMChildren(toolboxElement, sortToolbox); +} + function boot() { log.log('loading done, booting. Built: '+'@build_date@'); if (window.deviceID) { @@ -244,6 +267,8 @@ function boot() { window.iitcLoaded = true; window.runHooks('iitcLoaded'); + + setupToolboxSort(); } try { diff --git a/core/code/utils_misc.js b/core/code/utils_misc.js index 532bf262e..770365b0a 100644 --- a/core/code/utils_misc.js +++ b/core/code/utils_misc.js @@ -427,3 +427,22 @@ if (!Element.prototype.closest) { return null; }; } + +var MutObserver = window.MutationObserver || window.WebKitMutationObserver; +window.observeDOMChildren = function (obj, callback) { + if (!obj || obj.nodeType !== 1) return; + + if (MutObserver) { + // define a new observer + var mutationObserver = new MutObserver(callback); + + // have the observer observe for changes in children + mutationObserver.observe(obj, { childList: true, subtree: true }); + return mutationObserver; + } + + // browser support fallback + else if (window.addEventListener) { + obj.addEventListener('DOMNodeInserted', callback, false); + } +}; diff --git a/core/total-conversion-build.js b/core/total-conversion-build.js index a9e6ed9fb..cbd6f2b5b 100644 --- a/core/total-conversion-build.js +++ b/core/total-conversion-build.js @@ -14,6 +14,7 @@ window.script_info.changelog = [ 'Improved info panel styling', 'Timestamp added to link and field data', 'Added scanner link to info panel', + 'Sorted sidebar links', ], }, ];