Sort directories before files

Sort directories before files in repository tree view

Από την 18/04/2025. Δείτε την τελευταία έκδοση.

Δημιουργός
anhkhoakz
Βαθμολογίες
0 0 0
Έκδοση
1.0.1
Δημιουργήθηκε την
09/04/2025
Ενημερώθηκε την
18/04/2025
Μέγεθος
952 Bytes
Άδεια
GPL-3.0
Εφαρμόζεται σε

Sort Directories Before Files

A user script designed to sort directories before files in the repository tree view on git.sr.ht.

Features

  • Sorting Logic: Prioritizes directories over files in the tree list display.
  • Compatibility: Specifically designed for git.sr.ht's tree view.

Usage

Once installed, the script will automatically sort directories before files whenever you're viewing the tree on git.sr.ht.

Code Overview

The script uses the following logic to sort the tree list:

  1. Identify Tree List:

    const tree_list = document.querySelector(".tree-list");
    
  2. Classify Nodes:

    • Iterates over elements with class .name to categorize them into directories (trees) and files (blobs).
  3. Sorting Mechanism:

    • Uses the indices of trees and blobs to sort the children of tree_list with directories prioritized.
  4. Reordering:

    • Re-appends sorted children to tree_list.

License

This script is released under the GPL-3.0 License.