Sort directories before files

Sort directories before files in repository tree view

You will need to install an extension such as Tampermonkey, Greasemonkey 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 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.

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

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

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name        Sort directories before files
// @description Sort directories before files in repository tree view
// @author      anhkhoakz
// @version     1.0.3
// @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==

(()=>{"use strict";const e=document.querySelector(".tree-list");if(!e)return;const t=e.querySelectorAll(".name");if(t.length===0)return;const n=Array.from(e.children),s=t.length,o=n.length/s;if(o*s!==n.length)return;const i=[];for(let e=0;e<s;e++){const a=t[e],r=a.classList.contains("tree");i.push({rowIndex:e,isDir:r,cells:n.slice(e*o,(e+1)*o)})}i.sort((e,t)=>e.isDir!==t.isDir?e.isDir?-1:1:e.rowIndex-t.rowIndex);const a=document.createDocumentFragment();for(const{cells:e}of i)for(const t of e)a.appendChild(t);e.appendChild(a)})();