Greasy Fork is available in English.

fix edx

Fixing UX problems of Edx

  1. // ==UserScript==
  2. // @name fix edx
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Fixing UX problems of Edx
  6. // @author Yaroslav Shepilov
  7. // @match https://courses.edx.org/*
  8. // @match https://inginious-lti.info.ucl.ac.be/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. if (window.top === window.self) {
  13.  
  14. window.onmessage = function(e){
  15. if (e.data.includes('"height"') && e.data.includes('"index"')) {
  16. var message = JSON.parse(e.data);
  17. var height = message.height;
  18. var index = message.index;
  19.  
  20. //console.log("READ " + e.data);
  21.  
  22. if (height > 0) {
  23. var iframe = document.getElementsByTagName('iframe')[index];
  24.  
  25. var currentHeight = iframe.offsetHeight;
  26.  
  27. var heightDiff = height - currentHeight;
  28.  
  29. if ((heightDiff > 0) || (currentHeight == 800) || (heightDiff < -50)) {
  30. iframe.style.height = height + "px";
  31. }
  32. }
  33. }
  34. };
  35.  
  36.  
  37. } else {
  38. MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  39. var currentFrame = window;
  40.  
  41. var observer = new MutationObserver(function(mutations, observer) {
  42. var height = document.body.offsetHeight;
  43.  
  44. var index = 0;
  45. for (var i = 0; i < parent.frames.length; i++) {
  46. if (parent.frames[i] === currentFrame) {
  47. index = i;
  48. break;
  49. }
  50. }
  51.  
  52. var message = {"index": index, "height": height};
  53. var jsonMessage = JSON.stringify(message);
  54. //console.log("WRITE " + jsonMessage);
  55. window.parent.postMessage(jsonMessage, "https://courses.edx.org/");
  56. });
  57.  
  58. observer.observe(document, {
  59. subtree: true,
  60. childList: true
  61. });
  62. }