Skip to content

Instantly share code, notes, and snippets.

@asheroto
Last active October 2, 2024 06:34
Show Gist options
  • Save asheroto/e0627077e815d7e7d30e1dcf1070ab7f to your computer and use it in GitHub Desktop.
Save asheroto/e0627077e815d7e7d30e1dcf1070ab7f to your computer and use it in GitHub Desktop.
Nextcloud - Show gallery view by default with public / sharing / shared folders

Nextcloud - Show gallery view by default with public / sharing / shared folders

This will automatically switch a public or shared folder to gallery view when loading.

This only works on public or shared folders on Nextcloud and will not affect normal folders viewed under your user account.

Tested and working on Nextcloud 27+.

How to Configure

  1. Open core/js/public/publicpage.js.
  2. Inside the window.addEventListener('DOMContentLoaded', function () { closure, add the JS.
  3. Save.

How to Use

Append #view-grid to any shared URL.

For example...

https://YourDrive.com/s/daBAWTg3aa3FMLS#view-grid

How to Make Gallery View Always Default

Set onlyOnViewGridUrl to false which will cause the gallery/grid view to be shown each time without having to append #view-grid to the URL.

Disclaimers

  1. This is a workaround that will be lost when you update Nextcloud. You will have to reapply it each time you update.
  2. Beacuse a Nextcloud file has changed, the file integrity check will fail. That's okay, it just means that because the file doesn't match the original file it will give you a warning on the Overview page.
// Execute if onlyOnViewGrid is false or if the URL hash is "#view-grid"
let onlyOnViewGridUrl = true;
if (!onlyOnViewGridUrl || (onlyOnViewGridUrl && window.location.hash === "#view-grid")) {
$('#view-toggle').removeClass('icon-toggle-pictures').addClass('icon-toggle-filelist');
$('.files-filestable').addClass('view-grid');
}
@asheroto
Copy link
Author

asheroto commented May 8, 2024

Agreed! You would think it'd be an option.

For photos, this is a great feature. For files, I prefer the existing list view. Similar to how Window Explorer will detect photos vs documents, I wish Nextcloud did the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment