Fix HKU Moodle Right Section Bug When Clicking Buttons/Hyperlinks Inside

fix right section popping up when clicking buttons/hyperlinks inside

  1. // ==UserScript==
  2. // @name Fix HKU Moodle Right Section Bug When Clicking Buttons/Hyperlinks Inside
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description fix right section popping up when clicking buttons/hyperlinks inside
  6. // @author SimonTheLiquid
  7. // @match https://moodle.hku.hk/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=hku.hk
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const drawer = document.querySelector('[class*="drawer-right"]');
  17.  
  18. const as = drawer.querySelectorAll('a,button');
  19. for (var i = 0; i < as.length; i++)
  20. {
  21. as[i].onmousedown = function(event) {
  22. drawer.setAttribute('style', 'position:absolute');
  23. drawer.setAttribute('style', 'position:fixed');
  24. }
  25. }
  26.  
  27. var observer = new MutationObserver(function(mutations) {
  28. const as = drawer.querySelectorAll('a,button');
  29. for (var i = 0; i < as.length; i++)
  30. {
  31. as[i].onmousedown = function(event) {
  32. drawer.setAttribute('style', 'position:absolute');
  33. drawer.setAttribute('style', 'position:fixed');
  34. }
  35. }
  36. });
  37.  
  38. observer.observe(drawer, {
  39. subtree: true,
  40. childList: true,
  41. });
  42.  
  43. })();