From 8770cc2911458be34eba3a2cf97c0cb0b20b1af9 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 10 Apr 2026 18:33:04 +0000 Subject: [PATCH] Update browser.js --- copyparty/web/browser.js | 72 ++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 69b1ab76..0cf7b4bd 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -155,7 +155,6 @@ if (1) "wt_m3ua": "add to m3u playlist (click 📻copy later)", "wt_m3uc": "copy m3u playlist to clipboard", "wt_grid": "toggle grid / list view$NHotkey: G", - "wt_gridauto": "toggle auto-grid mode", "wt_prev": "previous track$NHotkey: J", "wt_play": "play / pause$NHotkey: P", "wt_next": "next track$NHotkey: L", @@ -229,10 +228,9 @@ if (1) "cl_hpick": "tap on column headers to hide in the table below", "cl_hcancel": "column hiding aborted", "cl_rcm": "right-click menu", - "cl_gridauto": "autogrid", + "cl_gauto": "autogrid", "ct_grid": '田 the grid', - "ct_gridauto": 'autogrid', "ct_ttips": '◔ ◡ ◔">ℹ️ tooltips', "ct_thumb": 'in grid-view, toggle icons or thumbnails$NHotkey: T">🖼️ thumbs', "ct_csel": 'use CTRL and SHIFT for file selection in grid-view">sel', @@ -285,8 +283,8 @@ if (1) "tt_dynt": "autogrow as tree expands", "tt_wrap": "word wrap", "tt_hover": "reveal overflowing lines on hover$N( breaks scrolling unless mouse $N  cursor is in the left gutter )", - "tt_gathresh": "percentage of files required to trigger autogrid", - "tt_gaext": "comma-separated file extensions to consider for autogrid", + "tt_gauto": "display as grid or list depending on folder contents", + "tt_gathr": "use grid if this percentage of files are pics/vids", "ml_pmode": "at end of folder...", "ml_btns": "cmds", @@ -941,11 +939,10 @@ ebi('op_cfg').innerHTML = ( ' \n' + '\n' + '
\n' + - '

' + L.cl_gridauto + '

\n' + + '

' + L.cl_gauto + '

\n' + '
\n' + - ' ' + L.ct_gridauto + '\n' + - ' ' + - ' ' + + ' ' + L.enable + '\n' + + ' ' + '
\n' + '
\n' + '
\n' + @@ -5570,6 +5567,16 @@ var thegrid = (function () { r.setvis(); }; + r.autogrid = function (res) { + var ni = 0; + var nf = res.files.length; + for (var a = 0; a < nf; a++) + if (img_re.test('.' + res.files[a].ext)) + ni++; + if (nf) + thegrid.en = 100 * ni / nf >= r.gathr; + }; + function setln(v) { if (v) { r.ln += v; @@ -5957,10 +5964,17 @@ var thegrid = (function () { pbar.onresize(); vbar.onresize(); }); - bcfg_bind(r, 'gaen', 'gridauto', false, function(v) { - if (!jread("griden", false) && thegrid.en) - thegrid.en = false; + bcfg_bind(r, 'gaen', 'gauto', false, function(v) { + if (r.en && sread("griden") != 1) { + r.en = false; + r.setvis(true); + } }); + ebi('ga_thresh').value = r.gathr = icfg_get('ga_thresh', 70); + ebi('ga_thresh').oninput = function (e) { + var n = parseInt(this.value); + swrite('ga_thresh', r.gathr = (isNum(n) ? n : 0) || 70); + }; ebi('wtgrid').onclick = ebi('griden').onclick; return r; @@ -6893,16 +6907,6 @@ var treectl = (function () { var n = parseInt(this.value); swrite('bd_lim', r.lim = (isNum(n) ? n : 0) || 1000); }; - ebi('ga_thresh').value = r.gathresh = icfg_get('ga_thresh', 70); - ebi('ga_thresh').oninput = function (e) { - var n = parseInt(this.value); - swrite('ga_thresh', r.gathresh = (isNum(n) ? n : 0) || 70); - }; - ebi('ga_ext').value = r.gaext = scfg_get('ga_ext', 'jpg,jpeg,png,gif,webp,webm,mp4'); - ebi('ga_ext').oninput = function (e) { - var v = this.value; - swrite('ga_ext', r.gaext = v); - }; r.nvis = r.lim; ldks = jread('dks', []); @@ -7683,8 +7687,8 @@ var treectl = (function () { } } - if (jread('gridauto', false) && !jread('griden', false)) - autogrid(res); + if (thegrid.gaen && sread('griden') != 1) + thegrid.autogrid(res); if (url) setTimeout(asdf, 1); else asdf(); } @@ -7850,26 +7854,6 @@ var treectl = (function () { onresize(); } - function autogrid(res) { - var icount = 0; - var fcount = res.files.length; - var iext = new Set((sread('ga_ext') || "jpg,jpeg,png,gif,webp,webm,mp4").split(',')); - - for (var a = 0; a < fcount; a++) { - var fext = res.files[a].ext ? res.files[a].ext.toLowerCase() : ''; - if (fext && iext.has(fext)) - icount++; - } - - var iratio = fcount > 0 ? (icount / fcount) * 100 : 0; - var threshold = sread('ga_thresh') || 70; - - if (iratio >= threshold) - thegrid.en = true; - else - thegrid.en = false; - } - ebi('entree').onclick = r.entree; ebi('detree').onclick = r.detree; ebi('visdir').onclick = tree_scrollto;