Skip to content

Instantly share code, notes, and snippets.

@phoenixthrush
Last active August 13, 2025 02:01
Show Gist options
  • Select an option

  • Save phoenixthrush/2f8ae63170364cb50ae1b0585899f5ef to your computer and use it in GitHub Desktop.

Select an option

Save phoenixthrush/2f8ae63170364cb50ae1b0585899f5ef to your computer and use it in GitHub Desktop.
Adds layout=grid param to all links on file browse served by Caddy #Caddy #FileBrowser #UserScript
// ==UserScript==
// @name Layout Grid Injector
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Adds layout=grid param to all links on file browse served by Caddy
// @match https://files.bla.local/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const updateLinks = root => {
for (const a of root.querySelectorAll('a[href]')) {
const url = new URL(a.href, location.origin);
if (url.searchParams.get('layout') !== 'grid') {
url.searchParams.set('layout', 'grid');
a.href = url.toString();
}
}
};
updateLinks(document);
new MutationObserver(muts => {
for (const m of muts) {
for (const node of m.addedNodes) {
if (node.nodeType !== 1) continue;
if (node.tagName === 'A') updateLinks(node.parentNode || node);
else updateLinks(node);
}
}
}).observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment