fix edx

Fixing UX problems of Edx

当前为 2016-10-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name fix edx
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  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.startsWith("height: ")) {
  16. var height = e.data.substring("height: ".length);
  17.  
  18. //console.log("READ height: " + height);
  19.  
  20. if (height > 0) {
  21. var iframe = document.getElementsByTagName('iframe')[0];
  22.  
  23. var currentHeight = iframe.offsetHeight;
  24.  
  25. var heightDiff = height - currentHeight;
  26.  
  27. if ((heightDiff > 0) || (currentHeight == 800) || (heightDiff < -50)) {
  28. iframe.style.height = height + "px";
  29. }
  30. }
  31. }
  32. };
  33.  
  34.  
  35. } else {
  36. MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  37.  
  38. var observer = new MutationObserver(function(mutations, observer) {
  39. var height = document.body.offsetHeight;
  40.  
  41. //console.log("WRITE height: " + height);
  42. window.parent.postMessage("height: " + height , "https://courses.edx.org/");
  43. });
  44.  
  45. observer.observe(document, {
  46. subtree: true,
  47. childList: true
  48. });
  49. }