Skip to content

Instantly share code, notes, and snippets.

@asheroto
Last active December 15, 2023 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment