From 98da5cc509c5288feacad81d3d973064a476438e Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 17 Oct 2025 16:29:55 +0000 Subject: [PATCH] ui-elements can be hidden (#928) --- README.md | 7 ++++++- copyparty/__main__.py | 9 +++++++++ copyparty/authsrv.py | 4 ++++ copyparty/cfg.py | 18 ++++++++++++++++++ copyparty/web/browser.js | 28 ++++++++++++++++++++++++---- docs/rice/README.md | 21 +++++++++++++++++++++ tests/util.py | 2 +- 7 files changed, 83 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 63c7b903..d9b4b4bd 100644 --- a/README.md +++ b/README.md @@ -1496,7 +1496,12 @@ tweaking the ui * to sort in music order (album, track, artist, title) with filename as fallback, you could `--sort tags/Circle,tags/.tn,tags/Artist,tags/Title,href` * to sort by upload date, first enable showing the upload date in the listing with `-e2d -mte +.up_at` and then `--sort tags/.up_at` -see [./docs/rice](./docs/rice) for more, including how to add stuff (css/``/...) to the html `` tag, or to add your own translation +see [./docs/rice](./docs/rice) for more, including: +* how to [hide ui-elements](./docs/rice/README.md#hide-ui-elements) +* [custom fonts](./docs/rice/README.md#custom-fonts) +* [custom loading-spinner](./docs/rice/README.md#boring-loader-spinner) +* adding stuff (css/``/...) [to the html `` tag](./docs/rice/README.md#head) +* [adding your own translation](./docs/rice/README.md#translations) ## opengraph diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 48f4dea0..907a8904 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1821,6 +1821,15 @@ def add_ui(ap, retry: int): ap2.add_argument("--lg-sba", metavar="TXT", type=u, default="", help="the value of the iframe 'allow' attribute for prologue/epilogue docs (volflag=lg_sba); see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy#iframes") ap2.add_argument("--no-sb-md", action="store_true", help="don't sandbox README/PREADME.md documents (volflags: no_sb_md | sb_md)") ap2.add_argument("--no-sb-lg", action="store_true", help="don't sandbox prologue/epilogue docs (volflags: no_sb_lg | sb_lg); enables non-js support") + ap2.add_argument("--ui-nombar", action="store_true", help="hide top-menu in the UI (volflag=ui_nombar)") + ap2.add_argument("--ui-noacci", action="store_true", help="hide account-info in the UI (volflag=ui_noacci)") + ap2.add_argument("--ui-nosrvi", action="store_true", help="hide server-info in the UI (volflag=ui_nosrvi)") + ap2.add_argument("--ui-nonav", action="store_true", help="hide navpane+breadcrumbs (volflag=ui_nonav)") + ap2.add_argument("--ui-notree", action="store_true", help="hide navpane in the UI (volflag=ui_nonav)") + ap2.add_argument("--ui-nocpla", action="store_true", help="hide cpanel-link in the UI (volflag=ui_nocpla)") + ap2.add_argument("--ui-nolbar", action="store_true", help="hide link-bar in the UI (volflag=ui_nolbar)") + ap2.add_argument("--ui-noctxb", action="store_true", help="hide context-buttons in the UI (volflag=ui_noctxb)") + ap2.add_argument("--ui-norepl", action="store_true", help="hide repl-button in the UI (volflag=ui_norepl)") ap2.add_argument("--have-unlistc", action="store_true", help=argparse.SUPPRESS) diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 117b4308..2ac3cd09 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -3075,6 +3075,10 @@ class AuthSrv(object): "lifetime": vn.js_ls["lifetime"], "u2sort": self.args.u2sort, } + zs = "ui_noacci ui_nocpla ui_noctxb ui_nolbar ui_nombar ui_nonav ui_notree ui_norepl ui_nosrvi" + for zs in zs.split(): + if vf.get(zs): + js_htm[zs] = 1 vn.js_htm = json_hesc(json.dumps(js_htm)) vols = list(vfs.all_nodes.values()) diff --git a/copyparty/cfg.py b/copyparty/cfg.py index 0c50bcb0..3c4ab467 100644 --- a/copyparty/cfg.py +++ b/copyparty/cfg.py @@ -59,6 +59,15 @@ def vf_bmap() -> dict[str, str]: "rm_partial", "rmagic", "rss", + "ui_noacci", + "ui_nocpla", + "ui_nolbar", + "ui_nombar", + "ui_nonav", + "ui_notree", + "ui_norepl", + "ui_nosrvi", + "ui_noctxb", "wo_up_readme", "wram", "xdev", @@ -327,6 +336,15 @@ flagcats = { "md_sba": "value of iframe allow-prop for markdown-sandbox", "lg_sba": "value of iframe allow-prop for *logue-sandbox", "nohtml": "return html and markdown as text/html", + "ui_noacci": "hide account-info in the UI", + "ui_nocpla": "hide cpanel-link in the UI", + "ui_nolbar": "hide link-bar in the UI", + "ui_nombar": "hide top-menu in the UI", + "ui_nonav": "hide navpane+breadcrumbs in the UI", + "ui_notree": "hide navpane in the UI", + "ui_norepl": "hide repl-button in the UI", + "ui_nosrvi": "hide server-info in the UI", + "ui_noctxb": "hide context-buttons in the UI", }, "opengraph (discord embeds)": { "og": "enable OG (disables hotlinking)", diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 413f16a6..c173d528 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -1118,6 +1118,9 @@ var ACtx = !IPHONE && (window.AudioContext || window.webkitAudioContext), hash0 = location.hash, sloc0 = '' + location, noih = /[?&]v\b/.exec(sloc0), + fullui = /[?&]fullui\b/.exec(sloc0), + nonav = !fullui && (/[?&]nonav\b/.exec(sloc0) || window.ui_nonav), + notree = !fullui && (/[?&]notree\b/.exec(sloc0) || window.ui_notree || nonav), dbg_kbd = /[?&]dbgkbd\b/.exec(sloc0), abrt_key = "", can_shr = false, @@ -6660,7 +6663,7 @@ var treectl = (function () { r.show = function () { r.hidden = false; if (!entreed) { - ebi('path').style.display = 'inline-block'; + ebi('path').style.display = nonav ? 'none' : 'inline-block'; return; } @@ -6678,8 +6681,9 @@ var treectl = (function () { swrite('entreed', 'na'); r.hide(); - ebi('path').style.display = ''; - } + if (!nonav) + ebi('path').style.display = ''; + }; r.hide = function () { r.hidden = true; @@ -6689,7 +6693,7 @@ var treectl = (function () { window.removeEventListener('resize', onresize); window.removeEventListener('scroll', onscroll); aligngriditems(); - } + }; function unmenter() { if (mentered) { @@ -7554,6 +7558,11 @@ var treectl = (function () { var cs = sread('entreed'), vw = window.innerWidth / parseFloat(getComputedStyle(document.body)['font-size']); + if (notree) { + cs = 'na'; + r.hide(); + } + if (cs == 'tree' || (cs != 'na' && vw >= 60)) r.entree(null, true); @@ -9366,3 +9375,14 @@ function reload_browser() { msel.render(); } treectl.hydrate(); + +if (!fullui && (window.ui_nombar || /[?&]nombar\b/.exec(sloc0))) ebi('ops').style.display = 'none'; +if (!fullui && (window.ui_noacci || /[?&]noacci\b/.exec(sloc0))) ebi('acc_info').style.display = 'none'; +if (!fullui && (window.ui_nosrvi || /[?&]nosrvi\b/.exec(sloc0))) ebi('srv_info').style.display = 'none'; +if (!fullui && (window.ui_nocpla || /[?&]nocpla\b/.exec(sloc0))) ebi('goh').style.display = 'none'; +if (!fullui && (window.ui_nolbar || /[?&]nolbar\b/.exec(sloc0))) ebi('wfp').style.display = 'none'; +if (!fullui && (window.ui_noctxb || /[?&]noctxb\b/.exec(sloc0))) ebi('wtoggle').style.display = 'none'; +if (!fullui && (window.ui_norepl || /[?&]norepl\b/.exec(sloc0))) ebi('repl').style.display = 'none'; + +var m = /[?&]theme=([0-9]+)/.exec(sloc0); +if (m) settheme.go(parseInt(m[1])); diff --git a/docs/rice/README.md b/docs/rice/README.md index 4573a085..d1caf4b6 100644 --- a/docs/rice/README.md +++ b/docs/rice/README.md @@ -1,3 +1,24 @@ +# hide ui-elements + +useful for simplifying the UI in a write-only folder for uploads, or to embed copyparty into another website in an `