Last active
August 13, 2025 02:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==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