Add random sorting

This commit is contained in:
evergreen 2026-01-18 12:32:35 -07:00
parent d925553810
commit f6e183dcbf
3 changed files with 27 additions and 9 deletions

View file

@ -487,6 +487,7 @@ if (1)
"gt_sz": "size",
"gt_ts": "date",
"gt_ext": "type",
"gt_rand": "random",
"gt_c1": "truncate filenames more (show less)",
"gt_c2": "truncate filenames less (show more)",
@ -3900,7 +3901,7 @@ var fileman = (function () {
'<table>',
'<tr><td colspan="2">',
'<button id="sh_abrt">' + L.fs_abrt + '</button>',
'<button id="sh_rand">' + L.fs_rand + '</button>',
'<button id="sh_rand"> ' + L.fs_rand + '</button>',
'<button id="sh_apply">' + L.fs_go + '</button>',
'</td></tr>',
'<tr><td>' + L.fs_name + '</td><td><input type="text" id="sh_k" ' + NOAC + ' placeholder=" ' + L.fs_pname + '" /></td></tr>',
@ -5378,6 +5379,7 @@ var thegrid = (function () {
'<a href="#" s="sz">' + L.gt_sz + '</a> ' +
'<a href="#" s="ts">' + L.gt_ts + '</a> ' +
'<a href="#" s="ext">' + L.gt_ext + '</a>' +
'<a href="#" s="rand">' + L.gt_rand + '</a>' +
'</span></div>' +
'<div id="ggrid"></div>'
);
@ -7952,7 +7954,8 @@ function mk_files_header(taglist) {
'<thead><tr>',
'<th name="lead"><span>c</span></th>',
'<th name="href"><span>File Name</span></th>',
'<th name="sz" sort="int"><span>Size</span></th>'
'<th name="sz" sort="int"><span>Size</span></th>',
'<th name="rand" sort="random"><span>Random</span></th>'
];
for (var a = 0; a < taglist.length; a++) {
var tag = taglist[a],

View file

@ -719,15 +719,30 @@ function sortTable(table, col, cb) {
vl.push([v, a]);
}
if (stype == 'int')
if (stype == 'random') {
// Fisher-Yates shuffle for true randomization
for (var i = vl.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = vl[i];
vl[i] = vl[j];
vl[j] = temp;
}
}
else if (stype == 'int') {
vl.sort(st_cmp_num);
else if (ENATSORT)
if (reverse < 0)
vl.reverse();
}
else if (ENATSORT) {
vl.sort(st_cmp_nat);
else
if (reverse < 0)
vl.reverse();
}
else {
vl.sort(st_cmp_gen);
if (reverse < 0)
vl.reverse();
if (reverse < 0)
vl.reverse();
}
if (sread('dir1st') !== '0') {
var r1 = [], r2 = [];

View file

@ -322,7 +322,7 @@ necho() {
exit 1
}
rm "$f1"
cp -p "$f2" "$f1"
cp -rp "$f2" "$f1"
); done
# resolve symlinks on windows