Sort directories before files

Sort directories before files in repository tree view

Version vom 01.05.2025. Aktuellste Version

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 or Violentmonkey 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 directories before files
// @description Sort directories before files in repository tree view
// @author      anhkhoakz
// @version     1.0.2
// @match       *://git.sr.ht/*/tree
// @match       *://git.sr.ht/*/tree/*
// @namespace   anhkhoakz
// @icon        https://git.sr.ht/static/logo.png
// @license     GPL-3.0; https://www.gnu.org/licenses/gpl-3.0.html#license-text
// ==/UserScript==

(function(){"use strict";var e=document.querySelector(".tree-list");if(!e)return;var t=[],a=[],n=e.querySelectorAll(".name");for(var e1=0;e1<n.length;e1++){var s=n[e1];s.classList.contains("tree")?t.push(e1):s.classList.contains("blob")&&a.push(e1)}var o=e.children.length,i=n.length,s1=o/i;if(s1*i!==o)return;var r=Array.from(e.children).sort(function(n,o){var i=Array.prototype.indexOf.call(e.children,n),a=Array.prototype.indexOf.call(e.children,o),c=i/s1|0,l=a/s1|0,r=t.indexOf(c)!==-1,d=t.indexOf(l)!==-1;return r!==d?r?-1:1:i-a});var _iteratorNormalCompletion=true,_didIteratorError=false,_iteratorError=undefined;try{for(var _iterator=r[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var t1=_step.value;e.appendChild(t1)}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return!=null){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}})();