Skip to content

Instantly share code, notes, and snippets.

@Smart123s
Last active February 21, 2026 12:17
Show Gist options
  • Select an option

  • Save Smart123s/b172d4117463ba1db95fff1d0e97e4b8 to your computer and use it in GitHub Desktop.

Select an option

Save Smart123s/b172d4117463ba1db95fff1d0e97e4b8 to your computer and use it in GitHub Desktop.
Remove forcedownload from Moodle (University of Pannonia) links
// ==UserScript==
// @name Remove forcedownload from Moodle links
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Removes the forcedownload=1 parameter from links on Moodle to prevent forced downloads.
// @author Peter Tombor
// @match *://moodle.uni-pannon.hu/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function cleanLinks() {
// Find all link elements on the page
const links = document.querySelectorAll('a[href]');
links.forEach(link => {
if (link.href.includes('forcedownload=1')) {
// Remove the forcedownload parameter
let newHref = link.href.replace(/([?&])forcedownload=1(&|$)/, function(match, p1, p2) {
// If there's another parameter after, keep the starting ? or &
return p2 ? p1 : '';
});
// Clean up any trailing ? or & just in case
newHref = newHref.replace(/[?&]$/, '');
link.href = newHref;
}
});
}
// Run the cleaner immediately when the script injects
cleanLinks();
// Set up an observer to catch any links loaded dynamically (e.g., expanding folders)
const observer = new MutationObserver((mutations) => {
let shouldClean = false;
for (const mutation of mutations) {
if (mutation.addedNodes.length > 0) {
shouldClean = true;
break;
}
}
if (shouldClean) {
cleanLinks();
}
});
observer.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