Moodle remove forceautodownload

Opens file instead of downloading it in moodle.

  1. // ==UserScript==
  2. // @name Moodle remove forceautodownload
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Opens file instead of downloading it in moodle.
  6. // @author Doriano DiPierro
  7. // @license MIT
  8. // @match https://moodle.ost.ch/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=ost.ch
  10. // @grant none
  11. // ==/UserScript==
  12. // Function to remove 'forcedownload=1' from a URL
  13. function removeForcedDownloadParam(url) {
  14. return url.replace(/([?&])forcedownload=1(&|$)/ig, '$1$2');
  15. }
  16. (function() {
  17. 'use strict';
  18. // Select all links on the page
  19. const links = document.querySelectorAll('a');
  20. // Loop through each link and update its href attribute
  21. links.forEach(link => {
  22. const currentHref = link.getAttribute('href');
  23. if (currentHref) {
  24. const updatedHref = removeForcedDownloadParam(currentHref);
  25. link.setAttribute('href', updatedHref);
  26. }
  27. link.setAttribute("onclick", "");
  28. });
  29. })();